Skip to content

Commit 61fb931

Browse files
committed
Return path events from expect_payment_sent
Prepare for inspecting hold times in PaymentPathSuccessful.
1 parent 80f457e commit 61fb931

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
@@ -605,7 +605,7 @@ fn async_receive_flow_success() {
605605
let args = PassAlongPathArgs::new(&nodes[0], route[0], amt_msat, payment_hash, ev);
606606
let claimable_ev = do_pass_along_path(args).unwrap();
607607
let keysend_preimage = extract_payment_preimage(&claimable_ev);
608-
let res =
608+
let (res, _) =
609609
claim_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], route, keysend_preimage));
610610
assert_eq!(res, Some(PaidBolt12Invoice::StaticInvoice(static_invoice)));
611611
}

lightning/src/ln/functional_test_utils.rs

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

2843+
/// Inspect events to assert that a payment was sent. If this was a BOLT 12 payment, the BOLT 12 invoice is returned. If
2844+
/// per-path claims are expected, the events for each path are returned as well.
28432845
pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28442846
node: &H, expected_payment_preimage: PaymentPreimage,
28452847
expected_fee_msat_opt: Option<Option<u64>>, expect_per_path_claims: bool,
28462848
expect_post_ev_mon_update: bool,
2847-
) -> Option<PaidBolt12Invoice> {
2849+
) -> (Option<PaidBolt12Invoice>, Vec<Event>) {
28482850
let events = node.node().get_and_clear_pending_events();
28492851
let expected_payment_hash = PaymentHash(
28502852
bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).to_byte_array(),
@@ -2859,6 +2861,7 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28592861
}
28602862
// We return the invoice because some test may want to check the invoice details.
28612863
let invoice;
2864+
let mut path_events = Vec::new();
28622865
let expected_payment_id = match events[0] {
28632866
Event::PaymentSent {
28642867
ref payment_id,
@@ -2887,12 +2890,14 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28872890
Event::PaymentPathSuccessful { payment_id, payment_hash, .. } => {
28882891
assert_eq!(payment_id, expected_payment_id);
28892892
assert_eq!(payment_hash, Some(expected_payment_hash));
2893+
2894+
path_events.push(events[i].clone());
28902895
},
28912896
_ => panic!("Unexpected event"),
28922897
}
28932898
}
28942899
}
2895-
invoice
2900+
(invoice, path_events)
28962901
}
28972902

28982903
#[macro_export]
@@ -3904,15 +3909,17 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
39043909

39053910
expected_total_fee_msat
39063911
}
3907-
pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) -> Option<PaidBolt12Invoice> {
3912+
pub fn claim_payment_along_route(
3913+
args: ClaimAlongRouteArgs,
3914+
) -> (Option<PaidBolt12Invoice>, Vec<Event>) {
39083915
let origin_node = args.origin_node;
39093916
let payment_preimage = args.payment_preimage;
39103917
let skip_last = args.skip_last;
39113918
let expected_total_fee_msat = do_claim_payment_along_route(args);
39123919
if !skip_last {
39133920
expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat))
39143921
} else {
3915-
None
3922+
(None, Vec::new())
39163923
}
39173924
}
39183925

@@ -3925,6 +3932,7 @@ pub fn claim_payment<'a, 'b, 'c>(
39253932
&[expected_route],
39263933
our_payment_preimage,
39273934
))
3935+
.0
39283936
}
39293937

39303938
pub const TEST_FINAL_CLTV: u32 = 70;

0 commit comments

Comments
 (0)