@@ -1831,7 +1831,7 @@ fn build_route_from_hops_internal<L: Deref>(
18311831#[ cfg( test) ]
18321832mod tests {
18331833 use routing:: network_graph:: { NetworkGraph , NetGraphMsgHandler , NodeId } ;
1834- use routing:: router:: { get_route, add_random_cltv_offset, default_node_features,
1834+ use routing:: router:: { get_route, build_route_from_hops_internal , add_random_cltv_offset, default_node_features,
18351835 PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RoutingFees ,
18361836 DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA , MAX_PATH_LENGTH_ESTIMATE } ;
18371837 use routing:: scoring:: { ChannelUsage , Score } ;
@@ -5529,6 +5529,26 @@ mod tests {
55295529 assert ! ( path_plausibility. iter( ) . all( |x| * x) ) ;
55305530 }
55315531
5532+ #[ test]
5533+ fn builds_correct_path_from_hops ( ) {
5534+ let ( secp_ctx, network, _, _, logger) = build_graph ( ) ;
5535+ let ( _, our_id, _, nodes) = get_nodes ( & secp_ctx) ;
5536+ let network_graph = network. read_only ( ) ;
5537+
5538+ let keys_manager = test_utils:: TestKeysInterface :: new ( & [ 0u8 ; 32 ] , Network :: Testnet ) ;
5539+ let random_seed_bytes = keys_manager. get_secure_random_bytes ( ) ;
5540+
5541+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] ) ;
5542+ let hops = [ nodes[ 1 ] , nodes[ 2 ] , nodes[ 4 ] , nodes[ 3 ] ] ;
5543+ let route = build_route_from_hops_internal ( & our_id, & hops, & payment_params,
5544+ & network_graph, 100 , 0 , Arc :: clone ( & logger) , & random_seed_bytes) . unwrap ( ) ;
5545+ let route_hop_pubkeys = route. paths [ 0 ] . iter ( ) . map ( |hop| hop. pubkey ) . collect :: < Vec < _ > > ( ) ;
5546+ assert_eq ! ( hops. len( ) , route. paths[ 0 ] . len( ) ) ;
5547+ for ( idx, hop_pubkey) in hops. iter ( ) . enumerate ( ) {
5548+ assert ! ( * hop_pubkey == route_hop_pubkeys[ idx] ) ;
5549+ }
5550+ }
5551+
55325552 #[ cfg( not( feature = "no-std" ) ) ]
55335553 pub ( super ) fn random_init_seed ( ) -> u64 {
55345554 // Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
0 commit comments