Skip to content

Commit 94a7cc5

Browse files
committed
🧹 chore(tests): Move to new test file
1 parent 6218f55 commit 94a7cc5

File tree

2 files changed

+199
-176
lines changed

2 files changed

+199
-176
lines changed

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import pytest
44

55
from ethereum_test_tools import (
6-
AccessList,
76
Account,
87
Alloc,
98
Block,
109
BlockchainTestFiller,
11-
Hash,
1210
Storage,
1311
Transaction,
1412
compute_create_address,
@@ -286,177 +284,3 @@ def test_bal_code_changes(
286284
),
287285
},
288286
)
289-
290-
291-
@pytest.mark.valid_from("Amsterdam")
292-
def test_bal_2930_slot_listed_but_untouched(
293-
pre: Alloc,
294-
blockchain_test: BlockchainTestFiller,
295-
fork,
296-
):
297-
"""Ensure BAL excludes untouched access list storage slots."""
298-
alice = pre.fund_eoa()
299-
pure_calculator = pre.deploy_contract(
300-
# Pure add operation
301-
Op.ADD(35, 7)
302-
)
303-
304-
access_list = AccessList(
305-
address=pure_calculator,
306-
storage_keys=[Hash(0x1)],
307-
)
308-
309-
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
310-
gas_limit = (
311-
intrinsic_gas_calculator(
312-
calldata=b"",
313-
contract_creation=False,
314-
access_list=[access_list],
315-
)
316-
+ 1000
317-
) # intrinsic + buffer
318-
319-
tx = Transaction(
320-
ty=1, sender=alice, to=pure_calculator, gas_limit=gas_limit, access_list=[access_list]
321-
)
322-
323-
block = Block(
324-
txs=[tx],
325-
expected_block_access_list=BlockAccessListExpectation(
326-
account_expectations={
327-
alice: BalAccountExpectation(
328-
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
329-
),
330-
# The address excluded from BAL since state is not accessed
331-
pure_calculator: None,
332-
}
333-
),
334-
)
335-
336-
blockchain_test(
337-
pre=pre,
338-
blocks=[block],
339-
post={
340-
alice: Account(nonce=1),
341-
},
342-
)
343-
344-
345-
@pytest.mark.valid_from("Amsterdam")
346-
def test_bal_2930_slot_listed_and_unlisted_writes(
347-
pre: Alloc,
348-
blockchain_test: BlockchainTestFiller,
349-
fork,
350-
):
351-
"""Ensure BAL includes storage writes regardless of access list presence."""
352-
alice = pre.fund_eoa()
353-
storage_writer = pre.deploy_contract(code=Op.SSTORE(0x01, 0x42) + Op.SSTORE(0x02, 0x43))
354-
355-
# Access list only includes slot 0x01, but contract writes to both 0x01 and 0x02
356-
access_list = AccessList(
357-
address=storage_writer,
358-
storage_keys=[Hash(0x01)],
359-
)
360-
361-
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
362-
gas_limit = (
363-
intrinsic_gas_calculator(
364-
calldata=b"",
365-
contract_creation=False,
366-
access_list=[access_list],
367-
)
368-
+ 50000
369-
) # intrinsic + buffer for storage writes
370-
371-
tx = Transaction(
372-
ty=1, sender=alice, to=storage_writer, gas_limit=gas_limit, access_list=[access_list]
373-
)
374-
375-
block = Block(
376-
txs=[tx],
377-
expected_block_access_list=BlockAccessListExpectation(
378-
account_expectations={
379-
alice: BalAccountExpectation(
380-
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
381-
),
382-
storage_writer: BalAccountExpectation(
383-
storage_changes=[
384-
BalStorageSlot(
385-
slot=0x01,
386-
slot_changes=[BalStorageChange(tx_index=1, post_value=0x42)],
387-
),
388-
BalStorageSlot(
389-
slot=0x02,
390-
slot_changes=[BalStorageChange(tx_index=1, post_value=0x43)],
391-
),
392-
],
393-
),
394-
}
395-
),
396-
)
397-
398-
blockchain_test(
399-
pre=pre,
400-
blocks=[block],
401-
post={
402-
alice: Account(nonce=1),
403-
storage_writer: Account(storage={0x01: 0x42, 0x02: 0x43}),
404-
},
405-
)
406-
407-
408-
@pytest.mark.valid_from("Amsterdam")
409-
def test_bal_2930_slot_listed_and_unlisted_reads(
410-
pre: Alloc,
411-
blockchain_test: BlockchainTestFiller,
412-
fork,
413-
):
414-
"""Ensure BAL includes storage reads regardless of access list presence."""
415-
alice = pre.fund_eoa()
416-
storage_reader = pre.deploy_contract(
417-
code=Op.SLOAD(0x01) + Op.SLOAD(0x02),
418-
storage={0x01: 0x42, 0x02: 0x43}, # Pre-populate storage with values
419-
)
420-
421-
# Access list only includes slot 0x01, but contract reads from both 0x01 and 0x02
422-
access_list = AccessList(
423-
address=storage_reader,
424-
storage_keys=[Hash(0x01)],
425-
)
426-
427-
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
428-
gas_limit = (
429-
intrinsic_gas_calculator(
430-
calldata=b"",
431-
contract_creation=False,
432-
access_list=[access_list],
433-
)
434-
+ 50000
435-
) # intrinsic + buffer for storage reads
436-
437-
tx = Transaction(
438-
ty=1, sender=alice, to=storage_reader, gas_limit=gas_limit, access_list=[access_list]
439-
)
440-
441-
block = Block(
442-
txs=[tx],
443-
expected_block_access_list=BlockAccessListExpectation(
444-
account_expectations={
445-
alice: BalAccountExpectation(
446-
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
447-
),
448-
storage_reader: BalAccountExpectation(
449-
storage_reads=[0x01, 0x02],
450-
),
451-
}
452-
),
453-
)
454-
455-
blockchain_test(
456-
pre=pre,
457-
blocks=[block],
458-
post={
459-
alice: Account(nonce=1),
460-
storage_reader: Account(storage={0x01: 0x42, 0x02: 0x43}),
461-
},
462-
)
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
"""Tests for EIP-7928 for EIP-2930 transactions."""
2+
3+
import pytest
4+
5+
from ethereum_test_tools import (
6+
AccessList,
7+
Account,
8+
Alloc,
9+
Block,
10+
BlockchainTestFiller,
11+
Hash,
12+
Transaction,
13+
)
14+
from ethereum_test_tools.vm.opcode import Opcodes as Op
15+
from ethereum_test_types.block_access_list import (
16+
BalAccountExpectation,
17+
BalNonceChange,
18+
BalStorageChange,
19+
BalStorageSlot,
20+
BlockAccessListExpectation,
21+
)
22+
23+
from .spec import ref_spec_7928
24+
25+
REFERENCE_SPEC_GIT_PATH = ref_spec_7928.git_path
26+
REFERENCE_SPEC_VERSION = ref_spec_7928.version
27+
28+
pytestmark = pytest.mark.valid_from("Amsterdam")
29+
30+
31+
def test_bal_2930_slot_listed_but_untouched(
32+
pre: Alloc,
33+
blockchain_test: BlockchainTestFiller,
34+
fork,
35+
):
36+
"""Ensure BAL excludes untouched access list storage slots."""
37+
alice = pre.fund_eoa()
38+
pure_calculator = pre.deploy_contract(
39+
# Pure add operation
40+
Op.ADD(35, 7)
41+
)
42+
43+
access_list = AccessList(
44+
address=pure_calculator,
45+
storage_keys=[Hash(0x1)],
46+
)
47+
48+
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
49+
gas_limit = (
50+
intrinsic_gas_calculator(
51+
calldata=b"",
52+
contract_creation=False,
53+
access_list=[access_list],
54+
)
55+
+ 1000
56+
) # intrinsic + buffer
57+
58+
tx = Transaction(
59+
ty=1, sender=alice, to=pure_calculator, gas_limit=gas_limit, access_list=[access_list]
60+
)
61+
62+
block = Block(
63+
txs=[tx],
64+
expected_block_access_list=BlockAccessListExpectation(
65+
account_expectations={
66+
alice: BalAccountExpectation(
67+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
68+
),
69+
# The address excluded from BAL since state is not accessed
70+
pure_calculator: None,
71+
}
72+
),
73+
)
74+
75+
blockchain_test(
76+
pre=pre,
77+
blocks=[block],
78+
post={
79+
alice: Account(nonce=1),
80+
},
81+
)
82+
83+
84+
def test_bal_2930_slot_listed_and_unlisted_writes(
85+
pre: Alloc,
86+
blockchain_test: BlockchainTestFiller,
87+
fork,
88+
):
89+
"""Ensure BAL includes storage writes regardless of access list presence."""
90+
alice = pre.fund_eoa()
91+
storage_writer = pre.deploy_contract(code=Op.SSTORE(0x01, 0x42) + Op.SSTORE(0x02, 0x43))
92+
93+
# Access list only includes slot 0x01, but contract writes to both 0x01 and 0x02
94+
access_list = AccessList(
95+
address=storage_writer,
96+
storage_keys=[Hash(0x01)],
97+
)
98+
99+
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
100+
gas_limit = (
101+
intrinsic_gas_calculator(
102+
calldata=b"",
103+
contract_creation=False,
104+
access_list=[access_list],
105+
)
106+
+ 50000
107+
) # intrinsic + buffer for storage writes
108+
109+
tx = Transaction(
110+
ty=1, sender=alice, to=storage_writer, gas_limit=gas_limit, access_list=[access_list]
111+
)
112+
113+
block = Block(
114+
txs=[tx],
115+
expected_block_access_list=BlockAccessListExpectation(
116+
account_expectations={
117+
alice: BalAccountExpectation(
118+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
119+
),
120+
storage_writer: BalAccountExpectation(
121+
storage_changes=[
122+
BalStorageSlot(
123+
slot=0x01,
124+
slot_changes=[BalStorageChange(tx_index=1, post_value=0x42)],
125+
),
126+
BalStorageSlot(
127+
slot=0x02,
128+
slot_changes=[BalStorageChange(tx_index=1, post_value=0x43)],
129+
),
130+
],
131+
),
132+
}
133+
),
134+
)
135+
136+
blockchain_test(
137+
pre=pre,
138+
blocks=[block],
139+
post={
140+
alice: Account(nonce=1),
141+
storage_writer: Account(storage={0x01: 0x42, 0x02: 0x43}),
142+
},
143+
)
144+
145+
146+
def test_bal_2930_slot_listed_and_unlisted_reads(
147+
pre: Alloc,
148+
blockchain_test: BlockchainTestFiller,
149+
fork,
150+
):
151+
"""Ensure BAL includes storage reads regardless of access list presence."""
152+
alice = pre.fund_eoa()
153+
storage_reader = pre.deploy_contract(
154+
code=Op.SLOAD(0x01) + Op.SLOAD(0x02),
155+
storage={0x01: 0x42, 0x02: 0x43}, # Pre-populate storage with values
156+
)
157+
158+
# Access list only includes slot 0x01, but contract reads from both 0x01 and 0x02
159+
access_list = AccessList(
160+
address=storage_reader,
161+
storage_keys=[Hash(0x01)],
162+
)
163+
164+
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
165+
gas_limit = (
166+
intrinsic_gas_calculator(
167+
calldata=b"",
168+
contract_creation=False,
169+
access_list=[access_list],
170+
)
171+
+ 50000
172+
) # intrinsic + buffer for storage reads
173+
174+
tx = Transaction(
175+
ty=1, sender=alice, to=storage_reader, gas_limit=gas_limit, access_list=[access_list]
176+
)
177+
178+
block = Block(
179+
txs=[tx],
180+
expected_block_access_list=BlockAccessListExpectation(
181+
account_expectations={
182+
alice: BalAccountExpectation(
183+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
184+
),
185+
storage_reader: BalAccountExpectation(
186+
storage_reads=[0x01, 0x02],
187+
),
188+
}
189+
),
190+
)
191+
192+
blockchain_test(
193+
pre=pre,
194+
blocks=[block],
195+
post={
196+
alice: Account(nonce=1),
197+
storage_reader: Account(storage={0x01: 0x42, 0x02: 0x43}),
198+
},
199+
)

0 commit comments

Comments
 (0)