Skip to content

Commit 632b229

Browse files
committed
fix(fixtures): Use defaults in FixtureHeader for genesis generation
1 parent d4703af commit 632b229

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

src/ethereum_test_fixtures/blockchain.py

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,27 @@ class FixtureHeader(CamelModel):
119119
We combine the `Environment` and `Result` contents to create this model.
120120
"""
121121

122-
parent_hash: Hash
122+
parent_hash: Hash = Hash(0)
123123
ommers_hash: Hash = Field(Hash(EmptyOmmersRoot), alias="uncleHash")
124124
fee_recipient: Address = Field(
125125
..., alias="coinbase", validation_alias=AliasChoices("coinbase", "miner")
126126
)
127127
state_root: Hash
128128
transactions_trie: Hash = Field(
129-
validation_alias=AliasChoices("transactionsTrie", "transactionsRoot")
129+
Hash(EmptyTrieRoot), validation_alias=AliasChoices("transactionsTrie", "transactionsRoot")
130130
)
131131
receipts_root: Hash = Field(
132-
..., alias="receiptTrie", validation_alias=AliasChoices("receiptTrie", "receiptsRoot")
132+
Hash(EmptyTrieRoot),
133+
alias="receiptTrie",
134+
validation_alias=AliasChoices("receiptTrie", "receiptsRoot"),
133135
)
134136
logs_bloom: Bloom = Field(
135-
..., alias="bloom", validation_alias=AliasChoices("bloom", "logsBloom")
137+
Bloom(0), alias="bloom", validation_alias=AliasChoices("bloom", "logsBloom")
136138
)
137139
difficulty: ZeroPaddedHexNumber = ZeroPaddedHexNumber(0)
138140
number: ZeroPaddedHexNumber
139141
gas_limit: ZeroPaddedHexNumber
140-
gas_used: ZeroPaddedHexNumber
142+
gas_used: ZeroPaddedHexNumber = ZeroPaddedHexNumber(0)
141143
timestamp: ZeroPaddedHexNumber
142144
extra_data: Bytes
143145
prev_randao: Hash = Field(Hash(0), alias="mixHash")
@@ -219,32 +221,16 @@ def block_hash(self) -> Hash:
219221
@classmethod
220222
def genesis(cls, fork: Fork, env: Environment, state_root: Hash) -> "FixtureHeader":
221223
"""Get the genesis header for the given fork."""
222-
return FixtureHeader(
223-
parent_hash=0,
224-
ommers_hash=EmptyOmmersRoot,
225-
fee_recipient=env.fee_recipient,
226-
state_root=state_root,
227-
transactions_trie=EmptyTrieRoot,
228-
receipts_root=EmptyTrieRoot,
229-
logs_bloom=0,
230-
difficulty=env.difficulty,
231-
number=env.number,
232-
gas_limit=env.gas_limit,
233-
gas_used=0,
234-
timestamp=env.timestamp,
235-
extra_data=env.extra_data,
236-
prev_randao=env.prev_randao,
237-
nonce=0,
238-
base_fee_per_gas=env.base_fee_per_gas,
239-
blob_gas_used=env.blob_gas_used,
240-
excess_blob_gas=env.excess_blob_gas,
241-
withdrawals_root=(
242-
Withdrawal.list_root(env.withdrawals) if env.withdrawals is not None else None
243-
),
244-
parent_beacon_block_root=env.parent_beacon_block_root,
245-
requests_hash=Requests() if fork.header_requests_required(0, 0) else None,
246-
fork=fork,
247-
)
224+
environment_values = env.model_dump(exclude_none=True, exclude={"withdrawals"})
225+
if env.withdrawals is not None:
226+
environment_values["withdrawals_root"] = Withdrawal.list_root(env.withdrawals)
227+
environment_values["extra_data"] = env.extra_data
228+
extras = {
229+
"state_root": state_root,
230+
"requests_hash": Requests() if fork.header_requests_required(0, 0) else None,
231+
"fork": fork,
232+
}
233+
return FixtureHeader(**environment_values, **extras)
248234

249235

250236
class FixtureExecutionPayload(CamelModel):

src/ethereum_test_specs/blockchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def verify_block_exception(self, transition_tool_exceptions_reliable: bool):
385385
)
386386

387387

388-
GENESIS_DEFAULTS: Dict[str, Any] = {
388+
GENESIS_ENVIRONMENT_DEFAULTS: Dict[str, Any] = {
389389
"fee_recipient": 0,
390390
"number": 0,
391391
"timestamp": 0,
@@ -449,7 +449,7 @@ def get_genesis_environment(self, fork: Fork) -> Environment:
449449
modified_values = self.genesis_environment.set_fork_requirements(fork).model_dump(
450450
exclude_unset=True
451451
)
452-
return Environment(**(GENESIS_DEFAULTS | modified_values))
452+
return Environment(**(GENESIS_ENVIRONMENT_DEFAULTS | modified_values))
453453

454454
def make_genesis(
455455
self, *, fork: Fork, apply_pre_allocation_blockchain: bool

0 commit comments

Comments
 (0)