@@ -263,3 +263,44 @@ fn connect_to_public_testnet_esplora() {
263
263
node. sync_wallets ( ) . unwrap ( ) ;
264
264
node. stop ( ) . unwrap ( ) ;
265
265
}
266
+
267
+ #[ test]
268
+ fn start_stop_reinit ( ) {
269
+ let config = rand_config ( ) ;
270
+ let node = Builder :: from_config ( config. clone ( ) ) . build ( ) ;
271
+ let expected_node_id = node. node_id ( ) ;
272
+
273
+ let funding_address = node. new_funding_address ( ) . unwrap ( ) ;
274
+ let expected_amount = Amount :: from_sat ( 100000 ) ;
275
+
276
+ premine_and_distribute_funds ( vec ! [ funding_address] , expected_amount) ;
277
+ assert_eq ! ( node. on_chain_balance( ) . unwrap( ) . get_total( ) , 0 ) ;
278
+
279
+ node. start ( ) . unwrap ( ) ;
280
+ assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
281
+
282
+ node. sync_wallets ( ) . unwrap ( ) ;
283
+ assert_eq ! ( node. on_chain_balance( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
284
+
285
+ node. stop ( ) . unwrap ( ) ;
286
+ assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
287
+
288
+ node. start ( ) . unwrap ( ) ;
289
+ assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
290
+
291
+ node. stop ( ) . unwrap ( ) ;
292
+ assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
293
+ drop ( node) ;
294
+
295
+ let reinitialized_node = Builder :: from_config ( config) . build ( ) ;
296
+ assert_eq ! ( reinitialized_node. node_id( ) , expected_node_id) ;
297
+
298
+ reinitialized_node. start ( ) . unwrap ( ) ;
299
+
300
+ assert_eq ! ( reinitialized_node. on_chain_balance( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
301
+
302
+ reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
303
+ assert_eq ! ( reinitialized_node. on_chain_balance( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
304
+
305
+ reinitialized_node. stop ( ) . unwrap ( ) ;
306
+ }
0 commit comments