test_swapn_stack_underflow()
Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_stack_underflow@ffe48572.
Generate fixtures for these test cases for Bogota with:
fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_stack_underflow --fork Bogota
Test SWAPN causes transaction failure on stack underflow.
Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py
| @EIPChecklist.Opcode.Test.StackUnderflow()
def test_swapn_stack_underflow(
pre: Alloc,
state_test: StateTestFiller,
) -> None:
"""Test SWAPN causes transaction failure on stack underflow."""
sender = pre.fund_eoa()
# SWAPN with immediate 0x80 (n=17) swaps position 1 with position 18
# Need 18 items, so push only 17 to trigger underflow
code = Bytecode()
for i in range(17):
code += Op.PUSH1(i)
# Pass immediate as bytes (raw immediate byte for testing)
# decode_single(0x80) = 17, needs 18 items but only 17
code += Op.SWAPN[b"\x80"]
code += Op.STOP
contract_address = pre.deploy_contract(code=code)
tx = Transaction(to=contract_address, sender=sender)
# Transaction should fail, contract storage unchanged
post = {contract_address: Account(storage={})}
state_test(pre=pre, post=post, tx=tx)
|
Parametrized Test Cases
This test generates 1 parametrized test case across 2 forks.