Skip to content

test_mixed_opcodes_pc_advancement()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py::test_mixed_opcodes_pc_advancement@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

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

Verify PC advances correctly with mixed DUPN, SWAPN, and EXCHANGE opcodes.

Tests that different EIP-8024 opcodes each correctly advance PC by 2 bytes.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_pc_advancement.py
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
def test_mixed_opcodes_pc_advancement(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Verify PC advances correctly with mixed DUPN, SWAPN, and EXCHANGE opcodes.

    Tests that different EIP-8024 opcodes each correctly advance PC by 2 bytes.
    """
    sender = pre.fund_eoa()

    code = Bytecode()

    # Push enough values for all operations
    for i in range(30):
        code += Op.PUSH1(i)

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

    # Execute one of each opcode
    code += Op.DUPN[17]
    code += Op.SWAPN[18]
    code += Op.EXCHANGE[1, 5]

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

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.