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

+3-1
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

+18-1
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

+1
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

+2
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

+1
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

+3-2
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

+3-2
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

+3-2
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

+3-2
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

+2-1
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",

src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test_engine.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Cancun": {
33
"_info": {
4-
"hash": "0x66186573da8dc65698bed9544ccbe25c13a1ff1039320609531e134473e7210c",
4+
"hash": "0x82d853aef147345cedd8eb383c3ea00c1d1c4b64222911fd2580806de1f51c15",
55
"fixture_format": "blockchain_test_engine"
66
},
77
"network": "Cancun",
@@ -112,6 +112,7 @@
112112
},
113113
"config": {
114114
"network": "Cancun",
115+
"chainid": "0x01",
115116
"blobSchedule": {
116117
"Cancun": {
117118
"max": "0x06",

src/ethereum_test_specs/tests/fixtures/chainid_cancun_state_test.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Cancun": {
33
"_info": {
4-
"hash": "0x85756178b1a4315d675dd7a25ca319b61dd1f86a665baf8d51ba7faf7f3cb444",
4+
"hash": "0x9e980ae5cce8c6222831e99c0a33facfd7b8e50be053b84e3ed357c2c1818491",
55
"fixture_format": "state_test"
66
},
77
"env": {
@@ -15,6 +15,7 @@
1515
"currentExcessBlobGas": "0x00"
1616
},
1717
"config": {
18+
"chainid": "0x01",
1819
"blobSchedule": {
1920
"Cancun": {
2021
"max": "0x06",

src/ethereum_test_specs/tests/fixtures/chainid_istanbul_blockchain_test.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Istanbul": {
33
"_info": {
4-
"hash": "0x523fefcabce674d5b2ef4d99a151dabac431d61aff3e44f42d6d3b8a910a464b",
4+
"hash": "0x8b79023dc05fa9a4e374938ea0c6e04248cc6f30a3e2754737885901693e0c6e",
55
"fixture_format": "blockchain_test"
66
},
77
"network": "Istanbul",
@@ -104,7 +104,8 @@
104104
},
105105
"sealEngine": "NoProof",
106106
"config": {
107-
"network": "Istanbul"
107+
"network": "Istanbul",
108+
"chainid": "0x01"
108109
}
109110
}
110111
}

src/ethereum_test_specs/tests/fixtures/chainid_london_blockchain_test.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/London": {
33
"_info": {
4-
"hash": "0xb0d368cde0d719d6d0652854133631267760c0c41a88d12144c1d8845f677088",
4+
"hash": "0x8f3a32616f93086c33339f1d020a97103df4963edcef3a108babcc95d4cd3951",
55
"fixture_format": "blockchain_test"
66
},
77
"network": "London",
@@ -106,7 +106,8 @@
106106
},
107107
"sealEngine": "NoProof",
108108
"config": {
109-
"network": "London"
109+
"network": "London",
110+
"chainid": "0x01"
110111
}
111112
}
112113
}

src/ethereum_test_specs/tests/fixtures/chainid_paris_blockchain_test_engine.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Paris": {
33
"_info": {
4-
"hash": "0x72d0f1b29136f637f4e7cc22e990911fed6f9cdbd5f1987f1351cfc4efb4673b",
4+
"hash": "0xf07acbb0efdbea6064fa443f0c8a74de6bb3e9895a7717759deedb99310eec4e",
55
"fixture_format": "blockchain_test_engine"
66
},
77
"network": "Paris",
@@ -88,7 +88,8 @@
8888
}
8989
},
9090
"config": {
91-
"network": "Paris"
91+
"network": "Paris",
92+
"chainid": "0x01"
9293
}
9394
}
9495
}

src/ethereum_test_specs/tests/fixtures/chainid_paris_state_test.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Paris": {
33
"_info": {
4-
"hash": "0x1384e915045d477e8d6d0b26fa32f27cc0d30ec2b05f3b166d48d4134017e071",
4+
"hash": "0x9de75fac42e382815fa12e0252e64b901ed1b0225446209223c8a3569e1c2857",
55
"fixture_format": "state_test"
66
},
77
"env": {
@@ -79,6 +79,8 @@
7979
}
8080
]
8181
},
82-
"config": {}
82+
"config": {
83+
"chainid": "0x01"
84+
}
8385
}
8486
}

src/ethereum_test_specs/tests/fixtures/chainid_shanghai_blockchain_test_engine.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Shanghai": {
33
"_info": {
4-
"hash": "0x0853409d8524239ae79581d1fcf8d2da12dc98cd7c1cfd7d730d33ec75e0c56e",
4+
"hash": "0x361818ee5736a45c10c34ec445bf872d280b2f2ad61c297cceb14772b1393006",
55
"fixture_format": "blockchain_test_engine"
66
},
77
"lastblockhash": "0x9c10141361e180632f7973f4f3a0aed2baa5ebb776bae84caafdcc07a24933e8",
@@ -90,7 +90,8 @@
9090
}
9191
},
9292
"config": {
93-
"network": "Shanghai"
93+
"network": "Shanghai",
94+
"chainid": "0x01"
9495
}
9596
}
9697
}

src/ethereum_test_specs/tests/fixtures/chainid_shanghai_state_test.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"000/my_chain_id_test/Shanghai": {
33
"_info": {
4-
"hash": "0x2f1baaa3821157d4bc534b6a0f6908a9900839261b7e6347d3dc5206b8a333b3",
4+
"hash": "0xdd6900920530f2ba834d659b952c023a5962c352512529da8ed9614d99a0c1b8",
55
"fixture_format": "state_test"
66
},
77
"env": {
@@ -79,6 +79,8 @@
7979
}
8080
]
8181
},
82-
"config": {}
82+
"config": {
83+
"chainid": "0x01"
84+
}
8385
}
8486
}

src/pytest_plugins/consume/hive_simulators/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from hive.client import Client, ClientType
1010
from hive.testing import HiveTest
1111

12-
from ethereum_test_base_types import to_json
12+
from ethereum_test_base_types import Number, to_json
1313
from ethereum_test_fixtures import BlockchainFixtureCommon
1414
from ethereum_test_fixtures.consume import TestCaseIndexFile, TestCaseStream
1515
from ethereum_test_rpc import EthRPC
@@ -172,7 +172,7 @@ def environment(
172172
f"fork '{blockchain_fixture.fork}' missing in hive ruleset"
173173
)
174174
return {
175-
"HIVE_CHAIN_ID": "1",
175+
"HIVE_CHAIN_ID": str(Number(blockchain_fixture.config.chain_id)),
176176
"HIVE_FORK_DAO_VOTE": "1",
177177
"HIVE_NODETYPE": "full",
178178
"HIVE_CHECK_LIVE_PORT": str(check_live_port),

0 commit comments

Comments
 (0)