Skip to content

Commit

Permalink
feat(specs): Add blob schedule to blockchain tests, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Dec 21, 2024
1 parent 7cdd4d5 commit 1f96c64
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 13 deletions.
40 changes: 35 additions & 5 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from pprint import pprint
from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type
from typing import Any, Callable, ClassVar, Dict, Generator, List, Mapping, Optional, Tuple, Type

import pytest
from pydantic import ConfigDict, Field, field_validator
Expand Down Expand Up @@ -35,12 +35,13 @@
FixtureBlock,
FixtureBlockBase,
FixtureEngineNewPayload,
FixtureForkBlobSchedule,
FixtureHeader,
FixtureTransaction,
FixtureWithdrawal,
InvalidFixtureBlock,
)
from ethereum_test_forks import Fork
from ethereum_test_forks import Fork, TransitionFork
from ethereum_test_types import Alloc, Environment, Removable, Requests, Transaction, Withdrawal

from .base import BaseTest, verify_result
Expand Down Expand Up @@ -119,7 +120,6 @@ class Header(CamelModel):
excess_blob_gas: Removable | HexNumber | None = None
parent_beacon_block_root: Removable | Hash | None = None
requests_hash: Removable | Hash | None = None
target_blobs_per_block: Removable | HexNumber | None = None

REMOVE_FIELD: ClassVar[Removable] = Removable()
"""
Expand Down Expand Up @@ -270,8 +270,6 @@ def set_environment(self, env: Environment) -> Environment:
new_env_values["blob_gas_used"] = self.blob_gas_used
if not isinstance(self.parent_beacon_block_root, Removable):
new_env_values["parent_beacon_block_root"] = self.parent_beacon_block_root
if not isinstance(self.target_blobs_per_block, Removable):
new_env_values["target_blobs_per_block"] = self.target_blobs_per_block
"""
These values are required, but they depend on the previous environment,
so they can be calculated here.
Expand Down Expand Up @@ -515,6 +513,36 @@ def network_info(self, fork: Fork, eips: Optional[List[int]] = None):
else fork.blockchain_test_network_name()
)

def blob_schedule(
self, fork: Fork | TransitionFork, eips: Optional[List[int]] = None
) -> Mapping[str, FixtureForkBlobSchedule] | None:
"""
Returns the blob schedule for the given fork and EIPs.
"""
if fork.is_transition_fork():
fork: Fork = fork.transitions_to() # type: ignore
blob_schedule: Dict[str, FixtureForkBlobSchedule] = {}
last_fork_blob_schedule: FixtureForkBlobSchedule | None = None
for fork in fork.parents() + [fork]:
if fork.target_blobs_per_block(0, 0) is None or fork.max_blobs_per_block(0, 0) is None:
continue
current_fork_blob_schedule = FixtureForkBlobSchedule(
target_blobs_per_block=fork.target_blobs_per_block(0, 0),
max_blobs_per_block=fork.max_blobs_per_block(0, 0),
)
if (
last_fork_blob_schedule is None
or current_fork_blob_schedule != last_fork_blob_schedule
):
blob_schedule[fork.name()] = current_fork_blob_schedule

last_fork_blob_schedule = current_fork_blob_schedule

if not blob_schedule:
return None

return blob_schedule

def verify_post_state(self, t8n, alloc: Alloc):
"""
Verifies the post alloc after all block/s or payload/s are generated.
Expand Down Expand Up @@ -607,6 +635,7 @@ def make_fixture(
last_block_hash=head,
pre=pre,
post_state=alloc,
blob_schedule=self.blob_schedule(fork, eips),
)

def make_hive_fixture(
Expand Down Expand Up @@ -697,6 +726,7 @@ def make_hive_fixture(
post_state=alloc,
sync_payload=sync_payload,
last_block_hash=head_hash,
blob_schedule=self.blob_schedule(fork, eips),
)

def generate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"000/my_chain_id_test/Cancun": {
"_info": {
"hash": "0x969794b41e3ae61c6ed89b7117f28a76f31498638931efd525446fe8939a7b50",
"fixture_format": "blockchain_test"
},
"network": "Cancun",
"genesisRLP": "0xf9023df90237a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527efa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080808502540be400808000a0000000000000000000000000000000000000000000000000000000000000000088000000000000000007a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000c0c0c0",
"genesisBlockHeader": {
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527ef",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x00",
"number": "0x00",
"gasLimit": "0x02540be400",
"gasUsed": "0x00",
"timestamp": "0x00",
"extraData": "0x00",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"baseFeePerGas": "0x07",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"blobGasUsed": "0x00",
"excessBlobGas": "0x00",
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b"
},
"blocks": [
{
"rlp": "0xf902a5f9023ba028c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2697ff9baa0db94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbba08151d548273f6683169524b66ca9fe338b9ce42bc3540046c828fd939ae23bcba0c598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0ab901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018502540be40082a8618203e800a0000000000000000000000000000000000000000000000000000000000000000088000000000000000007a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000f863f861800a8405f5e10094100000000000000000000000000000000000000080801ba07e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37a05f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509bc0c0",
"blockHeader": {
"parentHash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"stateRoot": "0xdb94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbb",
"transactionsTrie": "0x8151d548273f6683169524b66ca9fe338b9ce42bc3540046c828fd939ae23bcb",
"receiptTrie": "0xc598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0a",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x00",
"number": "0x01",
"gasLimit": "0x02540be400",
"gasUsed": "0xa861",
"timestamp": "0x03e8",
"extraData": "0x00",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"baseFeePerGas": "0x07",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"blobGasUsed": "0x00",
"excessBlobGas": "0x00",
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b"
},
"blocknumber": "1",
"transactions": [
{
"type": "0x00",
"chainId": "0x00",
"nonce": "0x00",
"gasPrice": "0x0a",
"gasLimit": "0x05f5e100",
"to": "0x1000000000000000000000000000000000000000",
"value": "0x00",
"data": "0x",
"v": "0x1b",
"r": "0x7e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37",
"s": "0x5f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509b",
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
}
],
"uncleHeaders": [],
"withdrawals": []
}
],
"lastblockhash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b",
"pre": {
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02": {
"balance": "0x00",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
"nonce": "0x01",
"storage": {}
},
"0x1000000000000000000000000000000000000000": {
"nonce": "0x00",
"balance": "0x00",
"code": "0x4660015500",
"storage": {}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x00",
"balance": "0x3635c9adc5dea00000",
"code": "0x",
"storage": {}
}
},
"postState": {
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02": {
"balance": "0x00",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
"nonce": "0x01",
"storage": {
"0x03e8": "0x03e8"
}
},
"0x1000000000000000000000000000000000000000": {
"nonce": "0x00",
"balance": "0x00",
"code": "0x4660015500",
"storage": {
"0x01": "0x01"
}
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"nonce": "0x00",
"balance": "0x01f923",
"code": "0x",
"storage": {}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x3635c9adc5de996c36",
"code": "0x",
"storage": {}
}
},
"sealEngine": "NoProof",
"blobSchedule": {
"Cancun": {
"max": "0x6",
"target": "0x3"
}
}
}
}
Loading

0 comments on commit 1f96c64

Please sign in to comment.