Skip to content

test_vector_exchange_valid_0x50()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test vector: e850 [EXCHANGE 14 16].

EXCHANGE with immediate 0x50 (80 decimal) is valid. decode_pair(0x50) = (14, 16), swaps positions 15 and 17.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
def test_vector_exchange_valid_0x50(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test vector: e850 [EXCHANGE 14 16].

    EXCHANGE with immediate 0x50 (80 decimal) is valid.
    decode_pair(0x50) = (14, 16), swaps positions 15 and 17.
    """
    sender = pre.fund_eoa()

    # Build stack with 17 items, with known values at positions 15 and 17
    code = Bytecode()
    for i in range(17):
        stack_pos = 17 - i  # Position from top (1-indexed)
        if stack_pos == 15:
            code += Op.PUSH2(0xAAAA)
        elif stack_pos == 17:
            code += Op.PUSH2(0xBBBB)
        else:
            code += Op.PUSH2(0x1000 + i)

    # EXCHANGE with immediate 0x50 - swaps positions 15 and 17
    code += Op.EXCHANGE[b"\x50"]

    # Store swapped positions to verify
    # Pop to position 15 (pop 14 items)
    for _ in range(14):
        code += Op.POP
    code += Op.PUSH1(0) + Op.SSTORE  # Position 15 (was 0xBBBB)
    code += Op.POP  # Skip position 16
    code += Op.PUSH1(1) + Op.SSTORE  # Position 17 (was 0xAAAA)
    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: 0xBBBB,  # Position 15 now has value from 17
                1: 0xAAAA,  # Position 17 now has value from 15
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.