Skip to content

Commit 90e03f4

Browse files
committed
Split expect_payment_forwarded into a function called by macro
Also allowing us to pass the event manually.
1 parent e18481d commit 90e03f4

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

lightning/src/ln/functional_test_utils.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -1999,29 +1999,38 @@ macro_rules! expect_payment_path_successful {
19991999
}
20002000
}
20012001

2002+
pub fn expect_payment_forwarded<CM: AChannelManager, H: NodeHolder<CM=CM>>(
2003+
event: Event, node: &H, prev_node: &H, next_node: &H, expected_fee: Option<u64>,
2004+
upstream_force_closed: bool, downstream_force_closed: bool
2005+
) {
2006+
match event {
2007+
Event::PaymentForwarded {
2008+
fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
2009+
outbound_amount_forwarded_msat: _
2010+
} => {
2011+
assert_eq!(fee_earned_msat, expected_fee);
2012+
if !upstream_force_closed {
2013+
// Is the event prev_channel_id in one of the channels between the two nodes?
2014+
assert!(node.node().list_channels().iter().any(|x| x.counterparty.node_id == prev_node.node().get_our_node_id() && x.channel_id == prev_channel_id.unwrap()));
2015+
}
2016+
// We check for force closures since a force closed channel is removed from the
2017+
// node's channel list
2018+
if !downstream_force_closed {
2019+
assert!(node.node().list_channels().iter().any(|x| x.counterparty.node_id == next_node.node().get_our_node_id() && x.channel_id == next_channel_id.unwrap()));
2020+
}
2021+
assert_eq!(claim_from_onchain_tx, downstream_force_closed);
2022+
},
2023+
_ => panic!("Unexpected event"),
2024+
}
2025+
}
2026+
20022027
macro_rules! expect_payment_forwarded {
20032028
($node: expr, $prev_node: expr, $next_node: expr, $expected_fee: expr, $upstream_force_closed: expr, $downstream_force_closed: expr) => {
2004-
let events = $node.node.get_and_clear_pending_events();
2029+
let mut events = $node.node.get_and_clear_pending_events();
20052030
assert_eq!(events.len(), 1);
2006-
match events[0] {
2007-
Event::PaymentForwarded {
2008-
fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
2009-
outbound_amount_forwarded_msat: _
2010-
} => {
2011-
assert_eq!(fee_earned_msat, $expected_fee);
2012-
if !$upstream_force_closed {
2013-
// Is the event prev_channel_id in one of the channels between the two nodes?
2014-
assert!($node.node.list_channels().iter().any(|x| x.counterparty.node_id == $prev_node.node.get_our_node_id() && x.channel_id == prev_channel_id.unwrap()));
2015-
}
2016-
// We check for force closures since a force closed channel is removed from the
2017-
// node's channel list
2018-
if !$downstream_force_closed {
2019-
assert!($node.node.list_channels().iter().any(|x| x.counterparty.node_id == $next_node.node.get_our_node_id() && x.channel_id == next_channel_id.unwrap()));
2020-
}
2021-
assert_eq!(claim_from_onchain_tx, $downstream_force_closed);
2022-
},
2023-
_ => panic!("Unexpected event"),
2024-
}
2031+
$crate::ln::functional_test_utils::expect_payment_forwarded(
2032+
events.pop().unwrap(), &$node, &$prev_node, &$next_node, $expected_fee,
2033+
$upstream_force_closed, $downstream_force_closed);
20252034
}
20262035
}
20272036

@@ -2398,7 +2407,7 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, '
23982407
}
23992408
};
24002409
if $idx == 1 { fee += expected_extra_fees[i]; }
2401-
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
2410+
expect_payment_forwarded!(*$node, $next_node, $prev_node, Some(fee as u64), false, false);
24022411
expected_total_fee_msat += fee as u64;
24032412
check_added_monitors!($node, 1);
24042413
let new_next_msgs = if $new_msgs {

0 commit comments

Comments
 (0)