Skip to content

test_identity_precompile_returndata()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
71
72
73
74
75
76
77
78
@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,
) -> None:
    """
    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,
                ret_offset=0x10,
                ret_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

This test generates 2 parametrized test cases across 12 forks.