Merge pull request #1199 from valentinewallace/2021-11-phantom-node
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index b7d7011c93341e9b779fdbf4c4734db90e300caf..1d9e5afc46eecb7c66abac96528aa763a4030bbb 100644 (file)
@@ -1085,7 +1085,7 @@ macro_rules! get_route_and_payment_hash {
                let payment_params = $crate::routing::router::PaymentParameters::from_node_id($recv_node.node.get_our_node_id())
                        .with_features($crate::ln::features::InvoiceFeatures::known())
                        .with_route_hints($last_hops);
-               let scorer = $crate::util::test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = $crate::util::test_utils::TestScorer::with_penalty(0);
                let route = $crate::routing::router::get_route(
                        &$send_node.node.get_our_node_id(), &payment_params, $send_node.network_graph,
                        Some(&$send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
@@ -1102,7 +1102,7 @@ macro_rules! expect_pending_htlcs_forwardable_ignore {
                let events = $node.node.get_and_clear_pending_events();
                assert_eq!(events.len(), 1);
                match events[0] {
-                       Event::PendingHTLCsForwardable { .. } => { },
+                       $crate::util::events::Event::PendingHTLCsForwardable { .. } => { },
                        _ => panic!("Unexpected event"),
                };
        }}
@@ -1137,18 +1137,22 @@ macro_rules! expect_pending_htlcs_forwardable_from_events {
        }}
 }
 
-#[cfg(any(test, feature = "unstable"))]
+#[macro_export]
+#[cfg(any(test, feature = "_bench_unstable", feature = "_test_utils"))]
 macro_rules! expect_payment_received {
        ($node: expr, $expected_payment_hash: expr, $expected_payment_secret: expr, $expected_recv_value: expr) => {
+               expect_payment_received!($node, $expected_payment_hash, $expected_payment_secret, $expected_recv_value, None)
+       };
+       ($node: expr, $expected_payment_hash: expr, $expected_payment_secret: expr, $expected_recv_value: expr, $expected_payment_preimage: expr) => {
                let events = $node.node.get_and_clear_pending_events();
                assert_eq!(events.len(), 1);
                match events[0] {
-                       Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
+                       $crate::util::events::Event::PaymentReceived { ref payment_hash, ref purpose, amt } => {
                                assert_eq!($expected_payment_hash, *payment_hash);
                                assert_eq!($expected_recv_value, amt);
                                match purpose {
-                                       PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
-                                               assert!(payment_preimage.is_none());
+                                       $crate::util::events::PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
+                                               assert_eq!(&$expected_payment_preimage, payment_preimage);
                                                assert_eq!($expected_payment_secret, *payment_secret);
                                        },
                                        _ => {},
@@ -1540,7 +1544,7 @@ pub const TEST_FINAL_CLTV: u32 = 70;
 pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) {
        let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
                .with_features(InvoiceFeatures::known());
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = get_route(
                &origin_node.node.get_our_node_id(), &payment_params, &origin_node.network_graph,
                Some(&origin_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
@@ -1558,9 +1562,9 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
 pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64)  {
        let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
                .with_features(InvoiceFeatures::known());
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = get_route(
-               &origin_node.node.get_our_node_id(), &payment_params, origin_node.network_graph, 
+               &origin_node.node.get_our_node_id(), &payment_params, origin_node.network_graph,
                None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap();
        assert_eq!(route.paths.len(), 1);
        assert_eq!(route.paths[0].len(), expected_route.len());