Skip to content

test_exchange_all_valid_immediates()

Documentation for tests/prague/eip7692_eof_v1/eip663_dupn_swapn_exchange/test_exchange.py::test_exchange_all_valid_immediates@verkle@v0.0.6.

Generate fixtures for these test cases for Pragueeip7692 with:

Pragueeip7692 only:

fill -v tests/prague/eip7692_eof_v1/eip663_dupn_swapn_exchange/test_exchange.py::test_exchange_all_valid_immediates --fork=PragueEIP7692 --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Pragueeip7692:

fill -v tests/prague/eip7692_eof_v1/eip663_dupn_swapn_exchange/test_exchange.py::test_exchange_all_valid_immediates --until=PragueEIP7692

Test case for all valid EXCHANGE immediates.

Source code in tests/prague/eip7692_eof_v1/eip663_dupn_swapn_exchange/test_exchange.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@pytest.mark.valid_from(EOF_FORK_NAME)
def test_exchange_all_valid_immediates(eof_state_test: EOFStateTestFiller):
    """
    Test case for all valid EXCHANGE immediates.
    """
    n = 256
    s = 34
    values = range(0x3E8, 0x3E8 + s)

    eof_code = Container(
        sections=[
            Section.Code(
                code=sum(Op.PUSH2[v] for v in values)
                + sum(Op.EXCHANGE[x] for x in range(0, n))
                + sum((Op.PUSH1[x] + Op.SSTORE) for x in range(0, s))
                + Op.STOP,
            )
        ],
    )

    # this does the same full-loop exchange
    values_rotated = list(range(0x3E8, 0x3E8 + s))
    for e in range(0, n):
        a = (e >> 4) + 1
        b = (e & 0x0F) + 1 + a
        temp = values_rotated[a]
        values_rotated[a] = values_rotated[b]
        values_rotated[b] = temp

    post = Account(storage=dict(zip(range(0, s), reversed(values_rotated))))

    eof_state_test(
        tx_sender_funding_amount=1_000_000_000,
        data=eof_code,
        container_post=post,
    )