@@ -263,3 +263,50 @@ fn connect_to_public_testnet_esplora() {
263263 node. sync_wallets ( ) . unwrap ( ) ;
264264 node. stop ( ) . unwrap ( ) ;
265265}
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 ! (
301+ reinitialized_node. on_chain_balance( ) . unwrap( ) . get_spendable( ) ,
302+ expected_amount. to_sat( )
303+ ) ;
304+
305+ reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
306+ assert_eq ! (
307+ reinitialized_node. on_chain_balance( ) . unwrap( ) . get_spendable( ) ,
308+ expected_amount. to_sat( )
309+ ) ;
310+
311+ reinitialized_node. stop ( ) . unwrap ( ) ;
312+ }
0 commit comments