Skip to content

Commit 093d119

Browse files
winsvegamarioevz
andauthored
feat(tests): export 'chain_id' in fixture config (#1131)
* export chain_id in fixtureConfig * adjust unit tests * Update src/pytest_plugins/consume/hive_simulators/conftest.py * fix * fix: Make fixture readers backwards compatible --------- Co-authored-by: Mario Vega <[email protected]>
1 parent cf8e53a commit 093d119

19 files changed

+65
-27
lines changed

src/cli/check_fixtures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ def check_json(json_file_path: Path):
4848
message=f"Fixture hash attributes do not match for {fixture_name}",
4949
)
5050
if "hash" in fixture.info and fixture.info["hash"] != original_hash:
51+
info_hash = fixture.info["hash"]
5152
raise HashMismatchExceptionError(
5253
original_hash,
5354
fixture.info["hash"],
54-
message=f"Fixture info['hash'] does not match calculated hash for {fixture_name}",
55+
message=f"Fixture info['hash'] does not match calculated hash for {fixture_name}:"
56+
f"'{info_hash}' != '{original_hash}'",
5557
)
5658

5759

src/ethereum_test_fixtures/blockchain.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import ethereum_rlp as eth_rlp
1818
from ethereum_types.numeric import Uint
19-
from pydantic import AliasChoices, Field, PlainSerializer, computed_field
19+
from pydantic import AliasChoices, Field, PlainSerializer, computed_field, model_validator
2020

2121
from ethereum_test_base_types import (
2222
Address,
@@ -401,6 +401,7 @@ class FixtureConfig(CamelModel):
401401
"""Chain configuration for a fixture."""
402402

403403
fork: str = Field(..., alias="network")
404+
chain_id: ZeroPaddedHexNumber = Field(ZeroPaddedHexNumber(1), alias="chainid")
404405
blob_schedule: FixtureBlobSchedule | None = None
405406

406407

@@ -422,6 +423,22 @@ class BlockchainFixtureCommon(BaseFixture):
422423
last_block_hash: Hash = Field(..., alias="lastblockhash") # FIXME: lastBlockHash
423424
config: FixtureConfig
424425

426+
@model_validator(mode="before")
427+
@classmethod
428+
def config_network_default(cls, data: Any) -> Any:
429+
"""
430+
Check if the config.network is populated, otherwise use the root-level field value for
431+
backward compatibility.
432+
"""
433+
if (
434+
isinstance(data, dict)
435+
and "config" in data
436+
and isinstance(data["config"], dict)
437+
and "network" not in data["config"]
438+
):
439+
data["config"]["network"] = data["network"]
440+
return data
441+
425442
def get_fork(self) -> str | None:
426443
"""Return fork of the fixture as a string."""
427444
return self.fork

src/ethereum_test_fixtures/state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class FixtureConfig(CamelModel):
9898
"""Chain configuration for a fixture."""
9999

100100
blob_schedule: FixtureBlobSchedule | None = None
101+
chain_id: ZeroPaddedHexNumber = Field(ZeroPaddedHexNumber(1), alias="chainid")
101102

102103

103104
class StateFixture(BaseFixture):

src/ethereum_test_specs/blockchain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def make_fixture(
588588
config=FixtureConfig(
589589
fork=network_info,
590590
blob_schedule=FixtureBlobSchedule.from_blob_schedule(fork.blob_schedule()),
591+
chain_id=self.chain_id,
591592
),
592593
)
593594

@@ -686,6 +687,7 @@ def make_hive_fixture(
686687
last_block_hash=head_hash,
687688
config=FixtureConfig(
688689
fork=network_info,
690+
chain_id=self.chain_id,
689691
blob_schedule=FixtureBlobSchedule.from_blob_schedule(fork.blob_schedule()),
690692
),
691693
)

src/ethereum_test_specs/state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def make_state_test_fixture(
178178
transaction=FixtureTransaction.from_transaction(tx),
179179
config=FixtureConfig(
180180
blob_schedule=FixtureBlobSchedule.from_blob_schedule(fork.blob_schedule()),
181+
chain_id=self.chain_id,
181182
),
182183
)
183184

src/ethereum_test_specs/tests/fixtures/blockchain_london_invalid_filled.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_blockchain_test/London": {
33
"_info": {
4-
"hash": "0x76838b666ca44a330fcf031ae20392647c3251ad54f29e995890bd608948b915",
4+
"hash": "0x94854ed3844fcf06f8b74349e63aa0e6dcf43a307f5888b93be310ff39de55ff",
55
"fixture_format": "blockchain_test"
66
},
77
"network": "London",
@@ -541,7 +541,8 @@
541541
},
542542
"sealEngine": "NoProof",
543543
"config": {
544-
"network": "London"
544+
"network": "London",
545+
"chainid": "0x01"
545546
}
546547
}
547548
}

