Skip to content

Commit 1f96c64

Browse files
committed
feat(specs): Add blob schedule to blockchain tests, add tests
1 parent 7cdd4d5 commit 1f96c64

File tree

4 files changed

+306
-13
lines changed

4 files changed

+306
-13
lines changed

src/ethereum_test_specs/blockchain.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from pprint import pprint
6-
from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type
6+
from typing import Any, Callable, ClassVar, Dict, Generator, List, Mapping, Optional, Tuple, Type
77

88
import pytest
99
from pydantic import ConfigDict, Field, field_validator
@@ -35,12 +35,13 @@
3535
FixtureBlock,
3636
FixtureBlockBase,
3737
FixtureEngineNewPayload,
38+
FixtureForkBlobSchedule,
3839
FixtureHeader,
3940
FixtureTransaction,
4041
FixtureWithdrawal,
4142
InvalidFixtureBlock,
4243
)
43-
from ethereum_test_forks import Fork
44+
from ethereum_test_forks import Fork, TransitionFork
4445
from ethereum_test_types import Alloc, Environment, Removable, Requests, Transaction, Withdrawal
4546

4647
from .base import BaseTest, verify_result
@@ -119,7 +120,6 @@ class Header(CamelModel):
119120
excess_blob_gas: Removable | HexNumber | None = None
120121
parent_beacon_block_root: Removable | Hash | None = None
121122
requests_hash: Removable | Hash | None = None
122-
target_blobs_per_block: Removable | HexNumber | None = None
123123

124124
REMOVE_FIELD: ClassVar[Removable] = Removable()
125125
"""
@@ -270,8 +270,6 @@ def set_environment(self, env: Environment) -> Environment:
270270
new_env_values["blob_gas_used"] = self.blob_gas_used
271271
if not isinstance(self.parent_beacon_block_root, Removable):
272272
new_env_values["parent_beacon_block_root"] = self.parent_beacon_block_root
273-
if not isinstance(self.target_blobs_per_block, Removable):
274-
new_env_values["target_blobs_per_block"] = self.target_blobs_per_block
275273
"""
276274
These values are required, but they depend on the previous environment,
277275
so they can be calculated here.
@@ -515,6 +513,36 @@ def network_info(self, fork: Fork, eips: Optional[List[int]] = None):
515513
else fork.blockchain_test_network_name()
516514
)
517515

