Skip to content

test_call_opcodes_to_precompile()

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

Generate fixtures for these test cases for Bogota 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
@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 4 forks.