Skip to content

Commit 2b79c42

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 308,798 LoC to 304,969 LoC.
1 parent 58648bc commit 2b79c42

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,30 +1209,33 @@ macro_rules! check_warn_msg {
12091209

12101210
/// Check that a channel's closing channel update has been broadcasted, and optionally
12111211
/// check whether an error message event has occurred.
1212-
#[macro_export]
1213-
macro_rules! check_closed_broadcast {
1214-
($node: expr, $with_error_msg: expr) => {{
1215-
use $crate::util::events::MessageSendEvent;
1216-
use $crate::ln::msgs::ErrorAction;
1217-
1218-
let msg_events = $node.node.get_and_clear_pending_msg_events();
1219-
assert_eq!(msg_events.len(), if $with_error_msg { 2 } else { 1 });
1220-
match msg_events[0] {
1221-
MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
1222-
assert_eq!(msg.contents.flags & 2, 2);
1212+
pub fn check_closed_broadcast(node: &Node, with_error_msg: bool) -> Option<msgs::ErrorMessage> {
1213+
let msg_events = node.node.get_and_clear_pending_msg_events();
1214+
assert_eq!(msg_events.len(), if with_error_msg { 2 } else { 1 });
1215+
match msg_events[0] {
1216+
MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
1217+
assert_eq!(msg.contents.flags & 2, 2);
1218+
},
1219+
_ => panic!("Unexpected event"),
1220+
}
1221+
if with_error_msg {
1222+
match msg_events[1] {
1223+
MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
1224+
// TODO: Check node_id
1225+
Some(msg.clone())
12231226
},
12241227
_ => panic!("Unexpected event"),
12251228
}
1226-
if $with_error_msg {
1227-
match msg_events[1] {
1228-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
1229-
// TODO: Check node_id
1230-
Some(msg.clone())
1231-
},
1232-
_ => panic!("Unexpected event"),
1233-
}
1234-
} else { None }
1235-
}}
1229+
} else { None }
1230+
}
1231+
1232+
/// Check that a channel's closing channel update has been broadcasted, and optionally
1233+
/// 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+
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, $with_error_msg)
1238+
}
12361239
}
12371240

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

0 commit comments

Comments
 (0)