1212from .types import NetworkConfig
1313
1414
15- @pytest .fixture (scope = "session" )
16- def eth_config_response (request ) -> EthConfigResponse | None :
17- """Get the `eth_config` response from the user-provided RPC endpoint."""
18- config = request .config
19- eth_rpc_url = config .getoption ("rpc_endpoint" )
20- eth_rpc_target = EthRPC (eth_rpc_url )
21- return eth_rpc_target .config ()
15+ @pytest .fixture (scope = "function" )
16+ def eth_config_response (eth_rpc : List [EthRPC ]) -> EthConfigResponse | None :
17+ """Get the `eth_config` response from the client to be verified by all tests."""
18+ assert len (eth_rpc ) > 0
19+ return eth_rpc [0 ].config () # just pick the first of possible URLs for this exec client
2220
2321
24- @pytest .fixture (scope = "session " )
22+ @pytest .fixture (scope = "function " )
2523def network (request ) -> NetworkConfig :
2624 """Get the network that will be used to verify all tests."""
2725 return request .config .network
2826
2927
30- @pytest .fixture (scope = "session " )
28+ @pytest .fixture (scope = "function " )
3129def current_time () -> int :
3230 """Get the `eth_config` response from the client to be verified by all tests."""
3331 return int (time .time ())
3432
3533
36- @pytest .fixture (scope = "session " )
34+ @pytest .fixture (scope = "function " )
3735def expected_eth_config (network : NetworkConfig , current_time : int ) -> EthConfigResponse :
3836 """Calculate the current fork value to verify against the client's response."""
3937 print (f"Network provided: { network } , Type: { type (network )} " )
@@ -43,13 +41,8 @@ def expected_eth_config(network: NetworkConfig, current_time: int) -> EthConfigR
4341def test_eth_config_current (
4442 eth_config_response : EthConfigResponse | None ,
4543 expected_eth_config : EthConfigResponse ,
46- request ,
4744) -> None :
4845 """Validate `current` field of the `eth_config` RPC endpoint."""
49- config = request .config
50- if config .getoption ("network_config_file" ) is None :
51- pytest .skip ("Skipping test because no 'network_config_file' was specified" )
52-
5346 assert eth_config_response is not None , "Client did not return a valid `eth_config` response."
5447 assert eth_config_response .current is not None , (
5548 "Client did not return a valid `current` fork config."
@@ -65,13 +58,8 @@ def test_eth_config_current(
6558def test_eth_config_current_fork_id (
6659 eth_config_response : EthConfigResponse | None ,
6760 expected_eth_config : EthConfigResponse ,
68- request ,
6961) -> None :
7062 """Validate `forkId` field within the `current` configuration object."""
71- config = request .config
72- if config .getoption ("network_config_file" ) is None :
73- pytest .skip ("Skipping test because no 'network_config_file' was specified" )
74-
7563 assert eth_config_response is not None , "Client did not return a valid `eth_config` response."
7664 assert eth_config_response .current is not None , (
7765 "Client did not return a valid `current` fork config."
@@ -89,13 +77,8 @@ def test_eth_config_current_fork_id(
8977def test_eth_config_next (
9078 eth_config_response : EthConfigResponse | None ,
9179 expected_eth_config : EthConfigResponse ,
92- request ,
9380) -> None :
9481 """Validate `next` field of the `eth_config` RPC endpoint."""
95- config = request .config
96- if config .getoption ("network_config_file" ) is None :
97- pytest .skip ("Skipping test because no 'network_config_file' was specified" )
98-
9982 assert eth_config_response is not None , "Client did not return a valid `eth_config` response."
10083 expected_next = expected_eth_config .next
10184 if expected_next is None :
@@ -116,13 +99,8 @@ def test_eth_config_next(
11699def test_eth_config_next_fork_id (
117100 eth_config_response : EthConfigResponse | None ,
118101 expected_eth_config : EthConfigResponse ,
119- request ,
120102) -> None :
121103 """Validate `forkId` field within the `next` configuration object."""
122- config = request .config
123- if config .getoption ("network_config_file" ) is None :
124- pytest .skip ("Skipping test because no 'network_config_file' was specified" )
125-
126104 assert eth_config_response is not None , "Client did not return a valid `eth_config` response."
127105 expected_next = expected_eth_config .next
128106 if expected_next is None :
@@ -151,13 +129,8 @@ def test_eth_config_next_fork_id(
151129def test_eth_config_last (
152130 eth_config_response : EthConfigResponse | None ,
153131 expected_eth_config : EthConfigResponse ,
154- request ,
155132) -> None :
156133 """Validate `last` field of the `eth_config` RPC endpoint."""
157- config = request .config
158- if config .getoption ("network_config_file" ) is None :
159- pytest .skip ("Skipping test because no 'network_config_file' was specified" )
160-
161134 expected_last = expected_eth_config .last
162135 assert eth_config_response is not None , "Client did not return a valid `eth_config` response."
163136 if expected_last is None :
@@ -178,13 +151,8 @@ def test_eth_config_last(
178151def test_eth_config_last_fork_id (
179152 eth_config_response : EthConfigResponse | None ,
180153 expected_eth_config : EthConfigResponse ,
181- request ,
182154) -> None :
183155 """Validate `forkId` field within the `last` configuration object."""
184- config = request .config
185- if config .getoption ("network_config_file" ) is None :
186- pytest .skip ("Skipping test because no 'network_config_file' was specified" )
187-
188156 assert eth_config_response is not None , "Client did not return a valid `eth_config` response."
189157 expected_last = expected_eth_config .last
190158 if expected_last is None :
@@ -211,24 +179,15 @@ def test_eth_config_last_fork_id(
211179
212180
213181def test_eth_config_majority (
214- eth_rpc : Dict [str , List [EthRPC ]],
215- request ,
182+ all_rpc_endpoints : Dict [str , List [EthRPC ]],
216183) -> None :
217184 """Queries devnet exec clients for their eth_config and fails if not all have the same response.""" # noqa: E501
218- # decide whether to run this test
219- config = request .config
220- run_this_test_bool = config .getoption (name = "majority_eth_config_test_enabled" )
221- if not run_this_test_bool :
222- pytest .skip ("Skipping eth_config majority test" )
223-
224- assert eth_rpc is not None
225-
226185 responses = dict () # Dict[exec_client_name : response] # noqa: C408
227186 client_to_url_used_dict = dict () # noqa: C408
228- for exec_client in eth_rpc .keys ():
187+ for exec_client in all_rpc_endpoints .keys ():
229188 # try only as many consensus+exec client combinations until you receive a response
230189 # if all combinations for a given exec client fail we panic
231- for eth_rpc_target in eth_rpc [exec_client ]:
190+ for eth_rpc_target in all_rpc_endpoints [exec_client ]:
232191 response = eth_rpc_target .config (timeout = 10 )
233192 if response is None :
234193 # safely split url to not leak rpc_endpoint in logs
@@ -246,11 +205,14 @@ def test_eth_config_majority(
246205
247206 break # no need to gather more responses for this client
248207
249- assert len (responses .keys ()) == len (eth_rpc .keys ()), "Failed to get an eth_config response "
250- f" from each specified execution client. Full list of execution clients is { eth_rpc .keys ()} "
251- f"but we were only able to gather eth_config responses from: { responses .keys ()} \n Will try "
252- "again with a different consensus-execution client combination for this execution client"
253-
208+ assert len (responses .keys ()) == len (all_rpc_endpoints .keys ()), (
209+ "Failed to get an eth_config response "
210+ f" from each specified execution client. Full list of execution clients is "
211+ f"{ all_rpc_endpoints .keys ()} but we were only able to gather eth_config responses "
212+ f"from: { responses .keys ()} \n "
213+ "Will try again with a different consensus-execution client combination for "
214+ "this execution client"
215+ )
254216 # determine hashes of client responses
255217 client_to_hash_dict = dict () # Dict[exec_client : response hash] # noqa: C408
256218 for client in responses .keys ():
0 commit comments