Skip to content

test_extcodehash_call_to_nonexistent()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test EXTCODEHASH after calling a non-existent account.

Call a non-existent address using each call type, then check EXTCODEHASH — it returns 0 because the account does not exist.

Source code in tests/constantinople/eip1052_extcodehash/test_extcodehash.py
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/callToNonExistentFiller.json",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2410"],
)
@pytest.mark.with_all_call_opcodes
def test_extcodehash_call_to_nonexistent(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Opcodes,
) -> None:
    """
    Test EXTCODEHASH after calling a non-existent account.

    Call a non-existent address using each call type, then check
    EXTCODEHASH — it returns 0 because the account does not exist.
    """
    storage = Storage()
    nonexistent = pre.nonexistent_account()

    code = Op.SSTORE(
        storage.store_next(1),
        call_opcode(address=nonexistent, gas=25_000),
    ) + Op.SSTORE(
        storage.store_next(0),
        Op.EXTCODEHASH(nonexistent),
    )

    code_address = pre.deploy_contract(code, 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 4 parametrized test cases across 10 forks.