Skip to content

test_extcodehash_via_call()

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

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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
@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,
        gas_limit=400_000,
    )

    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.