-
Notifications
You must be signed in to change notification settings - Fork 488
fix(test-tests): Use ZeroPaddedHexNumber instead of HexNumber for BALs
#1922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fselmo
merged 3 commits into
ethereum:eips/amsterdam/eip-7928
from
fselmo:fix/use-zero-padded-hex-number-bals
Dec 30, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
748e976
fix(test-tests): Use ZeroPaddedHexNumber instead of HexNumber for conβ¦
fselmo 2b13f98
chore(test-tests): add bal serialization roundtrip & 0-padded hex tesβ¦
danceratopz ce162d0
refactor(test): Remove unnecessary instantiation of classes to pydantβ¦
fselmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...es/testing/src/execution_testing/test_types/tests/test_block_access_list_serialization.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| Tests for BlockAccessList serialization format. | ||
|
|
||
| These tests verify that BAL models serialize to JSON with the correct | ||
| format, particularly zero-padded hex strings. | ||
| """ | ||
|
|
||
| from execution_testing.base_types import Address, Bytes | ||
| from execution_testing.test_types.block_access_list import ( | ||
| BalAccountChange, | ||
| BalBalanceChange, | ||
| BalCodeChange, | ||
| BalNonceChange, | ||
| BalStorageChange, | ||
| BalStorageSlot, | ||
| BlockAccessList, | ||
| ) | ||
|
|
||
|
|
||
| def test_bal_serialization_roundtrip_zero_padded_hex() -> None: | ||
| """ | ||
| Test that BAL serializes with zero-padded hex format and round-trips correctly. | ||
|
|
||
| This verifies that values like 12 serialize as "0x0c" (not "0xc"), which is | ||
| required for consistency with other test vector fields. | ||
| """ | ||
| addr = Address(0xA) | ||
|
|
||
| original = BlockAccessList( | ||
| [ | ||
| BalAccountChange( | ||
| address=addr, | ||
| nonce_changes=[ | ||
| BalNonceChange(block_access_index=1, post_nonce=12), | ||
| BalNonceChange(block_access_index=2, post_nonce=255), | ||
| ], | ||
| balance_changes=[ | ||
| BalBalanceChange(block_access_index=1, post_balance=15), | ||
| ], | ||
| code_changes=[ | ||
| BalCodeChange( | ||
| block_access_index=3, new_code=Bytes(b"\xde\xad") | ||
| ), | ||
| ], | ||
| storage_changes=[ | ||
| BalStorageSlot( | ||
| slot=12, | ||
| slot_changes=[ | ||
| BalStorageChange( | ||
| block_access_index=1, post_value=255 | ||
| ), | ||
| BalStorageChange( | ||
| block_access_index=2, post_value=4096 | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| storage_reads=[1, 15, 256], | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
| # Serialize to JSON | ||
| json_data = original.model_dump(mode="json") | ||
| account_data = json_data[0] | ||
|
|
||
| # Verify zero-padded hex format (0x0c not 0xc, 0x01 not 0x1) | ||
| assert account_data["nonce_changes"][0]["block_access_index"] == "0x01" | ||
| assert account_data["nonce_changes"][0]["post_nonce"] == "0x0c" | ||
| assert account_data["nonce_changes"][1]["post_nonce"] == "0xff" | ||
| assert account_data["balance_changes"][0]["post_balance"] == "0x0f" | ||
| assert account_data["code_changes"][0]["block_access_index"] == "0x03" | ||
| assert account_data["storage_changes"][0]["slot"] == "0x0c" | ||
| assert ( | ||
| account_data["storage_changes"][0]["slot_changes"][0]["post_value"] | ||
| == "0xff" | ||
| ) | ||
| assert ( | ||
| account_data["storage_changes"][0]["slot_changes"][1]["post_value"] | ||
| == "0x1000" | ||
| ) | ||
| assert account_data["storage_reads"] == ["0x01", "0x0f", "0x0100"] | ||
|
|
||
| # Round-trip: deserialize and verify equality | ||
| restored = BlockAccessList.model_validate(json_data) | ||
| assert restored == original |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.