diff --git a/eth_tester/backends/pyevm/main.py b/eth_tester/backends/pyevm/main.py index 03e1c8f7..7916646f 100644 --- a/eth_tester/backends/pyevm/main.py +++ b/eth_tester/backends/pyevm/main.py @@ -873,14 +873,15 @@ def call(self, transaction, block_number="latest"): if "gas" not in defaulted_transaction: defaulted_transaction["gas"] = self._max_available_gas() - signed_evm_transaction = self._get_normalized_and_signed_evm_transaction( + unsigned_tx = self._get_normalized_and_unsigned_evm_transaction( defaulted_transaction, block_number, ) + evm_transaction = EVMSpoofTransaction(unsigned_tx, from_=transaction["from"]) computation = _execute_and_revert_transaction( self.chain, - signed_evm_transaction, + evm_transaction, block_number, ) if computation.is_error: diff --git a/newsfragments/297.bugfix.rst b/newsfragments/297.bugfix.rst new file mode 100644 index 00000000..3af12257 --- /dev/null +++ b/newsfragments/297.bugfix.rst @@ -0,0 +1 @@ +Fix a bug where requests for ``eth_call`` via *PyEVMBackend* fail with invalid ``from`` key. The account need not be a "known" account for signing since eth_call does not change the state of the blockchain. diff --git a/tests/backends/test_pyevm.py b/tests/backends/test_pyevm.py index 48366f25..94538830 100644 --- a/tests/backends/test_pyevm.py +++ b/tests/backends/test_pyevm.py @@ -491,3 +491,28 @@ def test_send_raw_transaction_invalid_blob_transaction(self, eth_tester): with pytest.raises(EthUtilsValidationError): acct.sign_transaction(tx, blobs=[blob_data]) + + def test_eth_call_does_not_require_a_known_account(self, eth_tester): + # `eth_call` should not require the `from` address to be a known account + # as it does not change the state of the blockchain + acct = Account.create() + + # fund acct + eth_tester.send_transaction( + { + "from": eth_tester.get_accounts()[0], + "to": acct.address, + "value": 10**18, + "gas": 21000, + } + ) + + result = eth_tester.call( + { + "from": acct.address, + "to": eth_tester.get_accounts()[0], + "data": "0x", + } + ) + + assert result == "0x"