Skip to content

test_extcodehash_empty_send_value()

Documentation for tests/constantinople/eip1052_extcodehash/test_extcodehash.py::test_extcodehash_empty_send_value@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/constantinople/eip1052_extcodehash/test_extcodehash.py::test_extcodehash_empty_send_value --fork Amsterdam

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@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,
        gas_limit=400_000,
    )

    state_test(
        pre=pre,
        post={
            code_address: Account(storage=storage),
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 10 forks.