Skip to content

test_call_opcodes_to_precompile()

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

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
@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.