Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tools): update invalid blockchain fixture format #322

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Test fixtures for use by clients are available for each release on the [Github r

### 🔧 Tools

- 🔀 Tools: Updated invalid blocks in fixtures to include non-RLP format ([#322](https://github.com/ethereum/execution-spec-tests/pull/322)).

spencer-tb marked this conversation as resolved.
Show resolved Hide resolved
### 📋 Misc

- ✨ Docs: Changelog updated post release ([#321](https://github.com/ethereum/execution-spec-tests/pull/321)).
Expand Down
2 changes: 2 additions & 0 deletions src/ethereum_test_tools/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Header,
HeaderNonce,
HiveFixture,
InvalidFixtureBlock,
JSONEncoder,
Number,
Removable,
Expand Down Expand Up @@ -79,6 +80,7 @@
"HeaderNonce",
"HistoryStorageAddress",
"HiveFixture",
"InvalidFixtureBlock",
"JSONEncoder",
"Number",
"Removable",
Expand Down
27 changes: 26 additions & 1 deletion src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,7 @@ class FixtureBlock:
"""

rlp: Bytes = field(
default=None,
json_encoder=JSONEncoder.Field(),
)
block_header: Optional[FixtureHeader] = field(
Expand Down Expand Up @@ -2688,6 +2689,30 @@ class FixtureBlock:
)


@dataclass(kw_only=True)
class InvalidFixtureBlock:
"""
Representation of an invalid Ethereum block within a test Fixture.
"""

rlp: Bytes = field(
json_encoder=JSONEncoder.Field(),
)
expected_exception: Optional[str] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="expectException",
),
)
rlp_decoded: FixtureBlock = field(
default=None,
json_encoder=JSONEncoder.Field(
name="rlp_decoded",
to_json=True,
),
)


@dataclass(kw_only=True)
class BaseFixture:
"""
Expand Down Expand Up @@ -2763,7 +2788,7 @@ class Fixture(BaseFixture):
to_json=True,
),
)
blocks: Optional[List[FixtureBlock]] = field(
blocks: Optional[List[FixtureBlock | InvalidFixtureBlock]] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="blocks",
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum_test_tools/spec/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
FixtureEngineNewPayload,
FixtureHeader,
Hash,
InvalidFixtureBlock,
Transaction,
withdrawals_root,
)
Expand Down Expand Up @@ -129,7 +130,7 @@ def make_blocks(
chain_id: int = 1,
eips: Optional[List[int]] = None,
) -> Tuple[
Optional[List[FixtureBlock]],
Optional[List[FixtureBlock | InvalidFixtureBlock]],
Optional[List[Optional[FixtureEngineNewPayload]]],
Hash,
Dict[str, Any],
Expand Down
28 changes: 21 additions & 7 deletions src/ethereum_test_tools/spec/blockchain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
FixtureHeader,
Hash,
HeaderNonce,
InvalidFixtureBlock,
Number,
ZeroPaddedHexNumber,
to_json,
Expand Down Expand Up @@ -121,7 +122,13 @@ def make_block(
previous_head: Hash,
chain_id=1,
eips: Optional[List[int]] = None,
) -> Tuple[FixtureBlock, Optional[FixtureEngineNewPayload], Environment, Dict[str, Any], Hash]:
) -> Tuple[
FixtureBlock | InvalidFixtureBlock,
Optional[FixtureEngineNewPayload],
Environment,
Dict[str, Any],
Hash,
]:
"""
Produces a block based on the previous environment and allocation.
If the block is an invalid block, the environment and allocation
Expand Down Expand Up @@ -244,10 +251,15 @@ def make_block(
)
else:
return (
FixtureBlock(
InvalidFixtureBlock(
rlp=rlp,
block_number=Number(header.number),
expected_exception=block.exception,
rlp_decoded=FixtureBlock(
block_header=header,
txs=txs,
ommers=[],
withdrawals=env.withdrawals,
),
),
fixture_payload,
previous_env,
Expand All @@ -256,7 +268,7 @@ def make_block(
)
else:
return (
FixtureBlock(
InvalidFixtureBlock(
rlp=Bytes(block.rlp),
expected_exception=block.exception,
),
Expand All @@ -275,7 +287,7 @@ def make_blocks(
chain_id=1,
eips: Optional[List[int]] = None,
) -> Tuple[
Optional[List[FixtureBlock]],
Optional[List[FixtureBlock | InvalidFixtureBlock]],
Optional[List[Optional[FixtureEngineNewPayload]]],
Hash,
Dict[str, Any],
Expand All @@ -288,7 +300,9 @@ def make_blocks(
"""
alloc = to_json(pre)
env = Environment.from_parent_header(genesis)
fixture_blocks: List[FixtureBlock] | None = [] if not self.hive_enabled else None
fixture_blocks: List[FixtureBlock | InvalidFixtureBlock] | None = (
[] if not self.hive_enabled else None
)

fixture_payloads: List[Optional[FixtureEngineNewPayload]] | None = (
[] if self.hive_enabled else None
Expand All @@ -312,7 +326,7 @@ def make_blocks(
fixture_blocks.append(fixture_block)
if self.hive_enabled and fixture_payloads is not None:
fixture_payloads.append(fixture_payload)
if block.exception is None:
if isinstance(fixture_block, FixtureBlock):
last_valid = fixture_block.block_header

if self.hive_enabled and last_valid:
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum_test_tools/spec/state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
FixtureHeader,
Hash,
HeaderNonce,
InvalidFixtureBlock,
Number,
Transaction,
ZeroPaddedHexNumber,
Expand Down Expand Up @@ -128,7 +129,7 @@ def make_blocks(
chain_id=1,
eips: Optional[List[int]] = None,
) -> Tuple[
Optional[List[FixtureBlock]],
Optional[List[FixtureBlock | InvalidFixtureBlock]],
Optional[List[Optional[FixtureEngineNewPayload]]],
Hash,
Dict[str, Any],
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum_test_tools/tests/test_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def test_fill_state_test(fork: Fork, expected_json_file: str, enable_hive: bool)

fixture_json = to_json(fixture)
remove_info(fixture_json)
with open("gen.json", "w") as fr:
json.dump(fixture_json, fr, indent=4)
assert fixture_json == expected


Expand Down
Loading