Skip to content

test_dupn_valid_immediates()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_valid_immediates@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_valid_immediates --fork Amsterdam

Test DUPN with valid immediate values (0-90 and 128-255).

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
 71
 72
 73
 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
@pytest.mark.parametrize(
    "immediate",
    [0, 45, 90, 128, 200, 255],
    ids=lambda x: f"dupn_imm_{x}",
)
def test_dupn_valid_immediates(
    immediate: int,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """Test DUPN with valid immediate values (0-90 and 128-255)."""
    sender = pre.fund_eoa()

    # Decode the immediate to get the stack index
    stack_index = decode_single(immediate)
    stack_height = stack_index
    expected_value = 0xCAFE + immediate

    # Push values onto stack
    code = Bytecode()
    for i in range(stack_height):
        if i == 0:
            code += Op.PUSH2(expected_value)
        else:
            code += Op.PUSH2(0x1000 + i)

    # Pass immediate as bytes (raw immediate byte for testing)
    code += Op.DUPN[immediate.to_bytes(1, "big")]
    code += Op.PUSH1(0) + Op.SSTORE
    code += Op.STOP

    contract_address = pre.deploy_contract(code=code)

    tx = Transaction(to=contract_address, sender=sender)

    post = {contract_address: Account(storage={0: expected_value})}

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

Parametrized Test Cases

This test generates 6 parametrized test cases across 1 fork.