Skip to content

test_extcodehash_precompile()

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

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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
@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,
    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())

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