Skip to content

Commit 226c43c

Browse files
committed
Replace check_closed_event macro with a function
The `check_closed_event!()` macro has no reason to be a macro so here we move its logic to a function and leave the macro in place to avoid touching every line of code in the tests. This reduces the `--profile=test --lib` `Zpretty=expanded` code size from 309,522 LoC to 301,915 LoC.
1 parent 8bf5eda commit 226c43c

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::routing::router::{self, PaymentParameters, Route};
2020
use crate::ln::features::InitFeatures;
2121
use crate::ln::msgs;
2222
use crate::ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
23+
use crate::util::events::ClosureReason;
2324
use crate::util::enforcing_trait_impls::EnforcingSigner;
2425
use crate::util::scid_utils;
2526
use crate::util::test_utils;
@@ -1263,31 +1264,35 @@ macro_rules! check_closed_broadcast {
12631264
}
12641265

12651266
/// Check that a channel's closing channel events has been issued
1267+
pub fn check_closed_event(node: &Node, events_count: usize, expected_reason: ClosureReason, is_check_discard_funding: bool) {
1268+
let events = node.node.get_and_clear_pending_events();
1269+
assert_eq!(events.len(), events_count, "{:?}", events);
1270+
let mut issues_discard_funding = false;
1271+
for event in events {
1272+
match event {
1273+
Event::ChannelClosed { ref reason, .. } => {
1274+
assert_eq!(*reason, expected_reason);
1275+
},
1276+
Event::DiscardFunding { .. } => {
1277+
issues_discard_funding = true;
1278+
}
1279+
_ => panic!("Unexpected event"),
1280+
}
1281+
}
1282+
assert_eq!(is_check_discard_funding, issues_discard_funding);
1283+
}
1284+
1285+
/// Check that a channel's closing channel events has been issued
1286+
///
1287+
/// Don't use this, use the identically-named function instead.
12661288
#[macro_export]
12671289
macro_rules! check_closed_event {
12681290
($node: expr, $events: expr, $reason: expr) => {
12691291
check_closed_event!($node, $events, $reason, false);
12701292
};
1271-
($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {{
1272-
use $crate::util::events::Event;
1273-
1274-
let events = $node.node.get_and_clear_pending_events();
1275-
assert_eq!(events.len(), $events, "{:?}", events);
1276-
let expected_reason = $reason;
1277-
let mut issues_discard_funding = false;
1278-
for event in events {
1279-
match event {
1280-
Event::ChannelClosed { ref reason, .. } => {
1281-
assert_eq!(*reason, expected_reason);
1282-
},
1283-
Event::DiscardFunding { .. } => {
1284-
issues_discard_funding = true;
1285-
}
1286-
_ => panic!("Unexpected event"),
1287-
}
1288-
}
1289-
assert_eq!($is_check_discard_funding, issues_discard_funding);
1290-
}}
1293+
($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {
1294+
$crate::ln::functional_test_utils::check_closed_event(&$node, $events, $reason, $is_check_discard_funding);
1295+
}
12911296
}
12921297

12931298
pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: &Node<'a, 'b, 'c>, channel_id: &[u8; 32], funding_tx: Transaction, close_inbound_first: bool) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, Transaction) {

0 commit comments

Comments
 (0)