Skip to content

Commit

Permalink
Write up trivial test for single-hop payments
Browse files Browse the repository at this point in the history
  • Loading branch information
jurvis committed Aug 18, 2022
1 parent 35ac88a commit 84fd3e8
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lightning-invoice/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,20 +894,23 @@ mod tests {
let payment_id = Some(invoice_payer.pay_invoice(&invoice).unwrap());
assert_eq!(*payer.attempts.borrow(), 1);

{
let inflight_map = invoice_payer.create_inflight_map(&payment_hash);
// TestRouter returns two hops, with `fee_msat` divided by two. The invoice instantiated above
// is hard-coded to test sending an invoice with a value of 128 msats.
assert_eq!(inflight_map.get(&(0, true)).unwrap().clone(), 64);
assert_eq!(inflight_map.get(&(1, true)).unwrap().clone(), 64);
}

invoice_payer.handle_event(&Event::PaymentSent {
payment_id, payment_preimage, payment_hash, fee_paid_msat: None
});
assert_eq!(*event_handled.borrow(), true);
assert_eq!(*payer.attempts.borrow(), 1);

invoice_payer.handle_event(&Event::PaymentPathSuccessful {
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
path: TestRouter::route_for_value(final_value_msat).paths[0].clone()
});
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
path: TestRouter::route_for_value(final_value_msat).paths[1].clone()
});
// We should have cleared the payment_cache of information about this payment
let inflight_map = invoice_payer.create_inflight_map(&payment_hash);
assert_eq!(inflight_map.len(), 0)
}

#[test]
Expand Down Expand Up @@ -951,15 +954,6 @@ mod tests {
});
assert_eq!(*event_handled.borrow(), true);
assert_eq!(*payer.attempts.borrow(), 2);

invoice_payer.handle_event(&Event::PaymentPathSuccessful {
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
path: TestRouter::route_for_value(final_value_msat).paths[0].clone()
});
invoice_payer.handle_event(&Event::PaymentPathSuccessful {
payment_id: payment_id.unwrap(), payment_hash: Some(payment_hash),
path: TestRouter::route_for_value(final_value_msat).paths[1].clone()
});
}

#[test]
Expand Down

0 comments on commit 84fd3e8

Please sign in to comment.