Skip to content

test_worst_jumpi_fallthrough()

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

Generate fixtures for these test cases for Osaka with:

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

Test running a JUMPI-intensive contract with fallthrough.

Source code in tests/benchmark/test_worst_compute.py
1785
1786
1787
1788
1789
1790
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
def test_worst_jumpi_fallthrough(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_benchmark_value: int,
):
    """Test running a JUMPI-intensive contract with fallthrough."""
    max_code_size = fork.max_code_size()

    def jumpi_seq():
        return Op.JUMPI(Op.PUSH0, Op.PUSH0)

    prefix_seq = Op.JUMPDEST
    suffix_seq = Op.JUMP(Op.PUSH0)
    bytes_per_seq = len(jumpi_seq())
    seqs_per_call = (max_code_size - len(prefix_seq) - len(suffix_seq)) // bytes_per_seq

    # Create and deploy the jumpi-intensive contract
    jumpis_code = prefix_seq + jumpi_seq() * seqs_per_call + suffix_seq
    assert len(jumpis_code) <= max_code_size

    jumpis_address = pre.deploy_contract(code=bytes(jumpis_code))

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

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

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Prague-state_test
...fork_Prague-blockchain_test_from_state_test
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test