test_stack_overflow()
Documentation for tests/frontier/opcodes/test_all_opcodes.py::test_stack_overflow@ffe48572.
Generate fixtures for these test cases for Bogota with:
fill -v tests/frontier/opcodes/test_all_opcodes.py::test_stack_overflow --fork Bogota
Test that opcodes which leave new items on the stack can overflow.
Source code in tests/frontier/opcodes/test_all_opcodes.py
| @pytest.mark.parametrize_by_fork("opcode", fork_opcodes_increasing_stack)
@pytest.mark.parametrize("fails", [True, False])
@pytest.mark.eels_base_coverage
def test_stack_overflow(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
opcode: Op,
fails: bool,
env: Environment,
) -> None:
"""Test that opcodes which leave new items on the stack can overflow."""
pre_stack_items = fork.max_stack_height()
if not fails:
pre_stack_items -= (
opcode.pushed_stack_items - opcode.popped_stack_items
)
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_failed if fails else value_code_worked
}
state_test(
env=env,
pre=pre,
tx=tx,
post={contract: Account(storage=expected_storage)},
)
|
Parametrized Test Cases
This test generates 142 parametrized test cases across 17 forks.