Skip to content

test_worst_jumpi_fallthrough()

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

Generate fixtures for these test cases for Osaka with:

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

Test running a JUMPI-intensive contract with fallthrough.

Source code in tests/benchmark/test_worst_compute.py
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
@pytest.mark.valid_from("Cancun")
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_Cancun-state_test
...fork_Cancun-blockchain_test_from_state_test
...fork_Prague-state_test
...fork_Prague-blockchain_test_from_state_test
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test