Skip to content

Commit 8e21ce2

Browse files
committed
Improve tests
More cleanup
1 parent 5443a86 commit 8e21ce2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use core::cell::RefCell;
4646
use alloc::rc::Rc;
4747
use sync::{Arc, Mutex};
4848
use core::mem;
49+
use std::iter;
4950

5051
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
5152

@@ -1275,8 +1276,8 @@ impl HTLCHandlingFailedConditions {
12751276
self
12761277
}
12771278

1278-
pub fn htlc_processing_failed_with_count_and_reasons(mut self, count: u32, reasons: Vec<HTLCDestination>) -> Self {
1279-
self.expected_htlc_processing_failed = Some(count);
1279+
pub fn htlc_processing_failed_with_reasons(mut self, reasons: Vec<HTLCDestination>) -> Self {
1280+
self.expected_htlc_processing_failed = Some(reasons.len() as u32);
12801281
self.expected_destinations = Some(reasons);
12811282
self
12821283
}
@@ -1354,8 +1355,6 @@ macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed {
13541355
#[cfg(test)]
13551356
macro_rules! expect_pending_htlcs_forwardable_from_events {
13561357
($node: expr, $events: expr, $ignore: expr) => {{
1357-
// We need to clear pending events since there may possibly be `PaymentForwardingFailed` events here
1358-
$node.node.get_and_clear_pending_events();
13591358
assert_eq!($events.len(), 1);
13601359
match $events[0] {
13611360
Event::PendingHTLCsForwardable { .. } => { },
@@ -1887,7 +1886,8 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
18871886
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
18881887
}
18891888
expected_paths[0].last().unwrap().node.fail_htlc_backwards(&our_payment_hash);
1890-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(expected_paths[0].last().unwrap(), HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(expected_paths.len() as u32, vec![HTLCDestination::FailedPayment { payment_hash: our_payment_hash }]));
1889+
let expected_destinations: Vec<HTLCDestination> = iter::repeat(HTLCDestination::FailedPayment { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
1890+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(expected_paths[0].last().unwrap(), HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()));
18911891

18921892
pass_failed_payment_back(origin_node, expected_paths, skip_last, our_payment_hash);
18931893
}

lightning/src/ln/functional_tests.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5585,7 +5585,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
55855585
HTLCDestination::FailedPayment { payment_hash: payment_hash_5 },
55865586
HTLCDestination::FailedPayment { payment_hash: payment_hash_6 },
55875587
];
5588-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[4], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(failed_destinations.len() as u32, failed_destinations.clone()));
5588+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[4], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations.clone()));
55895589
check_added_monitors!(nodes[4], 1);
55905590

55915591
let four_removes = get_htlc_update_msgs!(nodes[4], nodes[3].node.get_our_node_id());
@@ -5604,7 +5604,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
56045604
HTLCDestination::FailedPayment { payment_hash: payment_hash_2 },
56055605
HTLCDestination::FailedPayment { payment_hash: payment_hash_4 },
56065606
];
5607-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[5], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(failed_destinations_2.len() as u32, failed_destinations_2.clone()));
5607+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[5], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations_2.clone()));
56085608
check_added_monitors!(nodes[5], 1);
56095609

56105610
let two_removes = get_htlc_update_msgs!(nodes[5], nodes[3].node.get_our_node_id());
@@ -5623,7 +5623,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
56235623
HTLCDestination::NextHopChannel { node_id: Some(nodes[5].node.get_our_node_id()), channel_id: chan_3_5.2 },
56245624
HTLCDestination::NextHopChannel { node_id: Some(nodes[5].node.get_our_node_id()), channel_id: chan_3_5.2 },
56255625
];
5626-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(failed_destinations_3.len() as u32, failed_destinations_3.clone()));
5626+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations_3.clone()));
56275627
check_added_monitors!(nodes[3], 1);
56285628
let six_removes = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id());
56295629
nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[0]);
@@ -5673,14 +5673,17 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
56735673
check_closed_broadcast!(nodes[2], true);
56745674
if deliver_last_raa {
56755675
expect_pending_htlcs_forwardable_from_events!(nodes[2], events[0..1], true);
5676+
5677+
let expected_destinations: Vec<HTLCDestination> = iter::repeat(HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }).take(3).collect();
5678+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()))
56765679
} else {
56775680
let expected_destinations: Vec<HTLCDestination> = if announce_latest {
56785681
iter::repeat(HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }).take(9).collect()
56795682
} else {
56805683
iter::repeat(HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }).take(6).collect()
56815684
};
56825685

5683-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(expected_destinations.len() as u32, expected_destinations.clone()));
5686+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()));
56845687
}
56855688
check_added_monitors!(nodes[2], 3);
56865689

@@ -9795,7 +9798,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) {
97959798
HTLCDestination::FailedPayment { payment_hash: our_payment_hash },
97969799
HTLCDestination::FailedPayment { payment_hash: our_payment_hash },
97979800
];
9798-
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(expected_destinations.len() as u32, expected_destinations.clone()));
9801+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()));
97999802
nodes[1].node.process_pending_htlc_forwards();
98009803

98019804
check_added_monitors!(nodes[1], 1);
@@ -10042,7 +10045,7 @@ fn test_double_partial_claim() {
1004210045
HTLCDestination::FailedPayment { payment_hash },
1004310046
HTLCDestination::FailedPayment { payment_hash },
1004410047
];
10045-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_count_and_reasons(failed_destinations.len() as u32, failed_destinations.clone()));
10048+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations.clone()));
1004610049

1004710050
pass_failed_payment_back(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_hash);
1004810051

0 commit comments

Comments
 (0)