Skip to content

test_clz_fork_transition()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_fork_transition@892e6d1e.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_fork_transition --fork Osaka

Test CLZ opcode behavior at fork transition.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
@EIPChecklist.Opcode.Test.ForkTransition.Invalid()
@EIPChecklist.Opcode.Test.ForkTransition.At()
@pytest.mark.valid_at_transition_to("Osaka")
def test_clz_fork_transition(
    blockchain_test: BlockchainTestFiller, pre: Alloc
) -> None:
    """Test CLZ opcode behavior at fork transition."""
    sender = pre.fund_eoa()
    callee_address = pre.deploy_contract(
        code=Op.SSTORE(Op.TIMESTAMP, Op.CLZ(1 << 100)) + Op.STOP,
        storage={14_999: "0xdeadbeef"},
    )
    caller_address = pre.deploy_contract(
        code=Op.SSTORE(
            Op.TIMESTAMP, Op.CALL(gas=0xFFFF, address=callee_address)
        ),
        storage={14_999: "0xdeadbeef"},
    )
    blocks = [
        Block(
            timestamp=14_999,
            txs=[
                Transaction(
                    to=caller_address,
                    sender=sender,
                    nonce=0,
                    gas_limit=200_000,
                )
            ],
        ),
        Block(
            timestamp=15_000,
            txs=[
                Transaction(
                    to=caller_address,
                    sender=sender,
                    nonce=1,
                    gas_limit=200_000,
                )
            ],
        ),
        Block(
            timestamp=15_001,
            txs=[
                Transaction(
                    to=caller_address,
                    sender=sender,
                    nonce=2,
                    gas_limit=200_000,
                )
            ],
        ),
    ]
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            caller_address: Account(
                storage={
                    14_999: 0,  # Call fails as opcode not valid before Osaka
                    15_000: 1,  # Call succeeds on fork transition block
                    15_001: 1,  # Call continues to succeed after transition
                }
            ),
            callee_address: Account(
                storage={
                    # CLZ not valid before fork, storage unchanged
                    14_999: "0xdeadbeef",
                    # CLZ valid on transition block, CLZ(1 << 100) = 155
                    15_000: 155,
                    # CLZ continues to be valid after transition
                    15_001: 155,
                }
            ),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.