Skip to content

test_swapn_empty_stack()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_empty_stack@c17999c0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_empty_stack --fork Amsterdam

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

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
@EIPChecklist.Opcode.Test.StackComplexOperations.StackHeights.Zero()
@EIPChecklist.Opcode.Test.StackUnderflow()
def test_swapn_empty_stack(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test SWAPN on an empty stack aborts with a stack underflow.
    """
    sender = pre.fund_eoa()

    code = Op.SSTORE(0, 1)  # leaves the stack empty
    code += Op.SWAPN[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 1 fork.