Skip to content

test_clz_gas_cost_boundary()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_gas_cost_boundary@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_gas_cost_boundary --fork Amsterdam

Test CLZ opcode gas cost boundary.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
@EIPChecklist.Opcode.Test.GasUsage.Normal()
@EIPChecklist.Opcode.Test.GasUsage.OutOfGasExecution()
@EIPChecklist.Opcode.Test.GasUsage.ExtraGas()
@pytest.mark.valid_from("Osaka")
@pytest.mark.parametrize("bits", [0, 64, 128, 255])
@pytest.mark.parametrize("gas_cost_delta", [-2, -1, 0, 1, 2])
def test_clz_gas_cost_boundary(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    bits: int,
    gas_cost_delta: int,
) -> None:
    """Test CLZ opcode gas cost boundary."""
    code = Op.PUSH32(1 << bits) + Op.CLZ

    contract_address = pre.deploy_contract(code=code)

    call_code = Op.SSTORE(
        0,
        Op.CALL(
            gas=code.gas_cost(fork) + gas_cost_delta,
            address=contract_address,
        ),
    )
    call_address = pre.deploy_contract(
        code=call_code,
        storage={"0x00": "0xdeadbeef"},
    )

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

    post = {
        call_address: Account(storage={"0x00": 0 if gas_cost_delta < 0 else 1})
    }

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

Parametrized Test Cases

This test generates 20 parametrized test cases across 2 forks.