Skip to content

Commit 0512260

Browse files
committed
Reduce macro contents in expect_pending_htlcs_forwardable* macros
The `expect_pending_htlcs_forwardable*` macros don't need to be macros so here we move much of the logic in them 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 301,915 LoC to 295,294 LoC.
1 parent 226c43c commit 0512260

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,22 +1394,11 @@ impl SendEvent {
13941394
}
13951395

13961396
#[macro_export]
1397+
/// Don't use this, use the identically-named function instead.
13971398
macro_rules! expect_pending_htlcs_forwardable_conditions {
1398-
($node: expr, $expected_failures: expr) => {{
1399-
let expected_failures = $expected_failures;
1400-
let events = $node.node.get_and_clear_pending_events();
1401-
match events[0] {
1402-
$crate::util::events::Event::PendingHTLCsForwardable { .. } => { },
1403-
_ => panic!("Unexpected event {:?}", events),
1404-
};
1405-
1406-
let count = expected_failures.len() + 1;
1407-
assert_eq!(events.len(), count);
1408-
1409-
if expected_failures.len() > 0 {
1410-
expect_htlc_handling_failed_destinations!(events, expected_failures)
1411-
}
1412-
}}
1399+
($node: expr, $expected_failures: expr) => {
1400+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions($node.node.get_and_clear_pending_events(), &$expected_failures);
1401+
}
14131402
}
14141403

14151404
#[macro_export]
@@ -1427,27 +1416,49 @@ macro_rules! expect_htlc_handling_failed_destinations {
14271416
}}
14281417
}
14291418

1419+
/// Checks that an [`Event::PendingHTLCsForwardable`] is available in the given events and, if
1420+
/// there are any [`Event::HTLCHandlingFailed`] events their [`HTLCDestination`] is included in the
1421+
/// `expected_failures` set.
1422+
pub fn expect_pending_htlcs_forwardable_conditions(events: Vec<Event>, expected_failures: &[HTLCDestination]) {
1423+
match events[0] {
1424+
Event::PendingHTLCsForwardable { .. } => { },
1425+
_ => panic!("Unexpected event {:?}", events),
1426+
};
1427+
1428+
let count = expected_failures.len() + 1;
1429+
assert_eq!(events.len(), count);
1430+
1431+
if expected_failures.len() > 0 {
1432+
expect_htlc_handling_failed_destinations!(events, expected_failures)
1433+
}
1434+
}
1435+
14301436
#[macro_export]
14311437
/// Clears (and ignores) a PendingHTLCsForwardable event
1438+
///
1439+
/// Don't use this, call [`expect_pending_htlcs_forwardable_conditions()`] with an empty failure
1440+
/// set instead.
14321441
macro_rules! expect_pending_htlcs_forwardable_ignore {
1433-
($node: expr) => {{
1434-
expect_pending_htlcs_forwardable_conditions!($node, vec![]);
1435-
}};
1442+
($node: expr) => {
1443+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions($node.node.get_and_clear_pending_events(), &[]);
1444+
}
14361445
}
14371446

14381447
#[macro_export]
14391448
/// Clears (and ignores) PendingHTLCsForwardable and HTLCHandlingFailed events
1449+
///
1450+
/// Don't use this, call [`expect_pending_htlcs_forwardable_conditions()`] instead.
14401451
macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore {
1441-
($node: expr, $expected_failures: expr) => {{
1442-
expect_pending_htlcs_forwardable_conditions!($node, $expected_failures);
1443-
}};
1452+
($node: expr, $expected_failures: expr) => {
1453+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions($node.node.get_and_clear_pending_events(), &$expected_failures);
1454+
}
14441455
}
14451456

14461457
#[macro_export]
14471458
/// Handles a PendingHTLCsForwardable event
14481459
macro_rules! expect_pending_htlcs_forwardable {
14491460
($node: expr) => {{
1450-
expect_pending_htlcs_forwardable_ignore!($node);
1461+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions($node.node.get_and_clear_pending_events(), &[]);
14511462
$node.node.process_pending_htlc_forwards();
14521463

14531464
// Ensure process_pending_htlc_forwards is idempotent.
@@ -1459,7 +1470,7 @@ macro_rules! expect_pending_htlcs_forwardable {
14591470
/// Handles a PendingHTLCsForwardable and HTLCHandlingFailed event
14601471
macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed {
14611472
($node: expr, $expected_failures: expr) => {{
1462-
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!($node, $expected_failures);
1473+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions($node.node.get_and_clear_pending_events(), &$expected_failures);
14631474
$node.node.process_pending_htlc_forwards();
14641475

14651476
// Ensure process_pending_htlc_forwards is idempotent.

0 commit comments

Comments
 (0)