Skip to content

test_clz_from_set_code()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_from_set_code@e9958ed2.

Generate fixtures for these test cases for Osaka with:

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

Test the address opcode in a set-code transaction.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
@EIPChecklist.Opcode.Test.ExecutionContext.SetCode()
@pytest.mark.valid_from("Osaka")
def test_clz_from_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """Test the address opcode in a set-code transaction."""
    storage = Storage()
    auth_signer = pre.fund_eoa(auth_account_start_balance)

    set_code = Bytecode()
    for bits in [0, 1, 128, 255]:
        expected_clz = 255 - bits
        set_code += Op.SSTORE(storage.store_next(expected_clz), Op.CLZ(1 << bits))
    set_code += Op.STOP

    set_code_to_address = pre.deploy_contract(set_code)

    tx = Transaction(
        gas_limit=200_000,
        to=auth_signer,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address: Account(storage={}),
            auth_signer: Account(
                nonce=1,
                code=Spec7702.delegation_designation(set_code_to_address),
                storage=storage,
            ),
        },
    )

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test