Test EXTCODEHASH of non-existent account before and after sending value.
Verify that EXTCODEHASH transitions from 0 to keccak256("") when
the account receives value within the same transaction.
Source code in tests/constantinople/eip1052_extcodehash/test_extcodehash.py
| @pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extcodehashEmpty_ParisFiller.yml", # noqa: E501
],
pr=["https://github.com/ethereum/execution-specs/pull/2237"],
)
def test_extcodehash_empty_send_value(
state_test: StateTestFiller,
pre: Alloc,
) -> None:
"""
Test EXTCODEHASH of non-existent account before and after sending value.
Verify that EXTCODEHASH transitions from 0 to keccak256("") when
the account receives value within the same transaction.
"""
storage = Storage()
target_address = pre.nonexistent_account()
code = (
# EXTCODEHASH before sending value: expect 0 (non-existent).
Op.SSTORE(
storage.store_next(0),
Op.EXTCODEHASH(target_address),
)
# Send 1 wei to target, creating the account.
+ Op.CALL(gas=Op.GAS, address=target_address, value=1)
# EXTCODEHASH after sending value: expect keccak256("").
+ Op.SSTORE(
storage.store_next(keccak256(b"")),
Op.EXTCODEHASH(target_address),
)
)
code_address = pre.deploy_contract(
code, balance=10**18, storage=storage.canary()
)
tx = Transaction(sender=pre.fund_eoa(), to=code_address)
state_test(
pre=pre,
post={
code_address: Account(storage=storage),
},
tx=tx,
)
|