Skip to content

test_extcodehash_precompile()

Documentation for tests/constantinople/eip1052_extcodehash/test_extcodehash.py::test_extcodehash_precompile@tests-bal@v5.7.0.

Generate fixtures for these test cases for Amsterdam with:

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

Test EXTCODEHASH/EXTCODESIZE of precompile addresses.

Precompiles have no associated code, so both return 0.

Source code in tests/constantinople/eip1052_extcodehash/test_extcodehash.py
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extCodeHashPrecompilesFiller.yml",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2302"],
)
@pytest.mark.with_all_precompiles
def test_extcodehash_precompile(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    precompile: Address,
) -> None:
    """
    Test EXTCODEHASH/EXTCODESIZE of precompile addresses.

    Precompiles have no associated code, so both return 0.
    """
    storage = Storage()

    code = Op.SSTORE(
        storage.store_next(0),
        Op.EXTCODEHASH(precompile),
    ) + Op.SSTORE(
        storage.store_next(0),
        Op.EXTCODESIZE(precompile),
    )

    code_address = pre.deploy_contract(code, storage=storage.canary())

    gas_limit = 400_000
    if fork.is_eip_enabled(8037):
        gas_limit = 1_000_000
    tx = Transaction(
        sender=pre.fund_eoa(),
        to=code_address,
        gas_limit=gas_limit,
    )

    state_test(
        pre=pre,
        post={code_address: Account(storage=storage)},
        tx=tx,
    )

Parametrized Test Cases

This test generates 18 parametrized test cases across 10 forks.