Skip to content

Commit 71b4a57

Browse files
feat(tests): add jump operation test case for CLZ (#1824)
* feat(clz): add jump operation test case for CLZ * refactor(tests): update CLZ jump operation test to use opcode parameterization * refactor(tests): enhance CLZ jump operation test with additional parameterization
1 parent 5097bf7 commit 71b4a57

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,57 @@ def test_clz_fork_transition(blockchain_test: BlockchainTestFiller, pre: Alloc):
222222
),
223223
},
224224
)
225+
226+
227+
@pytest.mark.valid_from("Osaka")
228+
@pytest.mark.parametrize("opcode", [Op.JUMPI, Op.JUMP])
229+
@pytest.mark.parametrize("valid_jump", [True, False])
230+
@pytest.mark.parametrize("jumpi_condition", [True, False])
231+
@pytest.mark.parametrize("bits", [0, 16, 64, 128, 255])
232+
def test_clz_jump_operation(
233+
state_test: StateTestFiller,
234+
pre: Alloc,
235+
opcode: Op,
236+
valid_jump: bool,
237+
jumpi_condition: bool,
238+
bits: int,
239+
):
240+
"""Test CLZ opcode with valid and invalid jump."""
241+
if opcode == Op.JUMP and not jumpi_condition:
242+
pytest.skip("Duplicate case for JUMP.")
243+
244+
code = Op.PUSH32(1 << bits)
245+
246+
if opcode == Op.JUMPI:
247+
code += Op.PUSH1(jumpi_condition)
248+
249+
code += Op.PUSH1(len(code) + 3) + opcode
250+
251+
if valid_jump:
252+
code += Op.JUMPDEST
253+
254+
code += Op.CLZ + Op.PUSH0 + Op.SSTORE + Op.RETURN(0, 0)
255+
256+
callee_address = pre.deploy_contract(code=code)
257+
258+
caller_address = pre.deploy_contract(
259+
code=Op.SSTORE(0, Op.CALL(gas=0xFFFF, address=callee_address)),
260+
storage={"0x00": "0xdeadbeef"},
261+
)
262+
263+
tx = Transaction(
264+
to=caller_address,
265+
sender=pre.fund_eoa(),
266+
gas_limit=200_000,
267+
)
268+
269+
expected_clz = 255 - bits
270+
271+
post = {
272+
caller_address: Account(storage={"0x00": 1 if valid_jump or not jumpi_condition else 0}),
273+
}
274+
275+
if valid_jump or not jumpi_condition:
276+
post[callee_address] = Account(storage={"0x00": expected_clz})
277+
278+
state_test(pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)