1
- """Common pytest fixtures for the RLP and Engine simulators ."""
1
+ """Common pytest fixtures for simulators with single-test client architecture ."""
2
2
3
3
import io
4
4
import json
5
5
import logging
6
- from pathlib import Path
7
- from typing import Dict , Generator , Literal , cast
6
+ from typing import Generator , Literal , cast
8
7
9
8
import pytest
10
9
from hive .client import Client , ClientType
11
10
from hive .testing import HiveTest
12
11
13
12
from ethereum_test_base_types import Number , to_json
14
13
from ethereum_test_fixtures import (
15
- BaseFixture ,
16
14
BlockchainFixtureCommon ,
17
15
)
18
- from ethereum_test_fixtures .consume import TestCaseIndexFile , TestCaseStream
19
- from ethereum_test_fixtures .file import Fixtures
20
- from ethereum_test_rpc import EthRPC
21
- from pytest_plugins .consume .consume import FixturesSource
22
16
from pytest_plugins .consume .simulators .helpers .ruleset import (
23
17
ruleset , # TODO: generate dynamically
24
18
)
28
22
logger = logging .getLogger (__name__ )
29
23
30
24
31
- @pytest .fixture (scope = "function" )
32
- def eth_rpc (client : Client ) -> EthRPC :
33
- """Initialize ethereum RPC client for the execution client under test."""
34
- return EthRPC (f"http://{ client .ip } :8545" )
35
-
36
-
37
25
@pytest .fixture (scope = "function" )
38
26
def client_genesis (fixture : BlockchainFixtureCommon ) -> dict :
39
27
"""Convert the fixture genesis block header and pre-state to a client genesis state."""
@@ -44,18 +32,6 @@ def client_genesis(fixture: BlockchainFixtureCommon) -> dict:
44
32
return genesis
45
33
46
34
47
- @pytest .fixture (scope = "function" )
48
- def check_live_port (test_suite_name : str ) -> Literal [8545 , 8551 ]:
49
- """Port used by hive to check for liveness of the client."""
50
- if test_suite_name == "eest/consume-rlp" :
51
- return 8545
52
- elif test_suite_name == "eest/consume-engine" :
53
- return 8551
54
- raise ValueError (
55
- f"Unexpected test suite name '{ test_suite_name } ' while setting HIVE_CHECK_LIVE_PORT."
56
- )
57
-
58
-
59
35
@pytest .fixture (scope = "function" )
60
36
def environment (
61
37
fixture : BlockchainFixtureCommon ,
@@ -105,56 +81,3 @@ def client(
105
81
with total_timing_data .time ("Stop client" ):
106
82
client .stop ()
107
83
logger .info (f"Client ({ client_type .name } ) stopped!" )
108
-
109
-
110
- class FixturesDict (Dict [Path , Fixtures ]):
111
- """
112
- A dictionary caches loaded fixture files to avoid reloading the same file
113
- multiple times.
114
- """
115
-
116
- def __init__ (self ) -> None :
117
- """Initialize the dictionary that caches loaded fixture files."""
118
- self ._fixtures : Dict [Path , Fixtures ] = {}
119
-
120
- def __getitem__ (self , key : Path ) -> Fixtures :
121
- """Return the fixtures from the index file, if not found, load from disk."""
122
- assert key .is_file (), f"Expected a file path, got '{ key } '"
123
- if key not in self ._fixtures :
124
- self ._fixtures [key ] = Fixtures .model_validate_json (key .read_text ())
125
- return self ._fixtures [key ]
126
-
127
-
128
- @pytest .fixture (scope = "session" )
129
- def fixture_file_loader () -> Dict [Path , Fixtures ]:
130
- """Return a singleton dictionary that caches loaded fixture files used in all tests."""
131
- return FixturesDict ()
132
-
133
-
134
- @pytest .fixture (scope = "function" )
135
- def fixture (
136
- fixtures_source : FixturesSource ,
137
- fixture_file_loader : Dict [Path , Fixtures ],
138
- test_case : TestCaseIndexFile | TestCaseStream ,
139
- ) -> BaseFixture :
140
- """
141
- Load the fixture from a file or from stream in any of the supported
142
- fixture formats.
143
-
144
- The fixture is either already available within the test case (if consume
145
- is taking input on stdin) or loaded from the fixture json file if taking
146
- input from disk (fixture directory with index file).
147
- """
148
- fixture : BaseFixture
149
- if fixtures_source .is_stdin :
150
- assert isinstance (test_case , TestCaseStream ), "Expected a stream test case"
151
- fixture = test_case .fixture
152
- else :
153
- assert isinstance (test_case , TestCaseIndexFile ), "Expected an index file test case"
154
- fixtures_file_path = fixtures_source .path / test_case .json_path
155
- fixtures : Fixtures = fixture_file_loader [fixtures_file_path ]
156
- fixture = fixtures [test_case .id ]
157
- assert isinstance (fixture , test_case .format ), (
158
- f"Expected a { test_case .format .format_name } test fixture"
159
- )
160
- return fixture
0 commit comments