Skip to content

test_eip_vector_exchange_end_of_code()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_exchange_end_of_code@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_exchange_end_of_code --fork Amsterdam

EIP test vector: 600260008080808080600160008080808080808080e8.

EXCHANGE at end of code, immediate = 0x00 (beyond code). decode_pair(0) = (9, 16), swaps positions 10 and 17. Results in 17 stack items, bottom=1, 10th from top=2, rest=0.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
def test_eip_vector_exchange_end_of_code(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 600260008080808080600160008080808080808080e8.

    EXCHANGE at end of code, immediate = 0x00 (beyond code).
    decode_pair(0) = (9, 16), swaps positions 10 and 17.
    Results in 17 stack items, bottom=1, 10th from top=2, rest=0.
    """
    sender = pre.fund_eoa()

    # Build exact bytecode from the EIP
    code = (
        Op.PUSH1[0x2]
        + Op.PUSH1[0x0]
        + Op.DUP1 * 5
        + Op.PUSH1[0x1]
        + Op.PUSH1[0x0]
        + Op.DUP1 * 8
        + Op.EXCHANGE
    )
    assert bytes(code) == bytes.fromhex(
        "600260008080808080600160008080808080808080e8"
    )
    # 17 items on stack:
    # pos 1-8: 0, pos 9: 0, pos 10: 1, pos 11-16: 0, pos 17: 2
    # After EXCHANGE(9,16): swap pos 10 and 17 -> pos 10=2, pos 17=1

    # Store marker before opcode to verify success
    # Since EXCHANGE is at end of code, we verify by checking that the
    # operation completed by storing the 10th and bottom items
    contract_address = pre.deploy_contract(
        code=Op.SSTORE(0, 0x42) + code + Op.STOP
    )
    tx = Transaction(to=contract_address, sender=sender, gas_limit=1_000_000)

    # Verify marker was stored (tx succeeded)
    post = {contract_address: Account(storage={0: 0x42})}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.