Skip to content

test_clz_initcode_create()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test CLZ opcode behavior when creating a contract.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
@EIPChecklist.Opcode.Test.ExecutionContext.Initcode.Behavior.Opcode()
@pytest.mark.valid_from("Osaka")
@pytest.mark.parametrize("opcode", [Op.CREATE, Op.CREATE2])
def test_clz_initcode_create(
    state_test: StateTestFiller, pre: Alloc, opcode: Op
) -> None:
    """Test CLZ opcode behavior when creating a contract."""
    bits = [0, 1, 64, 128, 255]  # expected values: [255, 254, 191, 127, 0]

    storage = Storage()
    ext_code = Bytecode()

    for bit in bits:
        ext_code += Op.SSTORE(storage.store_next(255 - bit), Op.CLZ(1 << bit))

    sender_address = pre.fund_eoa()

    create_contract = (
        Op.CALLDATACOPY(offset=0, size=len(ext_code))
        + opcode(offset=0, size=len(ext_code))
        + Op.STOP
    )

    factory_contract_address = pre.deploy_contract(code=create_contract)

    created_contract_address = compute_create_address(
        address=factory_contract_address,
        nonce=1,
        initcode=ext_code,
        opcode=opcode,
    )

    tx = Transaction(
        to=factory_contract_address,
        gas_limit=200_000,
        data=ext_code,
        sender=sender_address,
    )

    post = {
        created_contract_address: Account(
            storage=storage,
        ),
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.