Skip to content

Commit 4a21fb3

Browse files
authored
feat(fixtures,specs): Add postStateHash on exclude_full_post_state_in_output (#1667)
* feat(fixtures,specs): Add `postStateHash` on `exclude_full_post_state_in_output` * docs: Changelog * feat(fixtures,specs): Check mutually exclusive `postState`/`postStateHash`
1 parent 0c3397c commit 4a21fb3

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Users can select any of the artifacts depending on their testing needs for their
3131
- ✨ Don't warn about a "high Transaction gas_limit" for `zkevm` tests ([#1598](https://github.com/ethereum/execution-spec-tests/pull/1598)).
3232
- 🐞 `fill` no longer writes generated fixtures into an existing, non-empty output directory; it must now be empty or `--clean` must be used to delete it first ([#1608](https://github.com/ethereum/execution-spec-tests/pull/1608)).
3333
- 🐞 zkEVM marked tests have been removed from `tests-deployed` tox environment into its own separate workflow `tests-deployed-zkevm` and are filled by `evmone-t8n` ([#1617](https://github.com/ethereum/execution-spec-tests/pull/1617)).
34+
- ✨ Field `postStateHash` is now added to all `blockchain_test` and `blockchain_test_engine` tests that use `exclude_full_post_state_in_output` in place of `postState`. Fixes `evmone-blockchaintest` test consumption and indirectly fixes coverage runs for these tests ([#1667](https://github.com/ethereum/execution-spec-tests/pull/1667)).
3435

3536
#### `consume`
3637

src/ethereum_test_fixtures/blockchain.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,18 @@ class BlockchainFixtureCommon(BaseFixture):
407407
genesis: FixtureHeader = Field(..., alias="genesisBlockHeader")
408408
pre: Alloc
409409
post_state: Alloc | None = Field(None)
410+
post_state_hash: Hash | None = Field(None)
410411
last_block_hash: Hash = Field(..., alias="lastblockhash") # FIXME: lastBlockHash
411412
config: FixtureConfig
412413

414+
def model_post_init(self, __context):
415+
"""Model post init method to check mutually exclusive fields."""
416+
super().model_post_init(__context)
417+
if self.post_state_hash is None and self.post_state is None:
418+
raise ValueError("Either post_state_hash or post_state must be provided.")
419+
if self.post_state_hash is not None and self.post_state is not None:
420+
raise ValueError("Only one of post_state_hash or post_state must be provided.")
421+
413422
@model_validator(mode="before")
414423
@classmethod
415424
def config_defaults_for_backwards_compatibility(cls, data: Any) -> Any:

src/ethereum_test_specs/blockchain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ def make_fixture(
656656
last_block_hash=head,
657657
pre=pre,
658658
post_state=alloc if not self.exclude_full_post_state_in_output else None,
659+
post_state_hash=alloc.state_root() if self.exclude_full_post_state_in_output else None,
659660
config=FixtureConfig(
660661
fork=network_info,
661662
blob_schedule=FixtureBlobSchedule.from_blob_schedule(fork.blob_schedule()),
@@ -754,6 +755,7 @@ def make_hive_fixture(
754755
fcu_version=fcu_version,
755756
pre=pre,
756757
post_state=alloc if not self.exclude_full_post_state_in_output else None,
758+
post_state_hash=alloc.state_root() if self.exclude_full_post_state_in_output else None,
757759
sync_payload=sync_payload,
758760
last_block_hash=head_hash,
759761
config=FixtureConfig(

0 commit comments

Comments
 (0)