Skip to content

test_worst_unop()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_unop@v5.1.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_unop -m benchmark

Test running a block with as many unary instructions (takes one arg, produces one value) as possible.

Source code in tests/benchmark/test_worst_compute.py
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
@pytest.mark.parametrize("opcode", [Op.ISZERO, Op.NOT])
def test_worst_unop(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Op,
    fork: Fork,
    gas_benchmark_value: int,
):
    """
    Test running a block with as many unary instructions (takes one arg, produces one value)
    as possible.
    """
    max_code_size = fork.max_code_size()

    code_prefix = Op.JUMPDEST + Op.PUSH0  # Start with the arg 0.
    code_suffix = Op.POP + Op.PUSH0 + Op.JUMP
    code_body_len = max_code_size - len(code_prefix) - len(code_suffix)
    code_body = opcode * code_body_len
    code = code_prefix + code_body + code_suffix
    assert len(code) == max_code_size

    tx = Transaction(
        to=pre.deploy_contract(code=code),
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) opcode
...fork_Prague-state_test-opcode_ISZERO ISZERO
...fork_Prague-state_test-opcode_NOT NOT
...fork_Prague-blockchain_test_from_state_test-opcode_ISZERO ISZERO
...fork_Prague-blockchain_test_from_state_test-opcode_NOT NOT
...fork_Osaka-state_test-opcode_ISZERO ISZERO
...fork_Osaka-state_test-opcode_NOT NOT
...fork_Osaka-blockchain_test_from_state_test-opcode_ISZERO ISZERO
...fork_Osaka-blockchain_test_from_state_test-opcode_NOT NOT