Skip to content

test_dupn_with_dup1_sequence()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_with_dup1_sequence@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

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

Test DUPN duplicating the bottom item after building stack with DUP1.

Stack layout: PUSH1(1) PUSH1(0) DUP1*15 DUPN[0x80] Before DUPN: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] After DUPN[0x80] (decode_single(0x80)=17): [1, 0, 0, ..., 0, 1] Result: 18 stack items, top=1, bottom=1, rest=0

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def test_dupn_with_dup1_sequence(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test DUPN duplicating the bottom item after building stack with DUP1.

    Stack layout: PUSH1(1) PUSH1(0) DUP1*15 DUPN[0x80]
    Before DUPN: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
    After DUPN[0x80] (decode_single(0x80)=17): [1, 0, 0, ..., 0, 1]
    Result: 18 stack items, top=1, bottom=1, rest=0
    """
    sender = pre.fund_eoa()

    # Build the stack: PUSH1(1), PUSH1(0), 15x DUP1
    code = Bytecode()
    code += Op.PUSH1(1)  # Bottom of stack (position 17 after DUP1s)
    code += Op.PUSH1(0)
    for _ in range(15):
        code += Op.DUP1

    # Stack now has 17 items:
    # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
    # DUPN with immediate 0x80 (decode_single(0x80) = 17) duplicates pos 17
    # Pass as bytes (raw immediate byte for testing)
    code += Op.DUPN[b"\x80"]

    # Store all stack values to verify
    for i in range(18):
        code += Op.PUSH1(i) + Op.SSTORE

    code += Op.STOP

    contract_address = pre.deploy_contract(code=code)

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

    # Expected: top (position 0) = 1, bottom (position 17) = 1, all others = 0
    expected_storage = {}
    for i in range(18):
        if i == 0:
            expected_storage[i] = 1  # Top of stack after DUPN
        elif i == 17:
            expected_storage[i] = 1  # Bottom of stack
        else:
            expected_storage[i] = 0  # All middle values

    post = {contract_address: Account(storage=expected_storage)}

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.