516+
def blob_schedule(
517+
self, fork: Fork | TransitionFork, eips: Optional[List[int]] = None
518+
) -> Mapping[str, FixtureForkBlobSchedule] | None:
519+
"""
520+
Returns the blob schedule for the given fork and EIPs.
521+
"""
522+
if fork.is_transition_fork():
523+
fork: Fork = fork.transitions_to() # type: ignore
524+
blob_schedule: Dict[str, FixtureForkBlobSchedule] = {}
525+
last_fork_blob_schedule: FixtureForkBlobSchedule | None = None
526+
for fork in fork.parents() + [fork]:
527+
if fork.target_blobs_per_block(0, 0) is None or fork.max_blobs_per_block(0, 0) is None:
528+
continue
529+
current_fork_blob_schedule = FixtureForkBlobSchedule(
530+
target_blobs_per_block=fork.target_blobs_per_block(0, 0),
531+
max_blobs_per_block=fork.max_blobs_per_block(0, 0),
532+
)
533+
if (
534+
last_fork_blob_schedule is None
535+
or current_fork_blob_schedule != last_fork_blob_schedule
536+
):
537+
blob_schedule[fork.name()] = current_fork_blob_schedule
538+
539+
last_fork_blob_schedule = current_fork_blob_schedule
540+
541+
if not blob_schedule:
542+
return None
543+
544+
return blob_schedule
545+
518546
def verify_post_state(self, t8n, alloc: Alloc):
519547
"""
520548
Verifies the post alloc after all block/s or payload/s are generated.
@@ -607,6 +635,7 @@ def make_fixture(
607635
last_block_hash=head,
608636
pre=pre,
609637
post_state=alloc,
638+
blob_schedule=self.blob_schedule(fork, eips),
610639
)
611640

612641
def make_hive_fixture(
@@ -697,6 +726,7 @@ def make_hive_fixture(
697726
post_state=alloc,
698727
sync_payload=sync_payload,
699728
last_block_hash=head_hash,
729+
blob_schedule=self.blob_schedule(fork, eips),
700730
)
701731

702732
def generate(
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"000/my_chain_id_test/Cancun": {
3+
"_info": {
4+
"hash": "0x969794b41e3ae61c6ed89b7117f28a76f31498638931efd525446fe8939a7b50",
5+
"fixture_format": "blockchain_test"
6+
},
7+
"network": "Cancun",
8+
"genesisRLP": "0xf9023df90237a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527efa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080808502540be400808000a0000000000000000000000000000000000000000000000000000000000000000088000000000000000007a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000c0c0c0",
9+
"genesisBlockHeader": {
10+
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
11+
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
12+
"coinbase": "0x0000000000000000000000000000000000000000",
13+
"stateRoot": "0x789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527ef",
14+
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
15+
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
16+
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
17+
"difficulty": "0x00",
18+
"number": "0x00",
19+
"gasLimit": "0x02540be400",
20+
"gasUsed": "0x00",
21+
"timestamp": "0x00",
22+
"extraData": "0x00",
23+
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
24+
"nonce": "0x0000000000000000",
25+
"baseFeePerGas": "0x07",
26+
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
27+
"blobGasUsed": "0x00",
28+
"excessBlobGas": "0x00",
29+
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
30+
"hash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b"
31+
},
32+
"blocks": [
33+
{
34+
"rlp": "0xf902a5f9023ba028c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2697ff9baa0db94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbba08151d548273f6683169524b66ca9fe338b9ce42bc3540046c828fd939ae23bcba0c598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0ab901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018502540be40082a8618203e800a0000000000000000000000000000000000000000000000000000000000000000088000000000000000007a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000f863f861800a8405f5e10094100000000000000000000000000000000000000080801ba07e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37a05f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509bc0c0",
35+
"blockHeader": {
36+
"parentHash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b",
37+
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
38+
"coinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
39+
"stateRoot": "0xdb94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbb",
40+
"transactionsTrie": "0x8151d548273f6683169524b66ca9fe338b9ce42bc3540046c828fd939ae23bcb",
41+
"receiptTrie": "0xc598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0a",
42+
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
43+
"difficulty": "0x00",
44+
"number": "0x01",
45+
"gasLimit": "0x02540be400",
46+
"gasUsed": "0xa861",
47+
"timestamp": "0x03e8",
48+
"extraData": "0x00",
49+
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
50+
"nonce": "0x0000000000000000",
51+
"baseFeePerGas": "0x07",
52+
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
53+
"blobGasUsed": "0x00",
54+
"excessBlobGas": "0x00",
55+
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
56+
"hash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b"
57+
},
58+
"blocknumber": "1",
59+
"transactions": [
60+
{
61+
"type": "0x00",
62+
"chainId": "0x00",
63+
"nonce": "0x00",
64+
"gasPrice": "0x0a",
65+
"gasLimit": "0x05f5e100",
66+
"to": "0x1000000000000000000000000000000000000000",
67+
"value": "0x00",
68+
"data": "0x",
69+
"v": "0x1b",
70+
"r": "0x7e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37",
71+
"s": "0x5f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509b",
72+
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
73+
}
74+
],
75+
"uncleHeaders": [],
76+
"withdrawals": []
77+
}
78+
],
79+
"lastblockhash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b",
80+
"pre": {
81+
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02": {
82+
"balance": "0x00",
83+
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
84+
"nonce": "0x01",
85+
"storage": {}
86+
},
87+
"0x1000000000000000000000000000000000000000": {
88+
"nonce": "0x00",
89+
"balance": "0x00",
90+
"code": "0x4660015500",
91+
"storage": {}
92+
},
93+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
94+
"nonce": "0x00",
95+
"balance": "0x3635c9adc5dea00000",
96+
"code": "0x",
97+
"storage": {}
98+
}
99+
},
100+
"postState": {
101+
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02": {
102+
"balance": "0x00",
103+
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
104+
"nonce": "0x01",
105+
"storage": {
106+
"0x03e8": "0x03e8"
107+
}
108+
},
109+
"0x1000000000000000000000000000000000000000": {
110+
"nonce": "0x00",
111+
"balance": "0x00",
112+
"code": "0x4660015500",
113+
"storage": {
114+
"0x01": "0x01"
115+
}
116+
},
117+
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
118+
"nonce": "0x00",
119+
"balance": "0x01f923",
120+
"code": "0x",
121+
"storage": {}
122+
},
123+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
124+
"nonce": "0x01",
125+
"balance": "0x3635c9adc5de996c36",
126+
"code": "0x",
127+
"storage": {}
128+
}
129+
},
130+
"sealEngine": "NoProof",
131+
"blobSchedule": {
132+
"Cancun": {
133+
"max": "0x6",
134+
"target": "0x3"
135+
}
136+
}
137+
}
138+
}

0 commit comments

Comments
 (0)