src/ethereum_test_specs/tests/fixtures/blockchain_london_valid_filled.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_blockchain_test/London": {
33
"_info": {
4-
"hash": "0x7694748a5d5e0ea1e5e914210fb8db7c8077f070dd29ffcb13774d526aee35de",
4+
"hash": "0x4ba67dfce5957e3339bf3e6e7ad78f4345b34a087c4656c92fddbef3726b1ec2",
55
"fixture_format": "blockchain_test"
66
},
77
"network": "London",
@@ -419,7 +419,8 @@
419419
},
420420
"sealEngine": "NoProof",
421421
"config": {
422-
"network": "London"
422+
"network": "London",
423+
"chainid": "0x01"
423424
}
424425
}
425426
}

src/ethereum_test_specs/tests/fixtures/blockchain_shanghai_invalid_filled_engine.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_blockchain_test/Shanghai": {
33
"_info": {
4-
"hash": "0x75f8ac4dbd5bfee6046a0edd5bec5448e23d1f249c10025a47bfb46ff7dab303",
4+
"hash": "0xf3c8b8fddf2e80c7a3d4764f9ee022d2e3ef44898e279d1242750cd7083aead4",
55
"fixture_format": "blockchain_test_engine"
66
},
77
"lastblockhash": "0xfc75f11c05ec814a890141bef919bb7c20dd29245e37e9bcea66008dfde98526",
@@ -314,7 +314,8 @@
314314
}
315315
},
316316
"config": {
317-
"network": "Shanghai"
317+
"network": "Shanghai",
318+
"chainid": "0x01"
318319
}
319320
}
320321
}

src/ethereum_test_specs/tests/fixtures/blockchain_shanghai_valid_filled_engine.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_blockchain_test/Shanghai": {
33
"_info": {
4-
"hash": "0xe0738285cd63c07ce0dbc7801ad9d91962d25edcca544bc8475d88a86cab4a15",
4+
"hash": "0xed072f321c295a71beffd44f8130bc90a4fe755a506b30b2057aa342bd9c00f2",
55
"fixture_format": "blockchain_test_engine"
66
},
77
"lastblockhash": "0xfc75f11c05ec814a890141bef919bb7c20dd29245e37e9bcea66008dfde98526",
@@ -260,7 +260,8 @@
260260
}
261261
},
262262
"config": {
263-
"network": "Shanghai"
263+
"network": "Shanghai",
264+
"chainid": "0x01"
264265
}
265266
}
266267
}

src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Cancun": {
33
"_info": {
4-
"hash": "0xdc67839b9bbea740321a4ce4cd9124e14387e74627761cf65ff425bc44d56c1e",
4+
"hash": "0x6e77c3ba39a0874917e9dcd7f911de1e950e82e028603a0fc39630f973579fd9",
55
"fixture_format": "blockchain_test"
66
},
77
"network": "Cancun",
@@ -130,6 +130,7 @@
130130
"sealEngine": "NoProof",
131131
"config": {
132132
"network": "Cancun",
133+
"chainid": "0x01",
133134
"blobSchedule": {
134135
"Cancun": {
135136
"max": "0x06",

0 commit comments

Comments
 (0)