@@ -143,43 +143,56 @@ proptest! {
143143 generate_blocks_and_wait( bitcoind, electrs, 1 ) . await ;
144144 sync_wallets!( ) ;
145145
146- if force_close {
147- for node in & nodes {
148- node. sync_wallets( ) . unwrap( ) ;
149- // If there is no more balance, there is nothing to process here.
150- if node. list_balances( ) . lightning_balances. len( ) < 1 {
151- return ;
152- }
153- match node. list_balances( ) . lightning_balances[ 0 ] {
154- LightningBalance :: ClaimableAwaitingConfirmations {
155- confirmation_height,
156- ..
157- } => {
158- let cur_height = node. status( ) . current_best_block. height;
159- let blocks_to_go = confirmation_height - cur_height;
146+ if force_close {
147+ let mut found_claimable_balance = false ;
148+ for node in & nodes {
149+ node. sync_wallets( ) . unwrap( ) ;
150+ let balances = node. list_balances( ) ;
151+ let confirmation_height = balances. lightning_balances. iter( ) . find_map( |b| {
152+ match b {
153+ LightningBalance :: ClaimableAwaitingConfirmations {
154+ confirmation_height,
155+ ..
156+ } => Some ( * confirmation_height) ,
157+ _ => None ,
158+ }
159+ } ) ;
160+ let Some ( confirmation_height) = confirmation_height else {
161+ continue ;
162+ } ;
163+ found_claimable_balance = true ;
164+
165+ let cur_height = node. status( ) . current_best_block. height;
166+ let blocks_to_go = confirmation_height. saturating_sub( cur_height) ;
167+ if blocks_to_go > 0 {
160168 generate_blocks_and_wait( bitcoind, electrs, blocks_to_go as usize ) . await ;
161169 node. sync_wallets( ) . unwrap( ) ;
162- } ,
163- _ => panic!( "Unexpected balance state for node_hub!" ) ,
164- }
165-
166- assert!( node. list_balances( ) . lightning_balances. len( ) < 2 ) ;
167- assert!( node. list_balances( ) . pending_balances_from_channel_closures. len( ) > 0 ) ;
168- match node. list_balances( ) . pending_balances_from_channel_closures[ 0 ] {
169- PendingSweepBalance :: BroadcastAwaitingConfirmation { .. } => { } ,
170- _ => panic!( "Unexpected balance state!" ) ,
171- }
170+ }
172171
173- generate_blocks_and_wait( & bitcoind, electrs, 1 ) . await ;
174- node. sync_wallets( ) . unwrap( ) ;
175- assert!( node. list_balances( ) . lightning_balances. len( ) < 2 ) ;
176- assert!( node. list_balances( ) . pending_balances_from_channel_closures. len( ) > 0 ) ;
177- match node. list_balances( ) . pending_balances_from_channel_closures[ 0 ] {
178- PendingSweepBalance :: AwaitingThresholdConfirmations { .. } => { } ,
179- _ => panic!( "Unexpected balance state!" ) ,
172+ let balances = node. list_balances( ) ;
173+ assert!(
174+ balances. pending_balances_from_channel_closures. iter( ) . any( |b| matches!(
175+ b,
176+ PendingSweepBalance :: BroadcastAwaitingConfirmation { .. }
177+ | PendingSweepBalance :: AwaitingThresholdConfirmations { .. }
178+ ) ) ,
179+ "Unexpected balance state: {:?}" ,
180+ balances
181+ ) ;
182+
183+ generate_blocks_and_wait( bitcoind, electrs, 1 ) . await ;
184+ node. sync_wallets( ) . unwrap( ) ;
185+ let balances = node. list_balances( ) ;
186+ assert!(
187+ balances. pending_balances_from_channel_closures. iter( ) . any( |b| {
188+ matches!( b, PendingSweepBalance :: AwaitingThresholdConfirmations { .. } )
189+ } ) ,
190+ "Unexpected balance state: {:?}" ,
191+ balances
192+ ) ;
180193 }
194+ assert!( found_claimable_balance) ;
181195 }
182- }
183196
184197 generate_blocks_and_wait( bitcoind, electrs, 6 ) . await ;
185198 sync_wallets!( ) ;
0 commit comments