Skip to content

test_identity_precompile_returndata()

Documentation for tests/frontier/identity_precompile/test_identity_returndatasize.py::test_identity_precompile_returndata@64f949d0.

Generate fixtures for these test cases for Prague with:

fill -v tests/frontier/identity_precompile/test_identity_returndatasize.py::test_identity_precompile_returndata --fork Prague

Test identity precompile RETURNDATA is sized correctly based on the input size.

Source code in tests/frontier/identity_precompile/test_identity_returndatasize.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts/identity_to_biggerFiller.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts/identity_to_smallerFiller.json",
    ],
    pr=["https://github.com/ethereum/execution-spec-tests/pull/1344"],
)
@pytest.mark.valid_from("Byzantium")
@pytest.mark.parametrize(
    ["args_size", "output_size", "expected_returndatasize"],
    [
        pytest.param(16, 32, 16, id="output_size_greater_than_input"),
        pytest.param(32, 16, 32, id="output_size_less_than_input"),
    ],
)
def test_identity_precompile_returndata(
    state_test: StateTestFiller,
    pre: Alloc,
    args_size: int,
    output_size: int,
    expected_returndatasize: int,
):
    """Test identity precompile RETURNDATA is sized correctly based on the input size."""
    env = Environment()
    storage = Storage()

    account = pre.deploy_contract(
        Op.MSTORE(0, 0)
        + Op.GAS
        + Op.MSTORE(0, 0x112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00)
        + Op.POP(
            Op.CALL(
                address=Constants.IDENTITY_PRECOMPILE_ADDRESS,
                args_offset=0,
                args_size=args_size,
                output_offset=0x10,
                output_size=output_size,
            )
        )
        + Op.SSTORE(storage.store_next(expected_returndatasize), Op.RETURNDATASIZE)
        + Op.STOP,
        storage=storage.canary(),
    )

    tx = Transaction(
        to=account,
        sender=pre.fund_eoa(),
        gas_limit=200_000,
        protected=True,
    )

    post = {account: Account(storage=storage)}

    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) args_size output_size expected_returndatasize
...fork_Byzantium-state_test-output_size_greater_than_input 16 32 16
...fork_Byzantium-state_test-output_size_less_than_input 32 16 32
...fork_Byzantium-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Byzantium-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Constantinople-state_test-output_size_greater_than_input 16 32 16
...fork_Constantinople-state_test-output_size_less_than_input 32 16 32
...fork_Constantinople-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Constantinople-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_ConstantinopleFix-state_test-output_size_greater_than_input 16 32 16
...fork_ConstantinopleFix-state_test-output_size_less_than_input 32 16 32
...fork_ConstantinopleFix-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_ConstantinopleFix-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Istanbul-state_test-output_size_greater_than_input 16 32 16
...fork_Istanbul-state_test-output_size_less_than_input 32 16 32
...fork_Istanbul-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Istanbul-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Berlin-state_test-output_size_greater_than_input 16 32 16
...fork_Berlin-state_test-output_size_less_than_input 32 16 32
...fork_Berlin-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Berlin-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_London-state_test-output_size_greater_than_input 16 32 16
...fork_London-state_test-output_size_less_than_input 32 16 32
...fork_London-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_London-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Paris-state_test-output_size_greater_than_input 16 32 16
...fork_Paris-state_test-output_size_less_than_input 32 16 32
...fork_Paris-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Paris-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Shanghai-state_test-output_size_greater_than_input 16 32 16
...fork_Shanghai-state_test-output_size_less_than_input 32 16 32
...fork_Shanghai-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Shanghai-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Cancun-state_test-output_size_greater_than_input 16 32 16
...fork_Cancun-state_test-output_size_less_than_input 32 16 32
...fork_Cancun-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Cancun-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Prague-state_test-output_size_greater_than_input 16 32 16
...fork_Prague-state_test-output_size_less_than_input 32 16 32
...fork_Prague-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Prague-blockchain_test_from_state_test-output_size_less_than_input 32 16 32
...fork_Osaka-state_test-output_size_greater_than_input 16 32 16
...fork_Osaka-state_test-output_size_less_than_input 32 16 32
...fork_Osaka-blockchain_test_from_state_test-output_size_greater_than_input 16 32 16
...fork_Osaka-blockchain_test_from_state_test-output_size_less_than_input 32 16 32