Skip to content

test_eip_vector_exchange_30_items()

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

EIP test vector (30-item EXCHANGE).

Bytecode: 600080...(27x DUP1)...60016002e88f. decode_pair(0x8f / 143) = (1, 29), swaps positions 2 and 30. Results in 30 stack items, top=2, bottom=1, rest=0.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
def test_eip_vector_exchange_30_items(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector (30-item EXCHANGE).

    Bytecode: 600080...(27x DUP1)...60016002e88f.
    decode_pair(0x8f / 143) = (1, 29), swaps positions 2 and 30.
    Results in 30 stack items, top=2, bottom=1, rest=0.
    """
    sender = pre.fund_eoa()

    code = (
        Op.PUSH1[0x0]
        + Op.DUP1 * 27
        + Op.PUSH1[0x1]
        + Op.PUSH1[0x2]
        + Op.EXCHANGE[b"\x8f"]
    )
    assert bytes(code) == bytes.fromhex("6000" + "80" * 27 + "60016002e88f")
    # 30 items: pos 1=2, pos 2=1, rest=0
    # After EXCHANGE(1,29): swap pos 2 and 30 -> pos 2=0, pos 30=1
    # Result: top=2, bottom=1, rest=0

    # Store top value
    code += Op.PUSH1(0) + Op.SSTORE  # top = 2

    # Pop to get to bottom
    code += Op.POP * 28

    # Store bottom value
    code += Op.PUSH1(1) + Op.SSTORE  # bottom = 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: 2,  # top = 2 (unchanged)
                1: 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.