Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
More cleanup
  • Loading branch information
jurvis committed Jul 15, 2022
1 parent 5443a86 commit 8e21ce2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lightning/src/ln/functional_test_utils.rs
Expand Up @@ -46,6 +46,7 @@ use core::cell::RefCell;
use alloc::rc::Rc;
use sync::{Arc, Mutex};
use core::mem;
use std::iter;

pub const CHAN_CONFIRM_DEPTH: u32 = 10;

Expand Down Expand Up @@ -1275,8 +1276,8 @@ impl HTLCHandlingFailedConditions {
self
}

pub fn htlc_processing_failed_with_count_and_reasons(mut self, count: u32, reasons: Vec<HTLCDestination>) -> Self {
self.expected_htlc_processing_failed = Some(count);
pub fn htlc_processing_failed_with_reasons(mut self, reasons: Vec<HTLCDestination>) -> Self {
self.expected_htlc_processing_failed = Some(reasons.len() as u32);
self.expected_destinations = Some(reasons);
self
}
Expand Down Expand Up @@ -1354,8 +1355,6 @@ macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed {
#[cfg(test)]
macro_rules! expect_pending_htlcs_forwardable_from_events {
($node: expr, $events: expr, $ignore: expr) => {{
// We need to clear pending events since there may possibly be `PaymentForwardingFailed` events here
$node.node.get_and_clear_pending_events();
assert_eq!($events.len(), 1);
match $events[0] {
Event::PendingHTLCsForwardable { .. } => { },
Expand Down Expand Up @@ -1887,7 +1886,8 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
}
expected_paths[0].last().unwrap().node.fail_htlc_backwards(&our_payment_hash);
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 }]));
let expected_destinations: Vec<HTLCDestination> = iter::repeat(HTLCDestination::FailedPayment { payment_hash: our_payment_hash }).take(expected_paths.len()).collect();
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(expected_paths[0].last().unwrap(), HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()));

pass_failed_payment_back(origin_node, expected_paths, skip_last, our_payment_hash);
}
Expand Down
15 changes: 9 additions & 6 deletions lightning/src/ln/functional_tests.rs
Expand Up @@ -5585,7 +5585,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
HTLCDestination::FailedPayment { payment_hash: payment_hash_5 },
HTLCDestination::FailedPayment { payment_hash: payment_hash_6 },
];
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()));
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[4], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations.clone()));
check_added_monitors!(nodes[4], 1);

let four_removes = get_htlc_update_msgs!(nodes[4], nodes[3].node.get_our_node_id());
Expand All @@ -5604,7 +5604,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
HTLCDestination::FailedPayment { payment_hash: payment_hash_2 },
HTLCDestination::FailedPayment { payment_hash: payment_hash_4 },
];
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()));
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[5], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations_2.clone()));
check_added_monitors!(nodes[5], 1);

let two_removes = get_htlc_update_msgs!(nodes[5], nodes[3].node.get_our_node_id());
Expand All @@ -5623,7 +5623,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
HTLCDestination::NextHopChannel { node_id: Some(nodes[5].node.get_our_node_id()), channel_id: chan_3_5.2 },
HTLCDestination::NextHopChannel { node_id: Some(nodes[5].node.get_our_node_id()), channel_id: chan_3_5.2 },
];
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()));
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations_3.clone()));
check_added_monitors!(nodes[3], 1);
let six_removes = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id());
nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[0]);
Expand Down Expand Up @@ -5673,14 +5673,17 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
check_closed_broadcast!(nodes[2], true);
if deliver_last_raa {
expect_pending_htlcs_forwardable_from_events!(nodes[2], events[0..1], true);

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();
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()))
} else {
let expected_destinations: Vec<HTLCDestination> = if announce_latest {
iter::repeat(HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }).take(9).collect()
} else {
iter::repeat(HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }).take(6).collect()
};

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()));
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()));
}
check_added_monitors!(nodes[2], 3);

Expand Down Expand Up @@ -9795,7 +9798,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) {
HTLCDestination::FailedPayment { payment_hash: our_payment_hash },
HTLCDestination::FailedPayment { payment_hash: our_payment_hash },
];
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()));
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(expected_destinations.clone()));
nodes[1].node.process_pending_htlc_forwards();

check_added_monitors!(nodes[1], 1);
Expand Down Expand Up @@ -10042,7 +10045,7 @@ fn test_double_partial_claim() {
HTLCDestination::FailedPayment { payment_hash },
HTLCDestination::FailedPayment { payment_hash },
];
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()));
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], HTLCHandlingFailedConditions::new().htlc_processing_failed_with_reasons(failed_destinations.clone()));

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

Expand Down

0 comments on commit 8e21ce2

Please sign in to comment.