Skip to content

test_max_stack()

Documentation for tests/frontier/opcodes/test_all_opcodes.py::test_max_stack@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/opcodes/test_all_opcodes.py::test_max_stack --fork Bogota

Test that opcodes that don't push more items than they pop from the stack can operate when the stack is full.

Source code in tests/frontier/opcodes/test_all_opcodes.py
@pytest.mark.parametrize_by_fork(
    "opcode", fork_opcodes_with_non_increasing_stack
)
def test_max_stack(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    opcode: Op,
    env: Environment,
) -> None:
    """
    Test that opcodes that don't push more items than they pop from the
    stack can operate when the stack is full.
    """
    pre_stack_items = fork.max_stack_height()
    slot_code_worked = 1
    value_code_failed = 0xDEADBEEF
    value_code_worked = 1

    push_opcode = Op.PUSH0 if Op.PUSH0 in fork.valid_opcodes() else Op.PUSH1(0)

    contract = pre.deploy_contract(
        code=Op.SSTORE(slot_code_worked, value_code_worked)
        + push_opcode * pre_stack_items
        + opcode
        + Op.STOP,
        storage={slot_code_worked: value_code_failed},
    )
    tx = Transaction(
        to=contract,
        sender=pre.fund_eoa(),
        protected=fork.supports_protected_txs(),
    )
    expected_storage = {slot_code_worked: value_code_worked}

    state_test(
        env=env,
        pre=pre,
        tx=tx,
        post={contract: Account(storage=expected_storage)},
    )

Parametrized Test Cases

This test generates 78 parametrized test cases across 17 forks.