Skip to content

Commit 78c3cff

Browse files
feat(tests): add eip7702 test case for clz opcode (#1853)
* feat: add eip7702 test case for clz opcode * refactor(tests): update clz test to reduce test number * Update tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py * fix: merge issue --------- Co-authored-by: Mario Vega <[email protected]>
1 parent f41c57e commit 78c3cff

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
from ethereum_test_tools import (
1111
Account,
1212
Alloc,
13+
AuthorizationTuple,
1314
Block,
1415
BlockchainTestFiller,
16+
Bytecode,
1517
CodeGasMeasure,
18+
Environment,
1619
StateTestFiller,
1720
Transaction,
1821
)
1922
from ethereum_test_tools.vm.opcode import Opcodes as Op
2023

24+
from ...prague.eip7702_set_code_tx.spec import Spec as Spec7702
2125
from .spec import Spec, ref_spec_7939
2226

2327
REFERENCE_SPEC_GIT_PATH = ref_spec_7939.git_path
@@ -313,6 +317,55 @@ def test_clz_jump_operation(
313317
state_test(pre=pre, post=post, tx=tx)
314318

315319

320+
auth_account_start_balance = 0
321+
322+
323+
@pytest.mark.valid_from("Osaka")
324+
def test_clz_from_set_code(
325+
state_test: StateTestFiller,
326+
pre: Alloc,
327+
):
328+
"""Test the address opcode in a set-code transaction."""
329+
storage = Storage()
330+
auth_signer = pre.fund_eoa(auth_account_start_balance)
331+
332+
set_code = Bytecode()
333+
for bits in [0, 1, 128, 255]:
334+
expected_clz = 255 - bits
335+
set_code += Op.SSTORE(storage.store_next(expected_clz), Op.CLZ(1 << bits))
336+
set_code += Op.STOP
337+
338+
set_code_to_address = pre.deploy_contract(set_code)
339+
340+
tx = Transaction(
341+
gas_limit=200_000,
342+
to=auth_signer,
343+
value=0,
344+
authorization_list=[
345+
AuthorizationTuple(
346+
address=set_code_to_address,
347+
nonce=0,
348+
signer=auth_signer,
349+
),
350+
],
351+
sender=pre.fund_eoa(),
352+
)
353+
354+
state_test(
355+
env=Environment(),
356+
pre=pre,
357+
tx=tx,
358+
post={
359+
set_code_to_address: Account(storage={}),
360+
auth_signer: Account(
361+
nonce=1,
362+
code=Spec7702.delegation_designation(set_code_to_address),
363+
storage=storage,
364+
),
365+
},
366+
)
367+
368+
316369
@pytest.mark.valid_from("Osaka")
317370
@pytest.mark.parametrize("bits", [0, 64, 255])
318371
@pytest.mark.parametrize("opcode", [Op.CODECOPY, Op.EXTCODECOPY])

0 commit comments

Comments
 (0)