Skip to content

test_clz_mainnet()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_eip_mainnet.py::test_clz_mainnet@892e6d1e.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7939_count_leading_zeros/test_eip_mainnet.py::test_clz_mainnet --fork Osaka

Test CLZ opcode on mainnet.

Source code in tests/osaka/eip7939_count_leading_zeros/test_eip_mainnet.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@pytest.mark.parametrize(
    "clz_input,clz_expected",
    [
        pytest.param(
            0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            8,
            id="clz-8-leading-zeros",
        ),
        pytest.param(0, 256, id="clz-all-zeros"),
    ],
)
def test_clz_mainnet(
    state_test: StateTestFiller,
    pre: Alloc,
    clz_input: int,
    clz_expected: int,
) -> None:
    """
    Test CLZ opcode on mainnet.
    """
    sender = pre.fund_eoa()
    contract_address = pre.deploy_contract(
        code=Op.SSTORE(0, Op.CLZ(clz_input)),
        storage={"0x00": "0xdeadbeef"},
    )
    tx = Transaction(
        ty=0x02,
        to=contract_address,
        sender=sender,
        gas_limit=200_000,
    )
    post = {
        contract_address: Account(storage={"0x00": clz_expected}),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.