From dceca5b590dd34370e365307ed8517db5d04440e Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 5 Aug 2022 17:45:43 -0400 Subject: [PATCH] OM functional tests: update util to take nodes by reference And fix one test to be uniform with the others --- .../src/onion_message/functional_tests.rs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index 695064e46..f3026270f 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -47,10 +47,10 @@ fn create_nodes(num_messengers: u8) -> Vec { res } -fn pass_along_path(mut path: Vec, expected_path_id: Option<[u8; 32]>) { - let mut prev_node = path.remove(0); +fn pass_along_path(path: &Vec, expected_path_id: Option<[u8; 32]>) { + let mut prev_node = &path[0]; let num_nodes = path.len(); - for (idx, node) in path.into_iter().enumerate() { + for (idx, node) in path.into_iter().skip(1).enumerate() { let events = prev_node.messenger.release_pending_msgs(); assert_eq!(events.len(), 1); let onion_msg = { @@ -73,7 +73,7 @@ fn one_hop() { let nodes = create_nodes(2); nodes[0].messenger.send_onion_message(&[], Destination::Node(nodes[1].get_node_pk())).unwrap(); - pass_along_path(nodes, None); + pass_along_path(&nodes, None); } #[test] @@ -81,7 +81,7 @@ fn two_unblinded_hops() { let nodes = create_nodes(3); nodes[0].messenger.send_onion_message(&[nodes[1].get_node_pk()], Destination::Node(nodes[2].get_node_pk())).unwrap(); - pass_along_path(nodes, None); + pass_along_path(&nodes, None); } #[test] @@ -92,7 +92,7 @@ fn two_unblinded_two_blinded() { let blinded_route = BlindedRoute::new::(&[nodes[3].get_node_pk(), nodes[4].get_node_pk()], &*nodes[4].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], Destination::BlindedRoute(blinded_route)).unwrap(); - pass_along_path(nodes, None); + pass_along_path(&nodes, None); } #[test] @@ -103,7 +103,7 @@ fn three_blinded_hops() { let blinded_route = BlindedRoute::new::(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap(); - pass_along_path(nodes, None); + pass_along_path(&nodes, None); } #[test] @@ -124,19 +124,18 @@ fn too_big_packet_error() { fn invalid_blinded_route_error() { // Make sure we error as expected if a provided blinded route has 0 or 1 hops. let mut nodes = create_nodes(3); - let (node1, node2, node3) = (nodes.remove(0), nodes.remove(0), nodes.remove(0)); // 0 hops let secp_ctx = Secp256k1::new(); - let mut blinded_route = BlindedRoute::new::(&[node2.get_node_pk(), node3.get_node_pk()], &*node3.keys_manager, &secp_ctx).unwrap(); + let mut blinded_route = BlindedRoute::new::(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); blinded_route.blinded_hops.clear(); - let err = node1.messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap_err(); + let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap_err(); assert_eq!(err, SendError::TooFewBlindedHops); // 1 hop - let mut blinded_route = BlindedRoute::new::(&[node2.get_node_pk(), node3.get_node_pk()], &*node3.keys_manager, &secp_ctx).unwrap(); + let mut blinded_route = BlindedRoute::new::(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); blinded_route.blinded_hops.remove(0); assert_eq!(blinded_route.blinded_hops.len(), 1); - let err = node1.messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap_err(); + let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap_err(); assert_eq!(err, SendError::TooFewBlindedHops); } -- 2.39.5