Skip to content

test_call_identity_precompile()

Documentation for tests/frontier/identity_precompile/test_identity.py::test_call_identity_precompile@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/frontier/identity_precompile/test_identity.py::test_call_identity_precompile --fork Osaka

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

Source code in tests/frontier/identity_precompile/test_identity.py
 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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentitiy_0Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentitiy_1Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_1_nonzeroValueFiller.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_2Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_3Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_4Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_4_gas17Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_4_gas18Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentitiy_0Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentitiy_1Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_1_nonzeroValueFiller.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_2Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_3Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_4Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_4_gas17Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_4_gas18Filler.json",
    ],
    pr=["https://github.com/ethereum/execution-spec-tests/pull/1344"],
    coverage_missed_reason="MPT related coverage lost, not relevant to test",
)
@pytest.mark.valid_from("Byzantium")
@pytest.mark.parametrize("call_type", [Op.CALL, Op.CALLCODE])
@pytest.mark.parametrize(
    [
        "call_args",
        "memory_values",
        "contract_balance",
        "call_succeeds",
    ],
    [
        pytest.param(CallArgs(gas=0xFF), (0x1,), 0x0, True, id="identity_0"),
        pytest.param(
            CallArgs(args_size=0x0),
            (0x0,),
            0x0,
            True,
            id="identity_1",
        ),
        pytest.param(
            CallArgs(gas=0x30D40, value=0x1, args_size=0x0),
            (0x1,),
            0x1,
            True,
            id="identity_1_nonzerovalue",
        ),
        pytest.param(
            CallArgs(gas=0x30D40, value=0x1, args_size=0x0),
            None,
            0x0,
            False,
            id="identity_1_nonzerovalue_insufficient_balance",
        ),
        pytest.param(
            CallArgs(args_size=0x25),
            (0xF34578907F,),
            0x0,
            True,
            id="identity_2",
        ),
        pytest.param(
            CallArgs(args_size=0x25),
            (0xF34578907F,),
            0x0,
            True,
            id="identity_3",
        ),
        pytest.param(
            CallArgs(gas=0x64),
            (
                0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            ),
            0x0,
            True,
            id="identity_4",
        ),
        pytest.param(
            CallArgs(gas=0x11),
            (
                0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            ),
            0x0,
            False,
            id="identity_4_insufficient_gas",
        ),
        pytest.param(
            CallArgs(gas=0x12),
            (
                0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            ),
            0x0,
            True,
            id="identity_4_exact_gas",
        ),
    ],
)
def test_call_identity_precompile(
    state_test: StateTestFiller,
    pre: Alloc,
    call_type: Op,
    call_args: CallArgs,
    memory_values: Tuple[int, ...],
    call_succeeds: bool,
    tx_gas_limit: int,
    contract_balance: int,
) -> None:
    """
    Test identity precompile RETURNDATA is sized correctly based on the input
    size.
    """
    env = Environment()
    storage = Storage()

    contract_bytecode = generate_identity_call_bytecode(
        storage,
        call_type,
        memory_values,
        call_args,
        call_succeeds,
    )

    account = pre.deploy_contract(
        contract_bytecode,
        storage=storage.canary(),
        balance=contract_balance,
    )

    tx = Transaction(
        to=account,
        sender=pre.fund_eoa(),
        gas_limit=tx_gas_limit,
    )

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

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

Parametrized Test Cases

This test generates 16 parametrized test cases across 11 forks.