Skip to content

test_exchange_empty_stack()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py::test_exchange_empty_stack@c17999c0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py::test_exchange_empty_stack --fork Amsterdam

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

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
@EIPChecklist.Opcode.Test.StackComplexOperations.StackHeights.Zero()
@EIPChecklist.Opcode.Test.StackUnderflow()
def test_exchange_empty_stack(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test EXCHANGE on an empty stack aborts with a stack underflow.
    """
    sender = pre.fund_eoa()

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