Skip to content

test_exchange_invalid_immediate_aborts()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py::test_exchange_invalid_immediate_aborts@622620d8.

Generate fixtures for these test cases for Amsterdam with:

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

Test EXCHANGE aborts with invalid immediates (82-127).

This range is forbidden because it overlaps with JUMPDEST and PUSH opcodes.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_exchange.py
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
@EIPChecklist.Opcode.Test.ExceptionalAbort()
@pytest.mark.parametrize(
    "immediate",
    range(82, 128),  # Forbidden range: 0x52-0x7F
    ids=lambda x: f"imm_{x}",
)
def test_exchange_invalid_immediate_aborts(
    immediate: int,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test EXCHANGE aborts with invalid immediates (82-127).

    This range is forbidden because it overlaps with JUMPDEST and PUSH opcodes.
    """
    sender = pre.fund_eoa()

    code = Bytecode()
    code += Op.SSTORE(0, 1)  # Marker

    # Push 30 items (max needed for any valid EXCHANGE)
    for i in range(30):
        code += Op.PUSH1(i)

    code += Op.EXCHANGE[immediate.to_bytes(1, "big")]
    code += Op.SSTORE(0, 2)  # Should never execute
    code += Op.STOP

    contract_address = pre.deploy_contract(code=code)
    tx = Transaction(to=contract_address, sender=sender)

    # Execution aborted, transaction reverts
    post = {contract_address: Account(storage={})}

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 46 parametrized test cases across 1 fork.