Skip to content

Commit 4d695c0

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 4d695c0

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/ethereum_test_types/block_access_list/__init__.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@ def composed(bal: BlockAccessList) -> BlockAccessList:
4141
class BalNonceChange(CamelModel, RLPSerializable):
4242
"""Represents a nonce change in the block access list."""
4343

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

4750
rlp_fields: ClassVar[List[str]] = ["tx_index", "post_nonce"]
4851

4952

5053
class BalBalanceChange(CamelModel, RLPSerializable):
5154
"""Represents a balance change in the block access list."""
5255

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

5662
rlp_fields: ClassVar[List[str]] = ["tx_index", "post_balance"]
@@ -59,7 +65,10 @@ class BalBalanceChange(CamelModel, RLPSerializable):
5965
class BalCodeChange(CamelModel, RLPSerializable):
6066
"""Represents a code change in the block access list."""
6167

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

6574
rlp_fields: ClassVar[List[str]] = ["tx_index", "new_code"]
@@ -68,7 +77,10 @@ class BalCodeChange(CamelModel, RLPSerializable):
6877
class BalStorageChange(CamelModel, RLPSerializable):
6978
"""Represents a change to a specific storage slot."""
7079

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

7486
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)