Skip to content

Commit e8f0756

Browse files
feat: add eip7702 test case for clz opcode
1 parent df014bf commit e8f0756

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py

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

23+
from ...prague.eip7702_set_code_tx.spec import Spec as Spec7702
2024
from .spec import Spec, ref_spec_7939
2125

2226
REFERENCE_SPEC_GIT_PATH = ref_spec_7939.git_path
@@ -222,3 +226,50 @@ def test_clz_fork_transition(blockchain_test: BlockchainTestFiller, pre: Alloc):
222226
),
223227
},
224228
)
229+
230+
231+
auth_account_start_balance = 0
232+
233+
234+
@pytest.mark.valid_from("Osaka")
235+
@pytest.mark.parametrize("bits", [0, 1, 128, 255])
236+
def test_clz_from_set_code(
237+
state_test: StateTestFiller,
238+
pre: Alloc,
239+
bits: int,
240+
):
241+
"""Test the address opcode in a set-code transaction."""
242+
storage = Storage()
243+
auth_signer = pre.fund_eoa(auth_account_start_balance)
244+
245+
expected_clz = 255 - bits
246+
set_code = Op.SSTORE(storage.store_next(expected_clz), Op.CLZ(1 << bits)) + Op.STOP
247+
set_code_to_address = pre.deploy_contract(set_code)
248+
249+
tx = Transaction(
250+
gas_limit=10_000_000,
251+
to=auth_signer,
252+
value=0,
253+
authorization_list=[
254+
AuthorizationTuple(
255+
address=set_code_to_address,
256+
nonce=0,
257+
signer=auth_signer,
258+
),
259+
],
260+
sender=pre.fund_eoa(),
261+
)
262+
263+
state_test(
264+
env=Environment(),
265+
pre=pre,
266+
tx=tx,
267+
post={
268+
set_code_to_address: Account(storage={}),
269+
auth_signer: Account(
270+
nonce=1,
271+
code=Spec7702.delegation_designation(set_code_to_address),
272+
storage=storage,
273+
),
274+
},
275+
)

0 commit comments

Comments
 (0)