test_dupn_pc_advances_by_2()
Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py::test_dupn_pc_advances_by_2@9c2813ee.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py::test_dupn_pc_advances_by_2 --fork Amsterdam
Verify PC advances by 2 after DUPN (opcode + immediate byte).
Tests that DUPN consumes the immediate byte and advances PC correctly.
Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 | def test_dupn_pc_advances_by_2(
pre: Alloc,
state_test: StateTestFiller,
) -> None:
"""
Verify PC advances by 2 after DUPN (opcode + immediate byte).
Tests that DUPN consumes the immediate byte and advances PC correctly.
"""
sender = pre.fund_eoa()
code = Bytecode()
# Push 17 values so DUPN[17] will work
for i in range(17):
code += Op.PUSH1(i)
# Capture PC before DUPN and store it
code += Op.PC
code += Op.PUSH1(1) + Op.SSTORE # Store PC_before at key 1
# Execute DUPN - should advance PC by 2 (opcode + immediate)
code += Op.DUPN[17]
# Capture PC after DUPN and store it
code += Op.PC
code += Op.PUSH1(2) + Op.SSTORE # Store PC_after at key 2
# Calculate difference: get both values and subtract
code += Op.PUSH1(1) + Op.SLOAD # Load PC_before
code += Op.PUSH1(2) + Op.SLOAD # Load PC_after
code += Op.SUB # PC_after - PC_before (SUB does: second - top)
# Store the difference
code += Op.PUSH1(0) + Op.SSTORE
# Clean up intermediate storage
code += Op.PUSH1(0) + Op.PUSH1(1) + Op.SSTORE # Clear key 1
code += Op.PUSH1(0) + Op.PUSH1(2) + Op.SSTORE # Clear key 2
code += Op.STOP
contract_address = pre.deploy_contract(code=code)
tx = Transaction(to=contract_address, sender=sender, gas_limit=1_000_000)
# The difference should be:
# PUSH1(2) + SSTORE(1) + DUPN(2) + PC(1) = 6
# Note: Keys 1 and 2 are used for intermediate storage
post = {
contract_address: Account(
storage={
0: 6, # PC_after - PC_before (the main result)
# Keys 1 and 2 contain PC_before and PC_after for debugging
}
)
}
state_test(pre=pre, post=post, tx=tx)
|
Parametrized Test Cases
This test generates 1 parametrized test case across 1 fork.