Skip to content

Commit 8bf5eda

Browse files
committed
Replace check_closed_broadcast macro with a function
The `check_closed_broadcast!()` 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 313,312 LoC to 309,522 LoC.
1 parent 871aec2 commit 8bf5eda

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,30 +1231,35 @@ macro_rules! check_warn_msg {
12311231

12321232
/// Check that a channel's closing channel update has been broadcasted, and optionally
12331233
/// check whether an error message event has occurred.
1234-
#[macro_export]
1235-
macro_rules! check_closed_broadcast {
1236-
($node: expr, $with_error_msg: expr) => {{
1237-
use $crate::util::events::MessageSendEvent;
1238-
use $crate::ln::msgs::ErrorAction;
1239-
1240-
let msg_events = $node.node.get_and_clear_pending_msg_events();
1241-
assert_eq!(msg_events.len(), if $with_error_msg { 2 } else { 1 });
1242-
match msg_events[0] {
1243-
MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
1244-
assert_eq!(msg.contents.flags & 2, 2);
1234+
pub fn check_closed_broadcast(node: &Node, with_error_msg: bool) -> Option<msgs::ErrorMessage> {
1235+
let msg_events = node.node.get_and_clear_pending_msg_events();
1236+
assert_eq!(msg_events.len(), if with_error_msg { 2 } else { 1 });
1237+
match msg_events[0] {
1238+
MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
1239+
assert_eq!(msg.contents.flags & 2, 2);
1240+
},
1241+
_ => panic!("Unexpected event"),
1242+
}
1243+
if with_error_msg {
1244+
match msg_events[1] {
1245+
MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
1246+
// TODO: Check node_id
1247+
Some(msg.clone())
12451248
},
12461249
_ => panic!("Unexpected event"),
12471250
}
1248-
if $with_error_msg {
1249-
match msg_events[1] {
1250-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
1251-
// TODO: Check node_id
1252-
Some(msg.clone())
1253-
},
1254-
_ => panic!("Unexpected event"),
1255-
}
1256-
} else { None }
1257-
}}
1251+
} else { None }
1252+
}
1253+
1254+
/// Check that a channel's closing channel update has been broadcasted, and optionally
1255+
/// check whether an error message event has occurred.
1256+
///
1257+
/// Don't use this, use the identically-named function instead.
1258+
#[macro_export]
1259+
macro_rules! check_closed_broadcast {
1260+
($node: expr, $with_error_msg: expr) => {
1261+
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, $with_error_msg)
1262+
}
12581263
}
12591264

12601265
/// Check that a channel's closing channel events has been issued

0 commit comments

Comments
 (0)