Skip to content

Commit e96fe1c

Browse files
committed
Return path events from expect_payment_sent
Prepare for inspecting hold times in PaymentPathSuccessful.
1 parent 04e9e5e commit e96fe1c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn async_receive_flow_success() {
445445
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev)
446446
.with_payment_preimage(keysend_preimage);
447447
do_pass_along_path(args);
448-
let res =
448+
let (res, _) =
449449
claim_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], route, keysend_preimage));
450450
assert!(res.is_some());
451451
assert_eq!(res, Some(PaidBolt12Invoice::StaticInvoice(static_invoice)));

lightning/src/ln/functional_test_utils.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,11 +2839,13 @@ macro_rules! expect_payment_claimed {
28392839
};
28402840
}
28412841

2842+
/// Inspect events to assert that a payment was sent. If this was a BOLT 12 payment, the BOLT 12 invoice is returned. If
2843+
/// per-path claims are expected, the events for each path are returned as well.
28422844
pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28432845
node: &H, expected_payment_preimage: PaymentPreimage,
28442846
expected_fee_msat_opt: Option<Option<u64>>, expect_per_path_claims: bool,
28452847
expect_post_ev_mon_update: bool,
2846-
) -> Option<PaidBolt12Invoice> {
2848+
) -> (Option<PaidBolt12Invoice>, Vec<Event>) {
28472849
let events = node.node().get_and_clear_pending_events();
28482850
let expected_payment_hash = PaymentHash(
28492851
bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).to_byte_array(),
@@ -2858,6 +2860,7 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28582860
}
28592861
// We return the invoice because some test may want to check the invoice details.
28602862
let invoice;
2863+
let mut path_events = Vec::new();
28612864
let expected_payment_id = match events[0] {
28622865
Event::PaymentSent {
28632866
ref payment_id,
@@ -2886,12 +2889,14 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28862889
Event::PaymentPathSuccessful { payment_id, payment_hash, .. } => {
28872890
assert_eq!(payment_id, expected_payment_id);
28882891
assert_eq!(payment_hash, Some(expected_payment_hash));
2892+
2893+
path_events.push(events[i].clone());
28892894
},
28902895
_ => panic!("Unexpected event"),
28912896
}
28922897
}
28932898
}
2894-
invoice
2899+
(invoice, path_events)
28952900
}
28962901

28972902
#[macro_export]
@@ -3903,15 +3908,17 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
39033908

39043909
expected_total_fee_msat
39053910
}
3906-
pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) -> Option<PaidBolt12Invoice> {
3911+
pub fn claim_payment_along_route(
3912+
args: ClaimAlongRouteArgs,
3913+
) -> (Option<PaidBolt12Invoice>, Vec<Event>) {
39073914
let origin_node = args.origin_node;
39083915
let payment_preimage = args.payment_preimage;
39093916
let skip_last = args.skip_last;
39103917
let expected_total_fee_msat = do_claim_payment_along_route(args);
39113918
if !skip_last {
39123919
expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat))
39133920
} else {
3914-
None
3921+
(None, Vec::new())
39153922
}
39163923
}
39173924

@@ -3924,6 +3931,7 @@ pub fn claim_payment<'a, 'b, 'c>(
39243931
&[expected_route],
39253932
our_payment_preimage,
39263933
))
3934+
.0
39273935
}
39283936

39293937
pub const TEST_FINAL_CLTV: u32 = 70;

0 commit comments

Comments
 (0)