Skip to content

test_dupn_multiple_consecutive_pc_advancement()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py::test_dupn_multiple_consecutive_pc_advancement@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py::test_dupn_multiple_consecutive_pc_advancement --fork Amsterdam

Verify PC advances correctly with multiple consecutive DUPN opcodes.

Tests that each DUPN independently advances PC by 2 bytes.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def test_dupn_multiple_consecutive_pc_advancement(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Verify PC advances correctly with multiple consecutive DUPN opcodes.

    Tests that each DUPN independently advances PC by 2 bytes.
    """
    sender = pre.fund_eoa()

    code = Bytecode()

    # Push enough values for multiple DUPNs
    for i in range(20):
        code += Op.PUSH1(i)

    # Capture initial PC
    code += Op.PC
    code += Op.PUSH1(1) + Op.SSTORE

    # Execute three consecutive DUPNs
    code += Op.DUPN[17]
    code += Op.DUPN[18]
    code += Op.DUPN[19]

    # Capture final PC
    code += Op.PC
    code += Op.PUSH1(2) + Op.SSTORE

    # Calculate difference
    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

    # 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)

    post = {
        contract_address: Account(
            storage={
                0: 10,  # PUSH1(2) + SSTORE(1) + DUPN(2)*3 + PC(1) = 10
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.