Skip to content

Commit 29c8614

Browse files
committed
Implement test for build_route_from_hops.
1 parent d03655f commit 29c8614

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
@@ -5492,6 +5492,26 @@ mod tests {
54925492
assert!(path_plausibility.iter().all(|x| *x));
54935493
}
54945494

5495+
#[test]
5496+
fn builds_correct_path_from_hops() {
5497+
let (secp_ctx, network, _, _, logger) = build_line_graph();
5498+
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
5499+
let network_graph = network.read_only();
5500+
5501+
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
5502+
let random_seed_bytes = keys_manager.get_secure_random_bytes();
5503+
5504+
let payment_params = PaymentParameters::from_node_id(nodes[18]);
5505+
let hops = &nodes[..19];
5506+
let route = build_route_from_hops_internal(&our_id, hops, &payment_params,
5507+
&network_graph, 100, 0, Arc::clone(&logger), &random_seed_bytes).unwrap();
5508+
let route_hop_pubkeys = route.paths[0].iter().map(|hop| hop.pubkey).collect::<Vec<_>>();
5509+
assert_eq!(hops.len(), route.paths[0].len());
5510+
for (idx, hop_pubkey) in hops.iter().enumerate() {
5511+
assert!(*hop_pubkey == route_hop_pubkeys[idx]);
5512+
}
5513+
}
5514+
54955515
#[cfg(not(feature = "no-std"))]
54965516
pub(super) fn random_init_seed() -> u64 {
54975517
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.

0 commit comments

Comments
 (0)