Skip to content

Commit a3d4b56

Browse files
committed
Return path events from expect_payment_sent
Prepare for inspecting hold times in PaymentPathSuccessful.
1 parent 9ec18aa commit a3d4b56

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 3 additions & 3 deletions
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
}
@@ -1723,7 +1723,7 @@ fn refresh_static_invoices() {
17231723
let claimable_ev = do_pass_along_path(args).unwrap();
17241724
let keysend_preimage = extract_payment_preimage(&claimable_ev);
17251725
let res = claim_payment_along_route(ClaimAlongRouteArgs::new(sender, route, keysend_preimage));
1726-
assert_eq!(res, Some(PaidBolt12Invoice::StaticInvoice(updated_invoice)));
1726+
assert_eq!(res.0, Some(PaidBolt12Invoice::StaticInvoice(updated_invoice)));
17271727
}
17281728

17291729
#[cfg_attr(feature = "std", ignore)]
@@ -2053,5 +2053,5 @@ fn invoice_server_is_not_channel_peer() {
20532053
let claimable_ev = do_pass_along_path(args).unwrap();
20542054
let keysend_preimage = extract_payment_preimage(&claimable_ev);
20552055
let res = claim_payment_along_route(ClaimAlongRouteArgs::new(sender, route, keysend_preimage));
2056-
assert_eq!(res, Some(PaidBolt12Invoice::StaticInvoice(invoice)));
2056+
assert_eq!(res.0, Some(PaidBolt12Invoice::StaticInvoice(invoice)));
20572057
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,11 +2862,13 @@ macro_rules! expect_payment_claimed {
28622862
};
28632863
}
28642864

2865+
/// Inspect events to assert that a payment was sent. If this was a BOLT 12 payment, the BOLT 12 invoice is returned. If
2866+
/// per-path claims are expected, the events for each path are returned as well.
28652867
pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28662868
node: &H, expected_payment_preimage: PaymentPreimage,
28672869
expected_fee_msat_opt: Option<Option<u64>>, expect_per_path_claims: bool,
28682870
expect_post_ev_mon_update: bool,
2869-
) -> Option<PaidBolt12Invoice> {
2871+
) -> (Option<PaidBolt12Invoice>, Vec<Event>) {
28702872
let events = node.node().get_and_clear_pending_events();
28712873
let expected_payment_hash = PaymentHash(
28722874
bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).to_byte_array(),
@@ -2881,6 +2883,7 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
28812883
}
28822884
// We return the invoice because some test may want to check the invoice details.
28832885
let invoice;
2886+
let mut path_events = Vec::new();
28842887
let expected_payment_id = match events[0] {
28852888
Event::PaymentSent {
28862889
ref payment_id,
@@ -2909,12 +2912,14 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
29092912
Event::PaymentPathSuccessful { payment_id, payment_hash, .. } => {
29102913
assert_eq!(payment_id, expected_payment_id);
29112914
assert_eq!(payment_hash, Some(expected_payment_hash));
2915+
2916+
path_events.push(events[i].clone());
29122917
},
29132918
_ => panic!("Unexpected event"),
29142919
}
29152920
}
29162921
}
2917-
invoice
2922+
(invoice, path_events)
29182923
}
29192924

29202925
#[macro_export]
@@ -3926,15 +3931,17 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
39263931

39273932
expected_total_fee_msat
39283933
}
3929-
pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) -> Option<PaidBolt12Invoice> {
3934+
pub fn claim_payment_along_route(
3935+
args: ClaimAlongRouteArgs,
3936+
) -> (Option<PaidBolt12Invoice>, Vec<Event>) {
39303937
let origin_node = args.origin_node;
39313938
let payment_preimage = args.payment_preimage;
39323939
let skip_last = args.skip_last;
39333940
let expected_total_fee_msat = do_claim_payment_along_route(args);
39343941
if !skip_last {
39353942
expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat))
39363943
} else {
3937-
None
3944+
(None, Vec::new())
39383945
}
39393946
}
39403947

@@ -3947,6 +3954,7 @@ pub fn claim_payment<'a, 'b, 'c>(
39473954
&[expected_route],
39483955
our_payment_preimage,
39493956
))
3957+
.0
39503958
}
39513959

39523960
pub const TEST_FINAL_CLTV: u32 = 70;

0 commit comments

Comments
 (0)