Skip to content

Commit e7542c8

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

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
@@ -2005,29 +2005,38 @@ macro_rules! expect_payment_path_successful {
20052005
}
20062006
}
20072007

2008+
pub fn expect_payment_forwarded<CM: AChannelManager, H: NodeHolder<CM=CM>>(
2009+
event: Event, node: &H, prev_node: &H, next_node: &H, expected_fee: Option<u64>,
2010+
upstream_force_closed: bool, downstream_force_closed: bool
2011+
) {
2012+
match event {
2013+
Event::PaymentForwarded {
2014+
fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
2015+
outbound_amount_forwarded_msat: _
2016+
} => {
2017+
assert_eq!(fee_earned_msat, expected_fee);
2018+
if !upstream_force_closed {
2019+
// Is the event prev_channel_id in one of the channels between the two nodes?
2020+
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()));
2021+
}
2022+
// We check for force closures since a force closed channel is removed from the
2023+
// node's channel list
2024+
if !downstream_force_closed {
2025+
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()));
2026+
}
2027+
assert_eq!(claim_from_onchain_tx, downstream_force_closed);
2028+
},
2029+
_ => panic!("Unexpected event"),
2030+
}
2031+
}
2032+
20082033
macro_rules! expect_payment_forwarded {
20092034
($node: expr, $prev_node: expr, $next_node: expr, $expected_fee: expr, $upstream_force_closed: expr, $downstream_force_closed: expr) => {
2010-
let events = $node.node.get_and_clear_pending_events();
2035+
let mut events = $node.node.get_and_clear_pending_events();
20112036
assert_eq!(events.len(), 1);
2012-
match events[0] {
2013-
Event::PaymentForwarded {
2014-
fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
2015-
outbound_amount_forwarded_msat: _
2016-
} => {
2017-
assert_eq!(fee_earned_msat, $expected_fee);
2018-
if !$upstream_force_closed {
2019-
// Is the event prev_channel_id in one of the channels between the two nodes?
2020-
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()));
2021-
}
2022-
// We check for force closures since a force closed channel is removed from the
2023-
// node's channel list
2024-
if !$downstream_force_closed {
2025-
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()));
2026-
}
2027-
assert_eq!(claim_from_onchain_tx, $downstream_force_closed);
2028-
},
2029-
_ => panic!("Unexpected event"),
2030-
}
2037+
$crate::ln::functional_test_utils::expect_payment_forwarded(
2038+
events.pop().unwrap(), &$node, &$prev_node, &$next_node, $expected_fee,
2039+
$upstream_force_closed, $downstream_force_closed);
20312040
}
20322041
}
20332042

@@ -2404,7 +2413,7 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, '
24042413
}
24052414
};
24062415
if $idx == 1 { fee += expected_extra_fees[i]; }
2407-
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
2416+
expect_payment_forwarded!(*$node, $next_node, $prev_node, Some(fee as u64), false, false);
24082417
expected_total_fee_msat += fee as u64;
24092418
check_added_monitors!($node, 1);
24102419
let new_next_msgs = if $new_msgs {

0 commit comments

Comments
 (0)