Skip to content

test_call_opcodes_to_precompile()

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

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
@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.