Skip to content

Commit b12c6f7

Browse files
committed
Implement test for build_route_from_hops.
1 parent a8cf7a5 commit b12c6f7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5530,6 +5530,26 @@ mod tests {
55305530
assert!(path_plausibility.iter().all(|x| *x));
55315531
}
55325532

5533+
#[test]
5534+
fn builds_correct_path_from_hops() {
5535+
let (secp_ctx, network, _, _, logger) = build_line_graph();
5536+
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
5537+
let network_graph = network.read_only();
5538+
5539+
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
5540+
let random_seed_bytes = keys_manager.get_secure_random_bytes();
5541+
5542+
let payment_params = PaymentParameters::from_node_id(nodes[18]);
5543+
let hops = &nodes[..19];
5544+
let route = build_route_from_hops_internal(&our_id, hops, &payment_params,
5545+
&network_graph, 100, 0, Arc::clone(&logger), &random_seed_bytes).unwrap();
5546+
let route_hop_pubkeys = route.paths[0].iter().map(|hop| hop.pubkey).collect::<Vec<_>>();
5547+
assert_eq!(hops.len(), route.paths[0].len());
5548+
for (idx, hop_pubkey) in hops.iter().enumerate() {
5549+
assert!(*hop_pubkey == route_hop_pubkeys[idx]);
5550+
}
5551+
}
5552+
55335553
#[cfg(not(feature = "no-std"))]
55345554
pub(super) fn random_init_seed() -> u64 {
55355555
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.

0 commit comments

Comments
 (0)