@@ -62,6 +62,7 @@ pub fn setup_network_node(
6262
6363 let peer_manager = PeerManagerActor :: create ( move |ctx| {
6464 let mut client_config = ClientConfig :: test ( false , 100 , 200 , num_validators, false ) ;
65+ client_config. archive = config. archive ;
6566 client_config. ttl_account_id_router = config. ttl_account_id_router ;
6667 let network_adapter = NetworkRecipient :: new ( ) ;
6768 network_adapter. set_recipient ( ctx. address ( ) . recipient ( ) ) ;
@@ -363,6 +364,7 @@ struct TestConfig {
363364 ideal_connections : Option < ( u32 , u32 ) > ,
364365 minimum_outbound_peers : Option < u32 > ,
365366 safe_set_size : Option < u32 > ,
367+ archive : bool ,
366368}
367369
368370impl TestConfig {
@@ -377,6 +379,7 @@ impl TestConfig {
377379 ideal_connections : None ,
378380 minimum_outbound_peers : None ,
379381 safe_set_size : None ,
382+ archive : false ,
380383 }
381384 }
382385}
@@ -425,6 +428,12 @@ impl Runner {
425428 self
426429 }
427430
431+ /// Set node `u` as archival node.
432+ pub fn set_as_archival ( mut self , u : usize ) -> Self {
433+ self . test_config [ u] . archive = true ;
434+ self
435+ }
436+
428437 /// Specify boot nodes. By default there are no boot nodes.
429438 pub fn use_boot_nodes ( mut self , boot_nodes : Vec < usize > ) -> Self {
430439 self . apply_all ( move |test_config| {
@@ -453,7 +462,7 @@ impl Runner {
453462
454463 pub fn safe_set_size ( mut self , safe_set_size : u32 ) -> Self {
455464 self . apply_all ( move |test_config| {
456- test_config. minimum_outbound_peers = Some ( safe_set_size) ;
465+ test_config. safe_set_size = Some ( safe_set_size) ;
457466 } ) ;
458467 self
459468 }
@@ -539,6 +548,7 @@ impl Runner {
539548 network_config. blacklist = blacklist;
540549 network_config. outbound_disabled = test_config. outbound_disabled ;
541550 network_config. boot_nodes = boot_nodes;
551+ network_config. archive = test_config. archive ;
542552
543553 network_config. ideal_connections_lo =
544554 test_config. ideal_connections . map_or ( network_config. ideal_connections_lo , |( lo, _) | lo) ;
@@ -665,8 +675,14 @@ impl Handler<RunnerMessage> for Runner {
665675 }
666676}
667677
668- /// Check that `node_id` has at least `expected_connections` as active peers.
669- pub fn check_expected_connections ( node_id : usize , expected_connections : usize ) -> ActionFn {
678+ /// Check that the number of connections of `node_id` is in the range:
679+ /// [expected_connections_lo, expected_connections_hi]
680+ /// Use None to denote semi-open interval
681+ pub fn check_expected_connections (
682+ node_id : usize ,
683+ expected_connections_lo : Option < usize > ,
684+ expected_connections_hi : Option < usize > ,
685+ ) -> ActionFn {
670686 Box :: new (
671687 move |info : SharedRunningInfo ,
672688 flag : Arc < AtomicBool > ,
@@ -681,7 +697,19 @@ pub fn check_expected_connections(node_id: usize, expected_connections: usize) -
681697 . send ( GetInfo { } )
682698 . map_err ( |_| ( ) )
683699 . and_then ( move |res| {
684- if res. num_active_peers >= expected_connections {
700+ let left = if let Some ( expected_connections_lo) = expected_connections_lo {
701+ expected_connections_lo <= res. num_active_peers
702+ } else {
703+ true
704+ } ;
705+
706+ let right = if let Some ( expected_connections_hi) = expected_connections_hi {
707+ res. num_active_peers <= expected_connections_hi
708+ } else {
709+ true
710+ } ;
711+
712+ if left && right {
685713 flag. store ( true , Ordering :: Relaxed ) ;
686714 }
687715 future:: ok ( ( ) )
@@ -692,6 +720,39 @@ pub fn check_expected_connections(node_id: usize, expected_connections: usize) -
692720 )
693721}
694722
723+ /// Check that `node_id` has a direct connection to `target_id`.
724+ pub fn check_direct_connection ( node_id : usize , target_id : usize ) -> ActionFn {
725+ Box :: new (
726+ move |info : SharedRunningInfo ,
727+ flag : Arc < AtomicBool > ,
728+ _ctx : & mut Context < WaitOrTimeout > ,
729+ _runner| {
730+ let info = info. read ( ) . unwrap ( ) ;
731+ let target_peer_id = info. peers_info [ target_id] . id . clone ( ) ;
732+
733+ actix:: spawn (
734+ info. pm_addr
735+ . get ( node_id)
736+ . unwrap ( )
737+ . send ( NetworkRequests :: FetchRoutingTable )
738+ . map_err ( |_| ( ) )
739+ . and_then ( move |res| {
740+ if let NetworkResponses :: RoutingTableInfo ( routing_table) = res {
741+ if let Some ( routes) = routing_table. peer_forwarding . get ( & target_peer_id)
742+ {
743+ if routes. contains ( & target_peer_id) {
744+ flag. store ( true , Ordering :: Relaxed ) ;
745+ }
746+ }
747+ }
748+ future:: ok ( ( ) )
749+ } )
750+ . map ( drop) ,
751+ ) ;
752+ } ,
753+ )
754+ }
755+
695756/// Restart a node that was already stopped.
696757pub fn restart ( node_id : usize ) -> ActionFn {
697758 Box :: new (
0 commit comments