Skip to content

test_exchange_invalid_immediate_aborts()

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

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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
@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.