Skip to content

Commit 315d975

Browse files
refactor(forks): Make Fork Pydantic-Compatible (#1686)
* refactor(forks): Pydantic-friendly `Fork` type * fix(tests): Bad import * docs(forks): remove `blockchain_test_network_name` from docs --------- Co-authored-by: danceratopz <danceratopz@gmail.com>
1 parent feb6695 commit 315d975

File tree

32 files changed

+237
-336
lines changed

32 files changed

+237
-336
lines changed

docs/writing_tests/fork_methods.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ fork.name() # Returns the name of the fork
153153
fork.transition_tool_name(block_number=0, timestamp=0) # Returns name for transition tools
154154
fork.solc_name() # Returns name for the solc compiler
155155
fork.solc_min_version() # Returns minimum solc version supporting this fork
156-
fork.blockchain_test_network_name() # Returns network name for blockchain tests
157156
fork.is_deployed() # Returns whether the fork is deployed to mainnet
158157
```
159158

src/ethereum_clis/clis/besu.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def evaluate(
106106
chain_id: int,
107107
reward: int,
108108
blob_schedule: BlobSchedule | None = None,
109-
eips: Optional[List[int]] = None,
110109
debug_output_path: str = "",
111110
state_test: bool = False,
112111
slow_request: bool = False,
@@ -119,8 +118,6 @@ def evaluate(
119118
block_number=env.number,
120119
timestamp=env.timestamp,
121120
)
122-
if eips is not None:
123-
fork_name = "+".join([fork_name] + [str(eip) for eip in eips])
124121

125122
input_json = TransitionToolInput(
126123
alloc=alloc,

src/ethereum_clis/transition_tool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ def evaluate(
500500
chain_id: int,
501501
reward: int,
502502
blob_schedule: BlobSchedule | None,
503-
eips: Optional[List[int]] = None,
504503
debug_output_path: str = "",
505504
state_test: bool = False,
506505
slow_request: bool = False,
@@ -515,8 +514,6 @@ def evaluate(
515514
block_number=env.number,
516515
timestamp=env.timestamp,
517516
)
518-
if eips is not None:
519-
fork_name = "+".join([fork_name] + [str(eip) for eip in eips])
520517
if env.number == 0:
521518
reward = -1
522519
t8n_data = self.TransitionToolData(

src/ethereum_test_fixtures/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def fill_info(
132132
if _info_metadata:
133133
self.info.update(_info_metadata)
134134

135-
def get_fork(self) -> str | None:
135+
def get_fork(self) -> Fork | None:
136136
"""Return fork of the fixture as a string."""
137137
raise NotImplementedError
138138

src/ethereum_test_fixtures/blockchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def without_rlp(self) -> FixtureBlockBase:
386386
class FixtureConfig(CamelModel):
387387
"""Chain configuration for a fixture."""
388388

389-
fork: str = Field(..., alias="network")
389+
fork: Fork = Field(..., alias="network")
390390
chain_id: ZeroPaddedHexNumber = Field(ZeroPaddedHexNumber(1), alias="chainid")
391391
blob_schedule: FixtureBlobSchedule | None = None
392392

@@ -402,7 +402,7 @@ class InvalidFixtureBlock(CamelModel):
402402
class BlockchainFixtureCommon(BaseFixture):
403403
"""Base blockchain test fixture model."""
404404

405-
fork: str = Field(..., alias="network")
405+
fork: Fork = Field(..., alias="network")
406406
genesis: FixtureHeader = Field(..., alias="genesisBlockHeader")
407407
pre: Alloc
408408
post_state: Alloc | None = Field(None)
@@ -435,7 +435,7 @@ def config_defaults_for_backwards_compatibility(cls, data: Any) -> Any:
435435
data["config"]["chainid"] = "0x01"
436436
return data
437437

438-
def get_fork(self) -> str | None:
438+
def get_fork(self) -> Fork | None:
439439
"""Return fork of the fixture as a string."""
440440
return self.fork
441441

src/ethereum_test_fixtures/consume.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pydantic import BaseModel, RootModel
99

1010
from ethereum_test_base_types import HexNumber
11+
from ethereum_test_forks import Fork
1112

1213
from .base import BaseFixture, FixtureFormat
1314
from .file import Fixtures
@@ -44,7 +45,7 @@ class TestCaseBase(BaseModel):
4445

4546
id: str
4647
fixture_hash: HexNumber | None
47-
fork: str | None
48+
fork: Fork | None
4849
format: FixtureFormat
4950
__test__ = False # stop pytest from collecting this class as a test
5051

@@ -80,7 +81,7 @@ class IndexFile(BaseModel):
8081
root_hash: HexNumber | None
8182
created_at: datetime.datetime
8283
test_count: int
83-
forks: Optional[List[str]] = []
84+
forks: Optional[List[Fork]] = []
8485
fixture_formats: Optional[List[str]] = []
8586
test_cases: List[TestCaseIndexFile]
8687

src/ethereum_test_fixtures/eof.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from ethereum_test_base_types import Bytes, CamelModel, Number
88
from ethereum_test_exceptions.exceptions import EOFExceptionInstanceOrList
9+
from ethereum_test_forks import Fork
910
from ethereum_test_types.eof.v1 import ContainerKind
1011

1112
from .base import BaseFixture
@@ -34,7 +35,7 @@ class Vector(CamelModel):
3435

3536
code: Bytes
3637
container_kind: ContainerKind = ContainerKind.RUNTIME
37-
results: Mapping[str, Result]
38+
results: Mapping[Fork, Result]
3839

3940

4041
class EOFFixture(BaseFixture):
@@ -45,6 +46,6 @@ class EOFFixture(BaseFixture):
4546

4647
vectors: Mapping[Number, Vector]
4748

48-
def get_fork(self) -> str | None:
49+
def get_fork(self) -> Fork | None:
4950
"""Return fork of the fixture as a string."""
5051
return None

src/ethereum_test_fixtures/state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ZeroPaddedHexNumber,
1515
)
1616
from ethereum_test_exceptions import TransactionExceptionInstanceOrList
17+
from ethereum_test_forks import Fork
1718
from ethereum_test_types.block_types import EnvironmentGeneric
1819
from ethereum_test_types.transaction_types import (
1920
Transaction,
@@ -97,10 +98,10 @@ class StateFixture(BaseFixture):
9798
env: FixtureEnvironment
9899
pre: Alloc
99100
transaction: FixtureTransaction
100-
post: Mapping[str, List[FixtureForkPost]]
101+
post: Mapping[Fork, List[FixtureForkPost]]
101102
config: FixtureConfig
102103

103-
def get_fork(self) -> str | None:
104+
def get_fork(self) -> Fork | None:
104105
"""Return fork of the fixture as a string."""
105106
forks = list(self.post.keys())
106107
assert len(forks) == 1, "Expected state test fixture with single fork"

src/ethereum_test_fixtures/tests/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_json_dict():
1212
"""Test that the json_dict property does not include the info field."""
1313
fixture = TransactionFixture(
1414
txbytes="0x1234",
15-
result={"fork": FixtureResult(intrinsic_gas=0)},
15+
result={"Paris": FixtureResult(intrinsic_gas=0)},
1616
)
1717
assert "_info" not in fixture.json_dict, "json_dict should exclude the 'info' field"
1818

@@ -38,7 +38,7 @@ def test_json_dict():
3838
pytest.param(
3939
TransactionFixture(
4040
transaction="0x1234",
41-
result={"fork": FixtureResult(intrinsic_gas=0)},
41+
result={"Paris": FixtureResult(intrinsic_gas=0)},
4242
),
4343
id="TransactionFixture",
4444
),

src/ethereum_test_fixtures/tests/test_eof.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
code=Bytes(b"\x00"),
2222
container_kind=ContainerKind.INITCODE,
2323
results={
24-
"result1": Result(
24+
"Paris": Result(
2525
exception=None,
2626
valid=True,
2727
),
@@ -35,7 +35,7 @@
3535
"code": "0x00",
3636
"containerKind": "INITCODE",
3737
"results": {
38-
"result1": {
38+
"Paris": {
3939
"result": True,
4040
},
4141
},
@@ -52,7 +52,7 @@
5252
code=Bytes(b"\x00"),
5353
container_kind=ContainerKind.RUNTIME,
5454
results={
55-
"result1": Result(
55+
"Paris": Result(
5656
exception=EOFException.INVALID_MAGIC,
5757
valid=False,
5858
),
@@ -66,7 +66,7 @@
6666
"code": "0x00",
6767
"containerKind": "RUNTIME",
6868
"results": {
69-
"result1": {
69+
"Paris": {
7070
"exception": "EOFException.INVALID_MAGIC",
7171
"result": False,
7272
},

0 commit comments

Comments
 (0)