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@20373115.

Generate fixtures for these test cases for Amsterdam with:

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

Test the address opcode in a set-code transaction.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
@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 generates 1 parametrized test case across 2 forks.