Skip to content

test_extcodehash_via_call()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test EXTCODEHASH/EXTCODESIZE queried via different call types.

A helper contract computes EXTCODEHASH and EXTCODESIZE of a target and returns them. The caller invokes the helper using the parametrized call type and stores the results.

Source code in tests/constantinople/eip1052_extcodehash/test_extcodehash.py
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extCodeHashCALLFiller.json",  # noqa: E501
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extCodeHashCALLCODEFiller.json",  # noqa: E501
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extCodeHashDELEGATECALLFiller.json",  # noqa: E501
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stExtCodeHash/extCodeHashSTATICCALLFiller.json",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2348"],
)
@pytest.mark.parametrize(
    "opcode",
    [Op.CALL, Op.CALLCODE, Op.DELEGATECALL, Op.STATICCALL],
)
def test_extcodehash_via_call(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Opcodes,
) -> None:
    """
    Test EXTCODEHASH/EXTCODESIZE queried via different call types.

    A helper contract computes EXTCODEHASH and EXTCODESIZE of a target
    and returns them. The caller invokes the helper using the
    parametrized call type and stores the results.
    """
    storage = Storage()
    target_code = b"\x12\x34"
    target_address = pre.deploy_contract(target_code)

    helper_code = (
        Op.MSTORE(0, Op.EXTCODEHASH(target_address))
        + Op.MSTORE(32, Op.EXTCODESIZE(target_address))
        + Op.RETURN(0, 64)
    )
    helper_address = pre.deploy_contract(helper_code)

    code = (
        opcode(address=helper_address, gas=150_000)
        + Op.RETURNDATACOPY(0, 0, 64)
        + Op.SSTORE(
            storage.store_next(keccak256(target_code)),
            Op.MLOAD(0),
        )
        + Op.SSTORE(
            storage.store_next(len(target_code)),
            Op.MLOAD(32),
        )
    )

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