@@ -130,6 +130,83 @@ def fake_SetSettings(self, name, value):
130130 assert "Upgrade - Error" in output
131131
132132
133+ def test_reload_global_config (cli , monkeypatch ):
134+ # the cli fixture pins GetNetworkName to "mainnet"
135+ valid_config = json .dumps ({"validator" : {}, "liteservers" : []})
136+
137+ class FakeResponse :
138+ def __init__ (self , text , status = 200 ):
139+ self .text = text
140+ self ._status = status
141+
142+ def raise_for_status (self ):
143+ if self ._status >= 400 :
144+ raise Exception (f"HTTP { self ._status } " )
145+
146+ requested = {}
147+
148+ def fake_get (url , timeout = None ):
149+ requested ["url" ] = url
150+ requested ["timeout" ] = timeout
151+ return FakeResponse (valid_config )
152+
153+ monkeypatch .setattr (general_module .requests , "get" , fake_get )
154+
155+ copied = {}
156+
157+ def fake_run_as_root (run_args ):
158+ copied ["args" ] = run_args
159+ # the temp source file must still exist when we install it into place
160+ assert pathlib .Path (run_args [3 ]).is_file ()
161+ return 0
162+
163+ monkeypatch .setattr (general_module , "run_as_root" , fake_run_as_root )
164+
165+ # no url -> mainnet default url, installed to the global config path
166+ output = cli .execute ("reload_global_config" , no_color = True )
167+ assert requested ["url" ] == "https://ton-blockchain.github.io/global.config.json"
168+ assert copied ["args" ][:3 ] == ["install" , "-m" , "0644" ]
169+ assert copied ["args" ][4 ] == "/usr/bin/ton/global.config.json"
170+ assert not pathlib .Path (copied ["args" ][3 ]).exists () # temp file cleaned up
171+ assert "reload_global_config - OK" in output
172+
173+ # explicit url arg overrides the default
174+ output = cli .execute (
175+ "reload_global_config https://example.com/custom.json" , no_color = True
176+ )
177+ assert requested ["url" ] == "https://example.com/custom.json"
178+ assert "reload_global_config - OK" in output
179+
180+ # too many args -> usage error, nothing downloaded
181+ requested .clear ()
182+ output = cli .execute ("reload_global_config a b" , no_color = True )
183+ assert "Bad args" in output
184+ assert requested == {}
185+
186+ # non-json response -> error, config is not touched
187+ copied .clear ()
188+ monkeypatch .setattr (
189+ general_module .requests ,
190+ "get" ,
191+ lambda url , timeout = None : FakeResponse ("<html>not json</html>" ),
192+ )
193+ output = cli .execute ("reload_global_config" , no_color = True )
194+ assert "reload_global_config error" in output
195+ assert copied == {}
196+
197+ # network unknown and no url -> ask for explicit url
198+ monkeypatch .setattr (general_module .requests , "get" , fake_get )
199+ monkeypatch .setattr (MyTonCore , "GetNetworkName" , lambda self : "unknown" )
200+ output = cli .execute ("reload_global_config" , no_color = True )
201+ assert "could not detect the network" in output
202+
203+ # root install fails -> Error
204+ monkeypatch .setattr (MyTonCore , "GetNetworkName" , lambda self : "mainnet" )
205+ monkeypatch .setattr (general_module , "run_as_root" , lambda _ : 1 )
206+ output = cli .execute ("reload_global_config" , no_color = True )
207+ assert "reload_global_config - Error" in output
208+
209+
133210def test_installer (cli , monkeypatch ):
134211 calls = {}
135212 def fake_run (self , cmd ):
0 commit comments