11import os
22from typing import Optional
3+
4+ import mock
35import pytest
46import requests
5- import mock
67
7- from node_cli .configs .env import (
8- SkaleEnvConfig ,
9- SyncEnvConfig ,
10- MirageEnvConfig ,
11- absent_required_params ,
12- get_env_class ,
13- populate_env_params ,
14- get_validated_env_config ,
15- validate_env_params ,
16- validate_env_type ,
17- ALLOWED_ENV_TYPES ,
18- REQUIRED_PARAMS_MIRAGE_BOOT ,
19- REQUIRED_PARAMS_MIRAGE ,
20- OPTIONAL_PARAMS ,
21- )
228from node_cli .configs .alias_address_validation import (
23- validate_env_alias_or_address ,
24- validate_contract_address ,
25- validate_contract_alias ,
9+ ContractType ,
2610 get_chain_id ,
2711 get_network_metadata ,
28- ContractType ,
12+ validate_contract_address ,
13+ validate_contract_alias ,
14+ validate_env_alias_or_address ,
15+ )
16+ from node_cli .configs .env import (
17+ ALLOWED_ENV_TYPES ,
18+ OPTIONAL_PARAMS ,
19+ REQUIRED_PARAMS_MIRAGE ,
20+ REQUIRED_PARAMS_MIRAGE_BOOT ,
21+ MirageBootUserConfig ,
22+ MirageUserConfig ,
23+ SkaleUserConfig ,
24+ SyncUserConfig ,
25+ absent_required_params ,
26+ get_user_config_type ,
27+ get_validated_user_config ,
28+ validate_env_type ,
2929)
30- from node_cli .utils .exit_codes import CLIExitCodes
3130from node_cli .utils .node_type import NodeType
3231
3332ENDPOINT = 'http://localhost:8545'
@@ -42,38 +41,18 @@ def json(self):
4241 return self ._json_data
4342
4443
45- def test_absent_required_params_returns_missing_keys ():
46- params = {
47- 'A' : '' ,
48- 'B' : 'value' ,
49- 'C' : '' ,
50- 'MONITORING_CONTAINERS' : 'optional' ,
51- }
52- missing = absent_required_params (params )
53- assert 'A' in missing
54- assert 'C' in missing
55- assert 'MONITORING_CONTAINERS' not in missing
56-
57-
58- def test_populate_env_params_updates_from_environ (monkeypatch ):
59- params = {'FOO' : '' }
60- monkeypatch .setenv ('FOO' , 'bar' )
61- populate_env_params (params )
62- assert params ['FOO' ] == 'bar'
63-
64-
6544@pytest .mark .parametrize (
6645 'node_type, is_mirage_boot, expected_type' ,
6746 [
68- (NodeType .REGULAR , False , SkaleEnvConfig ),
69- (NodeType .SYNC , False , SyncEnvConfig ),
70- (NodeType .MIRAGE , True , SkaleEnvConfig ),
71- (NodeType .MIRAGE , False , MirageEnvConfig ),
47+ (NodeType .REGULAR , False , SkaleUserConfig ),
48+ (NodeType .SYNC , False , SyncUserConfig ),
49+ (NodeType .MIRAGE , True , MirageBootUserConfig ),
50+ (NodeType .MIRAGE , False , MirageUserConfig ),
7251 ],
7352 ids = ['regular' , 'sync' , 'mirage_boot' , 'mirage_regular' ],
7453)
7554def test_build_env_params_keys (node_type , is_mirage_boot , expected_type ):
76- env_type = get_env_class (node_type = node_type , is_mirage_boot = is_mirage_boot )
55+ env_type = get_user_config_type (node_type = node_type , is_mirage_boot = is_mirage_boot )
7756 assert env_type == expected_type
7857
7958
@@ -190,47 +169,6 @@ def test_validate_env_alias_or_address_with_alias(requests_mock):
190169 validate_env_alias_or_address ('test-alias' , ContractType .IMA , ENDPOINT )
191170
192171
193- @pytest .mark .parametrize ('env_type' , ALLOWED_ENV_TYPES )
194- @pytest .mark .parametrize (
195- 'required_params, key_to_remove, should_fail' ,
196- [
197- (REQUIRED_PARAMS_MIRAGE_BOOT , None , False ),
198- (REQUIRED_PARAMS_MIRAGE , None , False ),
199- (REQUIRED_PARAMS_MIRAGE_BOOT , 'IMA_CONTRACTS' , True ),
200- (REQUIRED_PARAMS_MIRAGE_BOOT , 'FILEBEAT_HOST' , True ),
201- (REQUIRED_PARAMS_MIRAGE , 'FILEBEAT_HOST' , True ),
202- ],
203- ids = [
204- 'mirage_boot' ,
205- 'mirage_regular' ,
206- 'mirage_boot_missing_ima' ,
207- 'mirage_boot_missing_filebeat' ,
208- 'mirage_regular_missing_filebeat' ,
209- ],
210- )
211- @mock .patch ('node_cli.configs.env.validate_env_alias_or_address' )
212- @mock .patch ('node_cli.configs.env.validate_env_type' )
213- def test_validate_env_params_mirage (
214- mock_validate_type ,
215- mock_validate_alias ,
216- required_params ,
217- key_to_remove ,
218- should_fail ,
219- env_type ,
220- ):
221- params = {k : f'{ k } _val' for k in required_params }
222- params ['ENV_TYPE' ] = env_type
223-
224- if key_to_remove :
225- params [key_to_remove ] = ''
226-
227- if should_fail :
228- with pytest .raises (SystemExit ):
229- validate_env_params (params = params )
230- else :
231- validate_env_params (params = params )
232-
233-
234172@pytest .mark .parametrize (
235173 'node_type, is_boot, required_keys_dict' ,
236174 [
@@ -280,12 +218,12 @@ def test_get_validated_env_config_mirage_success(
280218 with mock .patch ('node_cli.configs.alias_address_validation.requests.post' ) as mock_post :
281219 mock_post .return_value = FakeResponse (200 , {'result' : '0x123' })
282220
283- config = get_validated_env_config (
221+ user_config = get_validated_user_config (
284222 node_type = node_type , env_filepath = str (env_file ), is_mirage_boot = is_boot
285223 )
286224
287- assert config is not None
288- plain_config = config .to_env ()
225+ assert user_config is not None
226+ plain_config = user_config .to_env ()
289227 assert set (plain_config .keys ()) == set (expected_config .keys ())
290228 for key in expected_config :
291229 assert plain_config [key ] == expected_config [key ]
@@ -296,7 +234,7 @@ def test_get_validated_env_config_mirage_success(
296234
297235def test_get_validated_env_config_missing_file ():
298236 with pytest .raises (SystemExit ):
299- get_validated_env_config (env_filepath = 'nonexistent.env' , node_type = NodeType .REGULAR )
237+ get_validated_user_config (env_filepath = 'nonexistent.env' , node_type = NodeType .REGULAR )
300238
301239
302240def test_get_validated_env_config_unreadable_file (tmp_path ):
@@ -306,6 +244,6 @@ def test_get_validated_env_config_unreadable_file(tmp_path):
306244 try :
307245 os .chmod (env_file , 0o000 )
308246 with pytest .raises (PermissionError ):
309- get_validated_env_config (env_filepath = str (env_file ), node_type = NodeType .REGULAR )
247+ get_validated_user_config (env_filepath = str (env_file ), node_type = NodeType .REGULAR )
310248 finally :
311249 os .chmod (env_file , original_mode )
0 commit comments