File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,9 @@ where
348
348
. collect :: < FuturesOrdered < _ > > ( ) ;
349
349
350
350
if handles. is_empty ( ) {
351
+ if last_index. is_none ( ) {
352
+ return Err ( Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ;
353
+ }
351
354
break ;
352
355
}
353
356
@@ -368,7 +371,8 @@ where
368
371
. extend ( evicted. into_iter ( ) . map ( |txid| ( txid, start_time) ) ) ;
369
372
}
370
373
371
- let last_index = last_index. expect ( "Must be set since handles wasn't empty." ) ;
374
+ let last_index =
375
+ last_index. ok_or_else ( || Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ?;
372
376
let gap_limit_reached = if let Some ( i) = last_active_index {
373
377
last_index >= i. saturating_add ( stop_gap as u32 )
374
378
} else {
@@ -571,6 +575,15 @@ mod test {
571
575
} } ;
572
576
}
573
577
578
+ #[ test]
579
+ fn ensure_last_index_none_returns_error ( ) {
580
+ let last_index: Option < u32 > = None ;
581
+ let err = last_index
582
+ . ok_or_else ( || Box :: new ( esplora_client:: Error :: InvalidResponse ) )
583
+ . unwrap_err ( ) ;
584
+ assert ! ( matches!( * err, esplora_client:: Error :: InvalidResponse ) ) ;
585
+ }
586
+
574
587
// Test that `chain_update` fails due to wrong network.
575
588
#[ tokio:: test]
576
589
async fn test_chain_update_wrong_network_error ( ) -> anyhow:: Result < ( ) > {
Original file line number Diff line number Diff line change @@ -343,7 +343,8 @@ fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<SpkWithExpectedTxids>
343
343
. extend ( evicted. into_iter ( ) . map ( |txid| ( txid, start_time) ) ) ;
344
344
}
345
345
346
- let last_index = last_index. expect ( "Must be set since handles wasn't empty." ) ;
346
+ let last_index =
347
+ last_index. ok_or_else ( || Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ?;
347
348
let gap_limit_reached = if let Some ( i) = last_active_index {
348
349
last_index >= i. saturating_add ( stop_gap as u32 )
349
350
} else {
@@ -561,6 +562,15 @@ mod test {
561
562
) ) ;
562
563
}
563
564
565
+ #[ test]
566
+ fn ensure_last_index_none_returns_error ( ) {
567
+ let last_index: Option < u32 > = None ;
568
+ let err = last_index
569
+ . ok_or_else ( || Box :: new ( esplora_client:: Error :: InvalidResponse ) )
570
+ . unwrap_err ( ) ;
571
+ assert ! ( matches!( * err, esplora_client:: Error :: InvalidResponse ) ) ;
572
+ }
573
+
564
574
macro_rules! local_chain {
565
575
[ $( ( $height: expr, $block_hash: expr) ) , * ] => { {
566
576
#[ allow( unused_mut) ]
You can’t perform that action at this time.
0 commit comments