Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: eth_call for pyevm should not check for known account #297

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eth_tester/backends/pyevm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/297.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions tests/backends/test_pyevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"