Skip to content

test_extcodehash_precompile()

Documentation for tests/constantinople/eip1052_extcodehash/test_extcodehash.py::test_extcodehash_precompile@5f132e7c.

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
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
629
630
631
632
633
634
635
636
637
638
639
640
641
@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.