Skip to content

test_extcodehash_call_to_nonexistent()

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

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
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
@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,
        gas_limit=400_000,
    )

    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.