test_dupn_stack_underflow()
Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_stack_underflow@ffe48572.
Generate fixtures for these test cases for Bogota with:
fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_stack_underflow --fork Bogota
Test DUPN causes transaction failure on stack underflow.
Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
| @EIPChecklist.Opcode.Test.StackUnderflow()
@pytest.mark.parametrize(
"immediate",
[0, 45, 90, 128, 200, 255],
ids=lambda x: f"dupn_underflow_imm_{x}",
)
def test_dupn_stack_underflow(
immediate: int,
pre: Alloc,
state_test: StateTestFiller,
) -> None:
"""Test DUPN causes transaction failure on stack underflow."""
sender = pre.fund_eoa()
# Decode the immediate to get the stack index
stack_index = decode_single(immediate)
# Push one less than required to trigger underflow
insufficient_items = stack_index - 1
code = Op.SSTORE(0, 1)
for i in range(insufficient_items):
code += Op.PUSH1(i)
# Pass immediate as bytes (raw immediate byte for testing)
# Needs stack_index items, underflow
code += Op.DUPN[immediate.to_bytes(1, "big")]
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={0: 0})}
state_test(pre=pre, post=post, tx=tx)
|
Parametrized Test Cases
This test generates 6 parametrized test cases across 2 forks.