Skip to content

Commit 84fd3e8

Browse files
committed
Write up trivial test for single-hop payments
1 parent 35ac88a commit 84fd3e8

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

lightning-invoice/src/payment.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -894,20 +894,23 @@ mod tests {
894894
let payment_id = Some(invoice_payer.pay_invoice(&invoice).unwrap());
895895
assert_eq!(*payer.attempts.borrow(), 1);
896896

897+
{
898+
let inflight_map = invoice_payer.create_inflight_map(&payment_hash);
899+
// TestRouter returns two hops, with `fee_msat` divided by two. The invoice instantiated above
900+
// is hard-coded to test sending an invoice with a value of 128 msats.
901+
assert_eq!(inflight_map.get(&(0, true)).unwrap().clone(), 64);
902+
assert_eq!(inflight_map.get(&(1, true)).unwrap().clone(), 64);
903+
}
904+
897905
invoice_payer.handle_event(&Event::PaymentSent {
898906
payment_id, payment_preimage, payment_hash, fee_paid_msat: None
899907
});
900908
assert_eq!(*event_handled.borrow(), true);
901909
assert_eq!(*payer.attempts.borrow(), 1);
902910

903-
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
904-
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
905-
path: TestRouter::route_for_value(final_value_msat).paths[0].clone()
906-
});
907-
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
908-
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
909-
path: TestRouter::route_for_value(final_value_msat).paths[1].clone()
910-
});
911+
// We should have cleared the payment_cache of information about this payment
912+
let inflight_map = invoice_payer.create_inflight_map(&payment_hash);
913+
assert_eq!(inflight_map.len(), 0)
911914
}
912915

913916
#[test]
@@ -951,15 +954,6 @@ mod tests {
951954
});
952955
assert_eq!(*event_handled.borrow(), true);
953956
assert_eq!(*payer.attempts.borrow(), 2);
954-
955-
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
956-
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
957-
path: TestRouter::route_for_value(final_value_msat).paths[0].clone()
958-
});
959-
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
960-
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
961-
path: TestRouter::route_for_value(final_value_msat).paths[1].clone()
962-
});
963957
}
964958

965959
#[test]

0 commit comments

Comments
 (0)