@@ -483,6 +483,14 @@ mod tests {
483
483
let mut light_store = MemoryStore :: new ( ) ;
484
484
light_store. insert ( trusted_state, Status :: Trusted ) ;
485
485
486
+ for extra_trusted_height in trust_options. extra_heights {
487
+ let trusted_state = io
488
+ . fetch_light_block ( AtHeight :: At ( extra_trusted_height) )
489
+ . expect ( "could not 'request' light block" ) ;
490
+
491
+ light_store. insert ( trusted_state, Status :: Trusted ) ;
492
+ }
493
+
486
494
let state = State {
487
495
light_store : Box :: new ( light_store) ,
488
496
verification_trace : HashMap :: new ( ) ,
@@ -526,17 +534,12 @@ mod tests {
526
534
)
527
535
}
528
536
529
- fn make_peer_list (
537
+ fn make_peer_list_opts (
530
538
primary : Option < Vec < LightBlock > > ,
531
539
witnesses : Option < Vec < Vec < LightBlock > > > ,
532
540
now : Time ,
541
+ trust_options : TrustOptions ,
533
542
) -> PeerList < Instance > {
534
- let trust_options = TrustOptions {
535
- period : DurationStr ( Duration :: new ( 604800 , 0 ) ) ,
536
- height : Height :: try_from ( 1_u64 ) . expect ( "Error while making height" ) ,
537
- trust_level : TrustThresholdFraction :: TWO_THIRDS ,
538
- } ;
539
-
540
543
let mut peer_list = PeerList :: builder ( ) ;
541
544
542
545
if let Some ( primary) = primary {
@@ -559,6 +562,24 @@ mod tests {
559
562
peer_list. build ( )
560
563
}
561
564
565
+ fn make_peer_list (
566
+ primary : Option < Vec < LightBlock > > ,
567
+ witnesses : Option < Vec < Vec < LightBlock > > > ,
568
+ now : Time ,
569
+ ) -> PeerList < Instance > {
570
+ make_peer_list_opts (
571
+ primary,
572
+ witnesses,
573
+ now,
574
+ TrustOptions {
575
+ period : DurationStr ( Duration :: new ( 604800 , 0 ) ) ,
576
+ height : Height :: try_from ( 1_u64 ) . expect ( "Error while making height" ) ,
577
+ extra_heights : vec ! [ ] ,
578
+ trust_level : TrustThresholdFraction :: TWO_THIRDS ,
579
+ } ,
580
+ )
581
+ }
582
+
562
583
fn change_provider (
563
584
mut light_blocks : Vec < LightBlock > ,
564
585
peer_id : Option < & str > ,
@@ -859,4 +880,38 @@ mod tests {
859
880
. iter( )
860
881
. any( |& peer| peer == primary[ 0 ] . provider) ) ;
861
882
}
883
+
884
+ #[ test]
885
+ fn test_bisection_between_trusted_heights ( ) {
886
+ let chain = LightChain :: default_with_length ( 10 ) ;
887
+ let primary = chain
888
+ . light_blocks
889
+ . into_iter ( )
890
+ . map ( |lb| lb. generate ( ) . unwrap ( ) . into_light_block ( ) )
891
+ . collect :: < Vec < LightBlock > > ( ) ;
892
+
893
+ let witness = change_provider ( primary. clone ( ) , None ) ;
894
+
895
+ // Specify two trusted heights (1 and 8), then attempt to verify target height 4 which
896
+ // falls between the two. Verification should use regular bisection.
897
+
898
+ let peer_list = make_peer_list_opts (
899
+ Some ( primary. clone ( ) ) ,
900
+ Some ( vec ! [ witness] ) ,
901
+ get_time ( 11 ) . unwrap ( ) ,
902
+ TrustOptions {
903
+ period : DurationStr ( Duration :: new ( 604800 , 0 ) ) ,
904
+ height : Height :: try_from ( 1_u64 ) . expect ( "Error while making height" ) ,
905
+ extra_heights : vec ! [ Height :: try_from( 8_u64 ) . expect( "Error while making height" ) ] ,
906
+ trust_level : TrustThresholdFraction :: TWO_THIRDS ,
907
+ } ,
908
+ ) ;
909
+
910
+ let ( result, _) = run_bisection_test ( peer_list, 4 ) ;
911
+
912
+ let expected_state = primary[ 3 ] . clone ( ) ;
913
+ let new_state = result. unwrap ( ) ;
914
+
915
+ assert_eq ! ( expected_state, new_state) ;
916
+ }
862
917
}
0 commit comments