Skip to content

Commit 9626bd8

Browse files
committed
fix(tests,lint): Set up code changes test case; fix remaining lint issues
1 parent cde9f15 commit 9626bd8

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

tests/osaka/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
Block,
99
BlockchainTestFiller,
1010
Transaction,
11+
compute_create_address,
1112
)
1213
from ethereum_test_tools.vm.opcode import Opcodes as Op
1314
from ethereum_test_types.block_access_list import (
1415
BalAccountChange,
1516
BalBalanceChange,
17+
BalCodeChange,
1618
BalNonceChange,
1719
BalStorageChange,
1820
BalStorageSlot,
@@ -87,7 +89,9 @@ def test_bal_balance_changes(
8789
)
8890

8991
block = Block(txs=[tx])
90-
alice_initial_balance = pre[alice].balance
92+
alice_account = pre[alice]
93+
assert alice_account is not None, "Alice account should exist"
94+
alice_initial_balance = alice_account.balance
9195

9296
# Account for both the value sent and gas cost (gas_price * gas_used)
9397
alice_final_balance = alice_initial_balance - 100 - (intrinsic_gas_cost * 1_000_000_000)
@@ -202,17 +206,32 @@ def test_bal_code_changes(
202206
blockchain_test: BlockchainTestFiller,
203207
):
204208
"""Ensure BAL captures changes to account code."""
205-
deployed_code = Op.PUSH1(0x42) + Op.PUSH1(0x00) + Op.SSTORE + Op.STOP
209+
runtime_code = Op.STOP
210+
runtime_code_bytes = bytes(runtime_code)
211+
212+
init_code = (
213+
Op.PUSH1(len(runtime_code_bytes)) # size = 1
214+
+ Op.DUP1 # duplicate size for return
215+
+ Op.PUSH1(0x0C) # offset in init code where runtime code starts
216+
+ Op.PUSH1(0x00) # dest offset
217+
+ Op.CODECOPY # copy runtime code to memory
218+
+ Op.PUSH1(0x00) # memory offset for return
219+
+ Op.RETURN # return runtime code
220+
+ runtime_code # the actual runtime code to deploy
221+
)
222+
init_code_bytes = bytes(init_code)
206223

207-
deployed_code_bytes = bytes(deployed_code)
224+
# Factory contract that uses CREATE to deploy
208225
factory_code = (
209-
Op.PUSH32(deployed_code_bytes) # Contract code
210-
+ Op.PUSH1(0x00) # Memory offset
211-
+ Op.MSTORE # Store code in memory
212-
+ Op.PUSH1(len(deployed_code_bytes)) # Code size
213-
+ Op.PUSH1(0x00) # Memory offset
214-
+ Op.PUSH1(0x00) # Value to send
215-
+ Op.CREATE # CREATE opcode
226+
# Push init code to memory
227+
Op.PUSH32(init_code_bytes)
228+
+ Op.PUSH1(0x00)
229+
+ Op.MSTORE # Store at memory position 0
230+
# CREATE parameters: value, offset, size
231+
+ Op.PUSH1(len(init_code_bytes)) # size of init code
232+
+ Op.PUSH1(32 - len(init_code_bytes)) # offset in memory (account for padding)
233+
+ Op.PUSH1(0x00) # value = 0 (no ETH sent)
234+
+ Op.CREATE # Deploy the contract
216235
+ Op.STOP
217236
)
218237

@@ -227,29 +246,33 @@ def test_bal_code_changes(
227246

228247
block = Block(txs=[tx])
229248

230-
# The CREATE opcode will deploy to a deterministic address
231-
# We'll need to calculate or determine what that address will be
232-
# For now, we'll focus on the factory contract having a code change
249+
created_contract = compute_create_address(address=factory_contract, nonce=1)
250+
233251
blockchain_test(
234252
pre=pre,
235253
blocks=[block],
236254
post={
237255
alice: Account(nonce=1),
238-
factory_contract: Account(),
239-
# The newly created contract would be here but we'd need to calculate its address
256+
factory_contract: Account(nonce=2), # incremented by CREATE to 2
257+
created_contract: Account(
258+
code=runtime_code_bytes,
259+
storage={},
260+
),
240261
},
241-
# Note: This test might need adjustment based on how CREATE addresses are calculated
242-
# and how code changes are tracked in the BAL
243262
expected_block_access_list=BlockAccessList(
244263
account_changes=[
245-
# {
246-
# "address": alice,
247-
# "nonce_changes": [{"tx_index": 0, "post_nonce": 1}],
248-
# },
249-
# {
250-
# "address": factory_contract,
251-
# "code_changes": [{"tx_index": 0, "new_code": deployed_code}],
252-
# },
264+
BalAccountChange(
265+
address=alice,
266+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
267+
),
268+
BalAccountChange(
269+
address=factory_contract,
270+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=2)],
271+
),
272+
BalAccountChange(
273+
address=created_contract,
274+
code_changes=[BalCodeChange(tx_index=1, new_code=runtime_code_bytes)],
275+
),
253276
]
254277
),
255278
)

0 commit comments

Comments
 (0)