Skip to content

test_extcodehash_self()

Documentation for tests/constantinople/eip1052_extcodehash/test_extcodehash.py::test_extcodehash_self@8db70f93.

Generate fixtures for these test cases for Amsterdam with:

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

Test EXTCODEHASH/EXTCODESIZE of the currently executing account.

Source code in tests/constantinople/eip1052_extcodehash/test_extcodehash.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extCodeHashSelfFiller.json",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2249"],
)
@pytest.mark.eels_base_coverage
def test_extcodehash_self(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test EXTCODEHASH/EXTCODESIZE of the currently executing account.
    """
    storage = Storage()
    slot_hash = storage.store_next(0)
    slot_size = storage.store_next(0)

    code = Op.SSTORE(slot_hash, Op.EXTCODEHASH(Op.ADDRESS)) + Op.SSTORE(
        slot_size, Op.EXTCODESIZE(Op.ADDRESS)
    )

    storage[slot_hash] = code.keccak256()
    storage[slot_size] = len(code)

    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 1 parametrized test case across 10 forks.