Skip to content

test_eip_vector_swapn_swap_with_bottom()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_swapn_swap_with_bottom@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_swapn_swap_with_bottom --fork Amsterdam

EIP test vector: 600160008080808080808080808080808080806002e780.

Results in 18 stack items, top=1, bottom=2, rest=0.

PUSH1 1, PUSH1 0, 15x DUP1, PUSH1 2, SWAPN[0x80] - After PUSH1 2: 18 items with top=2, bottom=1 - SWAPN[0x80]: decode_single(0x80)=17, swap pos 1 with pos (17+1)=18 - Result: 18 items, top=1, bottom=2

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def test_eip_vector_swapn_swap_with_bottom(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 600160008080808080808080808080808080806002e780.

    Results in 18 stack items, top=1, bottom=2, rest=0.

    PUSH1 1, PUSH1 0, 15x DUP1, PUSH1 2, SWAPN[0x80]
    - After PUSH1 2: 18 items with top=2, bottom=1
    - SWAPN[0x80]: decode_single(0x80)=17, swap pos 1 with pos (17+1)=18
    - Result: 18 items, top=1, bottom=2
    """
    sender = pre.fund_eoa()

    # Build the exact bytecode from the EIP
    code = (
        Op.PUSH1[0x1]
        + Op.PUSH1[0x0]
        + Op.DUP1 * 15
        + Op.PUSH1[0x2]
        + Op.SWAPN[17]
    )
    assert bytes(code) == bytes.fromhex(
        "600160008080808080808080808080808080806002e780"
    )

    # Verify by storing top and bottom values
    code += Op.PUSH1(0) + Op.SSTORE  # Store top (should be 1) at key 0

    # Pop 16 items to get to bottom 1 item
    code += Op.POP * 16
    # Stack now has 1 item (bottom value = 2)

    # Store bottom value at key 1
    code += Op.PUSH1(1) + Op.SSTORE  # Store bottom (should be 2) at key 1
    code += Op.STOP

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

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.