Skip to content

test_eip_vector_exchange_swap_positions()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_exchange_swap_positions@5c024cbb.

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_swap_positions --fork Amsterdam

EIP test vector: 600060016002e88e.

Results in 3 stack items, from top to bottom: [2, 0, 1].

PUSH1 0, PUSH1 1, PUSH1 2, EXCHANGE[0x8e] - After pushes: [2, 1, 0] (top to bottom) - EXCHANGE[0x8e]: decode_pair(0x8e)=(1,2), swap positions 2 and 3 - Result: [2, 0, 1]

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def test_eip_vector_exchange_swap_positions(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 600060016002e88e.

    Results in 3 stack items, from top to bottom: [2, 0, 1].

    PUSH1 0, PUSH1 1, PUSH1 2, EXCHANGE[0x8e]
    - After pushes: [2, 1, 0] (top to bottom)
    - EXCHANGE[0x8e]: decode_pair(0x8e)=(1,2), swap positions 2 and 3
    - Result: [2, 0, 1]
    """
    sender = pre.fund_eoa()

    # Build the exact bytecode from the EIP
    code = Op.PUSH1[0x0] + Op.PUSH1[0x1] + Op.PUSH1[0x2] + Op.EXCHANGE[b"\x8e"]
    assert bytes(code) == bytes.fromhex("600060016002e88e")

    # Store all 3 stack values
    code += Op.PUSH1(0) + Op.SSTORE  # Store position 1 / top (should be 2)
    code += Op.PUSH1(1) + Op.SSTORE  # Store position 2 (should be 0)
    code += Op.PUSH1(2) + Op.SSTORE  # Store position 3 / bottom (should be 1)
    code += Op.STOP

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

    post = {
        contract_address: Account(
            storage={
                0: 2,  # top = 2 (unchanged)
                1: 0,  # position 2 = 0 (swapped from position 3)
                2: 1,  # bottom = 1 (swapped from position 2)
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.