Skip to content

Commit 0c5ab2a

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 304,969 LoC to 297,403 LoC.
1 parent 2b79c42 commit 0c5ab2a

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 23 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;
@@ -1238,32 +1239,34 @@ macro_rules! check_closed_broadcast {
12381239
}
12391240
}
12401241

1242+
/// Check that a channel's closing channel events has been issued
1243+
pub fn check_closed_event(node: &Node, events_count: usize, expected_reason: ClosureReason, is_check_discard_funding: bool) {
1244+
let events = node.node.get_and_clear_pending_events();
1245+
assert_eq!(events.len(), events_count, "{:?}", events);
1246+
let mut issues_discard_funding = false;
1247+
for event in events {
1248+
match event {
1249+
Event::ChannelClosed { ref reason, .. } => {
1250+
assert_eq!(*reason, expected_reason);
1251+
},
1252+
Event::DiscardFunding { .. } => {
1253+
issues_discard_funding = true;
1254+
}
1255+
_ => panic!("Unexpected event"),
1256+
}
1257+
}
1258+
assert_eq!(is_check_discard_funding, issues_discard_funding);
1259+
}
1260+
12411261
/// Check that a channel's closing channel events has been issued
12421262
#[macro_export]
12431263
macro_rules! check_closed_event {
12441264
($node: expr, $events: expr, $reason: expr) => {
12451265
check_closed_event!($node, $events, $reason, false);
12461266
};
1247-
($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {{
1248-
use $crate::util::events::Event;
1249-
1250-
let events = $node.node.get_and_clear_pending_events();
1251-
assert_eq!(events.len(), $events, "{:?}", events);
1252-
let expected_reason = $reason;
1253-
let mut issues_discard_funding = false;
1254-
for event in events {
1255-
match event {
1256-
Event::ChannelClosed { ref reason, .. } => {
1257-
assert_eq!(*reason, expected_reason);
1258-
},
1259-
Event::DiscardFunding { .. } => {
1260-
issues_discard_funding = true;
1261-
}
1262-
_ => panic!("Unexpected event"),
1263-
}
1264-
}
1265-
assert_eq!($is_check_discard_funding, issues_discard_funding);
1266-
}}
1267+
($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {
1268+
$crate::ln::functional_test_utils::check_closed_event(&$node, $events, $reason, $is_check_discard_funding);
1269+
}
12671270
}
12681271

12691272
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)