Skip to content

test_clz_call_operation()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_call_operation@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_call_operation --fork Osaka

Test CLZ opcode with call operation.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
@EIPChecklist.Opcode.Test.ExecutionContext.Call()
@EIPChecklist.Opcode.Test.ExecutionContext.Delegatecall()
@EIPChecklist.Opcode.Test.ExecutionContext.Callcode()
@EIPChecklist.Opcode.Test.ExecutionContext.Staticcall()
@pytest.mark.valid_from("Osaka")
@pytest.mark.parametrize(
    "opcode,context",
    [
        pytest.param(Op.CALL, CallingContext.callee_context, id="call"),
        pytest.param(Op.DELEGATECALL, CallingContext.caller_context, id="delegatecall"),
        pytest.param(Op.CALLCODE, CallingContext.caller_context, id="callcode"),
        pytest.param(Op.STATICCALL, CallingContext.no_context, id="staticcall"),
    ],
)
def test_clz_call_operation(
    state_test: StateTestFiller, pre: Alloc, opcode: Op, context: CallingContext
) -> None:
    """Test CLZ opcode with call operation."""
    test_cases = [0, 64, 255]

    # Storage Layout
    callee_storage = Storage()
    caller_storage = Storage()

    callee_code = Bytecode()

    for bits in reversed(test_cases):
        callee_code += Op.CLZ(1 << bits)

    if context != CallingContext.no_context:
        for bits in test_cases:
            callee_code += Op.SSTORE(callee_storage.store_next(255 - bits), Op.CLZ(1 << bits))

    for i in range(len(test_cases)):
        callee_code += Op.PUSH32(i * 0x20) + Op.MSTORE

    callee_code += Op.RETURN(0, len(test_cases) * 0x20)

    callee_address = pre.deploy_contract(code=callee_code)

    caller_code = opcode(
        gas=0xFFFF, address=callee_address, ret_offset=0, ret_size=len(test_cases) * 0x20
    )

    for i, bits in enumerate(test_cases):
        caller_code += Op.SSTORE(caller_storage.store_next(255 - bits), Op.MLOAD(i * 0x20))

    caller_address = pre.deploy_contract(code=caller_code)

    tx = Transaction(
        to=caller_address,
        sender=pre.fund_eoa(),
        gas_limit=200_000,
    )

    post = {}

    if context == CallingContext.caller_context:
        post[caller_address] = Account(storage=callee_storage)
    elif context == CallingContext.callee_context:
        post[callee_address] = Account(storage=callee_storage)
        post[caller_address] = Account(storage=caller_storage)
    elif context == CallingContext.no_context:
        post[caller_address] = Account(storage=caller_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 context
...fork_Osaka-state_test-call CALL 1
...fork_Osaka-state_test-delegatecall DELEGATECALL 2
...fork_Osaka-state_test-callcode CALLCODE 2
...fork_Osaka-state_test-staticcall STATICCALL 3
...fork_Osaka-blockchain_test_from_state_test-call CALL 1
...fork_Osaka-blockchain_test_from_state_test-delegatecall DELEGATECALL 2
...fork_Osaka-blockchain_test_from_state_test-callcode CALLCODE 2
...fork_Osaka-blockchain_test_from_state_test-staticcall STATICCALL 3