Skip to content

test_call_opcodes_to_precompile()

Documentation for tests/benchmark/compute/instruction/test_system.py::test_call_opcodes_to_precompile@c17999c0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_system.py::test_call_opcodes_to_precompile --gas-benchmark-values 1

Benchmark every call opcode dispatching to a precompile.

Source code in tests/benchmark/compute/instruction/test_system.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@pytest.mark.parametrize(
    "opcode,value",
    [
        pytest.param(Op.CALL, 0, id="CALL"),
        pytest.param(Op.CALL, 1, id="CALL with value"),
        pytest.param(Op.CALLCODE, 0, id="CALLCODE"),
        pytest.param(Op.CALLCODE, 1, id="CALLCODE with value"),
        pytest.param(Op.DELEGATECALL, None, id="DELEGATECALL"),
        pytest.param(Op.STATICCALL, None, id="STATICCALL"),
    ],
)
def test_call_opcodes_to_precompile(
    benchmark_test: BenchmarkTestFiller,
    opcode: Op,
    value: int | None,
) -> None:
    """Benchmark every call opcode dispatching to a precompile."""
    value_kwarg: dict[str, Any] = {}
    if value is not None:
        value_kwarg = {"value": value}

    attack_block = Op.POP(
        opcode(
            gas=Op.GAS,
            address=IdentitySpec.IDENTITY,
            args_offset=Op.PUSH0,
            args_size=Op.PUSH0,
            ret_offset=Op.PUSH0,
            ret_size=Op.PUSH0,
            **value_kwarg,
        )
    )

    benchmark_test(
        target_opcode=opcode,
        code_generator=JumpLoopGenerator(
            attack_block=attack_block,
            contract_balance=10**9 if value else 0,
        ),
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 3 forks.