Skip to content

test_clz_initcode_create()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_initcode_create@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

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

Test CLZ opcode behavior when creating a contract.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
@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

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) opcode
...fork_Osaka-state_test-opcode_CREATE CREATE
...fork_Osaka-state_test-opcode_CREATE2 CREATE2
...fork_Osaka-blockchain_test_from_state_test-opcode_CREATE CREATE
...fork_Osaka-blockchain_test_from_state_test-opcode_CREATE2 CREATE2