@@ -27,9 +27,20 @@ def set_test_params(self):
2727 self .wallet_names = []
2828 self .disable_autoconnect = False
2929
30+ # Overridden to avoid attempt to sync not yet started nodes.
31+ def setup_network (self ):
32+ self .setup_nodes ()
33+
34+ # Overriden to not start nodes automatically - doing so is the
35+ # responsibility of each test function.
36+ def setup_nodes (self ):
37+ self .add_nodes (self .num_nodes , self .extra_args )
38+ # Ensure a log file exists as TestNode.assert_debug_log() expects it.
39+ self .nodes [0 ].debug_log_path .parent .mkdir ()
40+ self .nodes [0 ].debug_log_path .touch ()
41+
3042 def test_config_file_parser (self ):
3143 self .log .info ('Test config file parser' )
32- self .stop_node (0 )
3344
3445 # Check that startup fails if conf= is set in bitcoin.conf or in an included conf file
3546 bad_conf_file_path = self .nodes [0 ].datadir_path / "bitcoin_bad.conf"
@@ -162,12 +173,11 @@ def test_invalid_command_line_options(self):
162173 )
163174
164175 def test_log_buffer (self ):
165- self .stop_node (0 )
166176 with self .nodes [0 ].assert_debug_log (expected_msgs = ['Warning: parsed potentially confusing double-negative -connect=0\n ' ]):
167177 self .start_node (0 , extra_args = ['-noconnect=0' ])
178+ self .stop_node (0 )
168179
169180 def test_args_log (self ):
170- self .stop_node (0 )
171181 self .log .info ('Test config args logging' )
172182 with self .nodes [0 ].assert_debug_log (
173183 expected_msgs = [
@@ -196,10 +206,10 @@ def test_args_log(self):
196206 '-rpcuser=secret-rpcuser' ,
197207 '-torpassword=secret-torpassword' ,
198208 ])
209+ self .stop_node (0 )
199210
200211 def test_networkactive (self ):
201212 self .log .info ('Test -networkactive option' )
202- self .stop_node (0 )
203213 with self .nodes [0 ].assert_debug_log (expected_msgs = ['SetNetworkActive: true\n ' ]):
204214 self .start_node (0 )
205215
@@ -222,16 +232,12 @@ def test_networkactive(self):
222232 self .stop_node (0 )
223233 with self .nodes [0 ].assert_debug_log (expected_msgs = ['SetNetworkActive: false\n ' ]):
224234 self .start_node (0 , extra_args = ['-nonetworkactive=1' ])
235+ self .stop_node (0 )
225236
226237 def test_seed_peers (self ):
227238 self .log .info ('Test seed peers' )
228239 default_data_dir = self .nodes [0 ].datadir_path
229240 peer_dat = default_data_dir / 'peers.dat'
230- # Only regtest has no fixed seeds. To avoid connections to random
231- # nodes, regtest is the only network where it is safe to enable
232- # -fixedseeds in tests
233- util .assert_equal (self .nodes [0 ].getblockchaininfo ()['chain' ],'regtest' )
234- self .stop_node (0 )
235241
236242 # No peers.dat exists and -dnsseed=1
237243 # We expect the node will use DNS Seeds, but Regtest mode does not have
@@ -248,6 +254,12 @@ def test_seed_peers(self):
248254 timeout = 10 ,
249255 ):
250256 self .start_node (0 , extra_args = ['-dnsseed=1' , '-fixedseeds=1' , f'-mocktime={ start } ' ])
257+
258+ # Only regtest has no fixed seeds. To avoid connections to random
259+ # nodes, regtest is the only network where it is safe to enable
260+ # -fixedseeds in tests
261+ util .assert_equal (self .nodes [0 ].getblockchaininfo ()['chain' ],'regtest' )
262+
251263 with self .nodes [0 ].assert_debug_log (expected_msgs = [
252264 "Adding fixed seeds as 60 seconds have passed and addrman is empty" ,
253265 ]):
@@ -294,13 +306,13 @@ def test_seed_peers(self):
294306 "Adding fixed seeds as 60 seconds have passed and addrman is empty" ,
295307 ]):
296308 self .nodes [0 ].setmocktime (start + 65 )
309+ self .stop_node (0 )
297310
298311 def test_connect_with_seednode (self ):
299312 self .log .info ('Test -connect with -seednode' )
300313 seednode_ignored = ['-seednode is ignored when -connect is used\n ' ]
301314 dnsseed_ignored = ['-dnsseed is ignored when -connect is used and -proxy is specified\n ' ]
302315 addcon_thread_started = ['addcon thread start\n ' ]
303- self .stop_node (0 )
304316
305317 # When -connect is supplied, expanding addrman via getaddr calls to ADDR_FETCH(-seednode)
306318 # nodes is irrelevant and -seednode is ignored.
@@ -325,6 +337,7 @@ def test_connect_with_seednode(self):
325337 with self .nodes [0 ].assert_debug_log (expected_msgs = addcon_thread_started ,
326338 unexpected_msgs = seednode_ignored ):
327339 self .restart_node (0 , extra_args = [connect_arg , '-seednode=fakeaddress2' ])
340+ self .stop_node (0 )
328341
329342 def test_ignored_conf (self ):
330343 self .log .info ('Test error is triggered when the datadir in use contains a bitcoin.conf file that would be ignored '
0 commit comments