Skip to content

test_worst_unop()

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

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_unop --fork Osaka

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
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
@pytest.mark.valid_from("Cancun")
@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_Cancun-state_test-opcode_ISZERO ISZERO
...fork_Cancun-state_test-opcode_NOT NOT
...fork_Cancun-blockchain_test_from_state_test-opcode_ISZERO ISZERO
...fork_Cancun-blockchain_test_from_state_test-opcode_NOT NOT
...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