Skip to content

Commit 303b9bf

Browse files
committed
fix: Number -> HexNumber for BAL types
- This becomes an issue when JSON-serializing the BAL object and then re-filling from the fixture. We should use `HexNumber` for any Number fields as this correctly serializes to JSON as hex representation.
1 parent 114e976 commit 303b9bf

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/ethereum_test_types/block_access_list/__init__.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
CamelModel,
1818
EthereumTestRootModel,
1919
HexNumber,
20-
Number,
2120
RLPSerializable,
2221
StorageKey,
2322
)
@@ -41,16 +40,22 @@ def composed(bal: BlockAccessList) -> BlockAccessList:
4140
class BalNonceChange(CamelModel, RLPSerializable):
4241
"""Represents a nonce change in the block access list."""
4342

44-
tx_index: Number = Field(..., description="Transaction index where the change occurred")
45-
post_nonce: Number = Field(..., description="Nonce value after the transaction")
43+
tx_index: HexNumber = Field(
44+
HexNumber(1),
45+
description="Transaction index where the change occurred",
46+
)
47+
post_nonce: HexNumber = Field(..., description="Nonce value after the transaction")
4648

4749
rlp_fields: ClassVar[List[str]] = ["tx_index", "post_nonce"]
4850

4951

5052
class BalBalanceChange(CamelModel, RLPSerializable):
5153
"""Represents a balance change in the block access list."""
5254

53-
tx_index: Number = Field(..., description="Transaction index where the change occurred")
55+
tx_index: HexNumber = Field(
56+
HexNumber(1),
57+
description="Transaction index where the change occurred",
58+
)
5459
post_balance: HexNumber = Field(..., description="Balance after the transaction")
5560

5661
rlp_fields: ClassVar[List[str]] = ["tx_index", "post_balance"]
@@ -59,7 +64,10 @@ class BalBalanceChange(CamelModel, RLPSerializable):
5964
class BalCodeChange(CamelModel, RLPSerializable):
6065
"""Represents a code change in the block access list."""
6166

62-
tx_index: Number = Field(..., description="Transaction index where the change occurred")
67+
tx_index: HexNumber = Field(
68+
HexNumber(1),
69+
description="Transaction index where the change occurred",
70+
)
6371
new_code: Bytes = Field(..., description="New code bytes")
6472

6573
rlp_fields: ClassVar[List[str]] = ["tx_index", "new_code"]
@@ -68,7 +76,10 @@ class BalCodeChange(CamelModel, RLPSerializable):
6876
class BalStorageChange(CamelModel, RLPSerializable):
6977
"""Represents a change to a specific storage slot."""
7078

71-
tx_index: Number = Field(..., description="Transaction index where the change occurred")
79+
tx_index: HexNumber = Field(
80+
HexNumber(1),
81+
description="Transaction index where the change occurred",
82+
)
7283
post_value: StorageKey = Field(..., description="Value after the transaction")
7384

7485
rlp_fields: ClassVar[List[str]] = ["tx_index", "post_value"]

src/ethereum_test_types/block_access_list/modifiers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from typing import Callable, List
1010

11-
from ethereum_test_base_types import Address, Number
11+
from ethereum_test_base_types import Address, HexNumber
1212

1313
from .. import BalCodeChange
1414
from . import (
@@ -244,36 +244,36 @@ def transform(bal: BlockAccessList) -> BlockAccessList:
244244
if new_account.nonce_changes:
245245
for nonce_change in new_account.nonce_changes:
246246
if nonce_change.tx_index == tx1:
247-
nonce_change.tx_index = Number(tx2)
247+
nonce_change.tx_index = HexNumber(tx2)
248248
elif nonce_change.tx_index == tx2:
249-
nonce_change.tx_index = Number(tx1)
249+
nonce_change.tx_index = HexNumber(tx1)
250250

251251
# Swap in balance changes
252252
if new_account.balance_changes:
253253
for balance_change in new_account.balance_changes:
254254
if balance_change.tx_index == tx1:
255-
balance_change.tx_index = Number(tx2)
255+
balance_change.tx_index = HexNumber(tx2)
256256
elif balance_change.tx_index == tx2:
257-
balance_change.tx_index = Number(tx1)
257+
balance_change.tx_index = HexNumber(tx1)
258258

259259
# Swap in storage changes (nested structure)
260260
if new_account.storage_changes:
261261
for storage_slot in new_account.storage_changes:
262262
for storage_change in storage_slot.slot_changes:
263263
if storage_change.tx_index == tx1:
264-
storage_change.tx_index = Number(tx2)
264+
storage_change.tx_index = HexNumber(tx2)
265265
elif storage_change.tx_index == tx2:
266-
storage_change.tx_index = Number(tx1)
266+
storage_change.tx_index = HexNumber(tx1)
267267

268268
# Note: storage_reads is just a list of StorageKey, no tx_index to swap
269269

270270
# Swap in code changes
271271
if new_account.code_changes:
272272
for code_change in new_account.code_changes:
273273
if code_change.tx_index == tx1:
274-
code_change.tx_index = Number(tx2)
274+
code_change.tx_index = HexNumber(tx2)
275275
elif code_change.tx_index == tx2:
276-
code_change.tx_index = Number(tx1)
276+
code_change.tx_index = HexNumber(tx1)
277277

278278
new_root.append(new_account)
279279

0 commit comments

Comments
 (0)