Skip to content

test_extcodehash_codeless_with_storage()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test EXTCODEHASH/EXTCODESIZE of a codeless account that has storage.

All three variants are non-empty per EIP-161 (non-zero balance or nonce), so EXTCODEHASH returns keccak256("") and EXTCODESIZE returns 0. Storage is not part of the EIP-161 emptiness check.

Source code in tests/constantinople/eip1052_extcodehash/test_extcodehash.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/dynamicAccountOverwriteEmpty_ParisFiller.yml",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2291"],
)
@pytest.mark.pre_alloc_mutable
@pytest.mark.parametrize(
    "balance, nonce",
    [
        pytest.param(1, 0, id="balance"),
        pytest.param(0, 1, id="nonce"),
        pytest.param(1, 1, id="balance_and_nonce"),
    ],
)
def test_extcodehash_codeless_with_storage(
    state_test: StateTestFiller,
    pre: Alloc,
    balance: int,
    nonce: int,
) -> None:
    """
    Test EXTCODEHASH/EXTCODESIZE of a codeless account that has storage.

    All three variants are non-empty per EIP-161 (non-zero balance or nonce),
    so EXTCODEHASH returns keccak256("") and EXTCODESIZE returns 0.
    Storage is not part of the EIP-161 emptiness check.
    """
    target_address = pre.nonexistent_account()
    pre[target_address] = Account(balance=balance, nonce=nonce, storage={1: 1})

    storage = Storage()
    code = Op.SSTORE(
        storage.store_next(keccak256(b"")),
        Op.EXTCODEHASH(target_address),
    ) + Op.SSTORE(
        storage.store_next(0),
        Op.EXTCODESIZE(target_address),
    )

    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 3 parametrized test cases across 10 forks.