Skip to content

test_dupn_empty_stack()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_empty_stack@02aafd78.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_empty_stack --fork Bogota

Test DUPN on an empty stack aborts with a stack underflow.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
@EIPChecklist.Opcode.Test.StackComplexOperations.StackHeights.Zero()
@EIPChecklist.Opcode.Test.StackUnderflow()
def test_dupn_empty_stack(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test DUPN on an empty stack aborts with a stack underflow.
    """
    sender = pre.fund_eoa()

    code = Op.SSTORE(0, 1)  # leaves the stack empty
    code += Op.DUPN[Spec.MIN_STACK_INDEX]
    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 1 parametrized test case across 2 forks.