Skip to content

test_clz_push_operation_same_value()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_push_operation_same_value@21507778.

Generate fixtures for these test cases for Amsterdam with:

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

Test CLZ opcode returns the same value via different push operations.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
@pytest.mark.valid_from("Osaka")
def test_clz_push_operation_same_value(
    state_test: StateTestFiller, pre: Alloc
) -> None:
    """Test CLZ opcode returns the same value via different push operations."""
    storage = {}

    code = Op.SSTORE(0, Op.CLZ(Op.PUSH0))
    storage[0x00] = 256

    for bit in range(1, 33):  # PUSH value
        for push_n in range(bit, 33):  # PUSHn opcode
            op = getattr(Op, f"PUSH{push_n}")
            key = 100 * bit + push_n
            code += Op.SSTORE(key, Op.CLZ(op[1 << bit]))
            storage[key] = 255 - bit

    code_address = pre.deploy_contract(code=code)

    tx = Transaction(
        to=code_address,
        sender=pre.fund_eoa(),
        gas_limit=12_000_000,
    )

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.