@@ -589,6 +589,52 @@ mod chain_notifier_tests {
589
589
Ok ( _) => { } ,
590
590
}
591
591
}
592
+
593
+ #[ tokio:: test]
594
+ async fn sync_from_chain_without_headers ( ) {
595
+ let mut chain = Blockchain :: default ( ) . with_height ( 3 ) . without_headers ( ) ;
596
+
597
+ let new_tip = chain. tip ( ) ;
598
+ let old_tip = chain. at_height ( 1 ) ;
599
+ let mut listener = MockChainListener :: new ( ) ;
600
+ let mut notifier = ChainNotifier { header_cache : chain. header_cache ( 0 ..=1 ) } ;
601
+ let mut poller = poller:: ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Testnet ) ;
602
+ match notifier. sync_listener ( new_tip, & old_tip, & mut poller, & mut listener) . await {
603
+ Err ( ( _, tip) ) => assert_eq ! ( tip, None ) ,
604
+ Ok ( _) => panic ! ( "Expected error" ) ,
605
+ }
606
+ }
607
+
608
+ #[ tokio:: test]
609
+ async fn sync_from_chain_without_any_new_blocks ( ) {
610
+ let mut chain = Blockchain :: default ( ) . with_height ( 3 ) . without_blocks ( 2 ..) ;
611
+
612
+ let new_tip = chain. tip ( ) ;
613
+ let old_tip = chain. at_height ( 1 ) ;
614
+ let mut listener = MockChainListener :: new ( ) ;
615
+ let mut notifier = ChainNotifier { header_cache : chain. header_cache ( 0 ..=3 ) } ;
616
+ let mut poller = poller:: ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Testnet ) ;
617
+ match notifier. sync_listener ( new_tip, & old_tip, & mut poller, & mut listener) . await {
618
+ Err ( ( _, tip) ) => assert_eq ! ( tip, Some ( old_tip) ) ,
619
+ Ok ( _) => panic ! ( "Expected error" ) ,
620
+ }
621
+ }
622
+
623
+ #[ tokio:: test]
624
+ async fn sync_from_chain_without_some_new_blocks ( ) {
625
+ let mut chain = Blockchain :: default ( ) . with_height ( 3 ) . without_blocks ( 3 ..) ;
626
+
627
+ let new_tip = chain. tip ( ) ;
628
+ let old_tip = chain. at_height ( 1 ) ;
629
+ let mut listener = MockChainListener :: new ( )
630
+ . expect_block_connected ( * chain. at_height ( 2 ) ) ;
631
+ let mut notifier = ChainNotifier { header_cache : chain. header_cache ( 0 ..=3 ) } ;
632
+ let mut poller = poller:: ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Testnet ) ;
633
+ match notifier. sync_listener ( new_tip, & old_tip, & mut poller, & mut listener) . await {
634
+ Err ( ( _, tip) ) => assert_eq ! ( tip, Some ( chain. at_height( 2 ) ) ) ,
635
+ Ok ( _) => panic ! ( "Expected error" ) ,
636
+ }
637
+ }
592
638
}
593
639
594
640
#[ cfg( test) ]
0 commit comments