Skip to content

Commit 0558c31

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 297,403 LoC to 290,689 LoC.
1 parent 0c5ab2a commit 0558c31

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,21 +1369,9 @@ impl SendEvent {
13691369

13701370
#[macro_export]
13711371
macro_rules! expect_pending_htlcs_forwardable_conditions {
1372-
($node: expr, $expected_failures: expr) => {{
1373-
let expected_failures = $expected_failures;
1374-
let events = $node.node.get_and_clear_pending_events();
1375-
match events[0] {
1376-
$crate::util::events::Event::PendingHTLCsForwardable { .. } => { },
1377-
_ => panic!("Unexpected event {:?}", events),
1378-
};
1379-
1380-
let count = expected_failures.len() + 1;
1381-
assert_eq!(events.len(), count);
1382-
1383-
if expected_failures.len() > 0 {
1384-
expect_htlc_handling_failed_destinations!(events, expected_failures)
1385-
}
1386-
}}
1372+
($node: expr, $expected_failures: expr) => {
1373+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions(&$node, &$expected_failures);
1374+
}
13871375
}
13881376

13891377
#[macro_export]
@@ -1401,27 +1389,42 @@ macro_rules! expect_htlc_handling_failed_destinations {
14011389
}}
14021390
}
14031391

1392+
pub fn expect_pending_htlcs_forwardable_conditions(node: &Node, expected_failures: &[HTLCDestination]) {
1393+
let events = node.node.get_and_clear_pending_events();
1394+
match events[0] {
1395+
Event::PendingHTLCsForwardable { .. } => { },
1396+
_ => panic!("Unexpected event {:?}", events),
1397+
};
1398+
1399+
let count = expected_failures.len() + 1;
1400+
assert_eq!(events.len(), count);
1401+
1402+
if expected_failures.len() > 0 {
1403+
expect_htlc_handling_failed_destinations!(events, expected_failures)
1404+
}
1405+
}
1406+
14041407
#[macro_export]
14051408
/// Clears (and ignores) a PendingHTLCsForwardable event
14061409
macro_rules! expect_pending_htlcs_forwardable_ignore {
1407-
($node: expr) => {{
1408-
expect_pending_htlcs_forwardable_conditions!($node, vec![]);
1409-
}};
1410+
($node: expr) => {
1411+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions(&$node, &[]);
1412+
}
14101413
}
14111414

14121415
#[macro_export]
14131416
/// Clears (and ignores) PendingHTLCsForwardable and HTLCHandlingFailed events
14141417
macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore {
1415-
($node: expr, $expected_failures: expr) => {{
1416-
expect_pending_htlcs_forwardable_conditions!($node, $expected_failures);
1417-
}};
1418+
($node: expr, $expected_failures: expr) => {
1419+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions(&$node, &$expected_failures);
1420+
}
14181421
}
14191422

14201423
#[macro_export]
14211424
/// Handles a PendingHTLCsForwardable event
14221425
macro_rules! expect_pending_htlcs_forwardable {
14231426
($node: expr) => {{
1424-
expect_pending_htlcs_forwardable_ignore!($node);
1427+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions(&$node, &[]);
14251428
$node.node.process_pending_htlc_forwards();
14261429

14271430
// Ensure process_pending_htlc_forwards is idempotent.
@@ -1433,7 +1436,7 @@ macro_rules! expect_pending_htlcs_forwardable {
14331436
/// Handles a PendingHTLCsForwardable and HTLCHandlingFailed event
14341437
macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed {
14351438
($node: expr, $expected_failures: expr) => {{
1436-
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!($node, $expected_failures);
1439+
$crate::ln::functional_test_utils::expect_pending_htlcs_forwardable_conditions(&$node, &$expected_failures);
14371440
$node.node.process_pending_htlc_forwards();
14381441

14391442
// Ensure process_pending_htlc_forwards is idempotent.

0 commit comments

Comments
 (0)