Skip to content

test_extcodehash_empty_send_value()

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

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
112
113
114
115
116
117
118
119
120
121
122
123
124
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
@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,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 10 forks.