From: Jeffrey Czyz Date: Wed, 6 Sep 2023 20:17:01 +0000 (-0500) Subject: Test removing abandoned AwaitingInvoice payments X-Git-Tag: v0.0.117-alpha1~23^2~8 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=cbeaeb708f413b1abadc7a3dadb2f7cf0a531eae;p=rust-lightning Test removing abandoned AwaitingInvoice payments --- diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index f89893665..e154b3f0d 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -1813,4 +1813,26 @@ mod tests { assert!(outbound_payments.add_new_awaiting_invoice(payment_id).is_err()); } + + #[test] + fn removes_abandoned_awaiting_invoice() { + let pending_events = Mutex::new(VecDeque::new()); + let outbound_payments = OutboundPayments::new(); + let payment_id = PaymentId([0; 32]); + + assert!(!outbound_payments.has_pending_payments()); + assert!(outbound_payments.add_new_awaiting_invoice(payment_id).is_ok()); + assert!(outbound_payments.has_pending_payments()); + + outbound_payments.abandon_payment( + payment_id, PaymentFailureReason::UserAbandoned, &pending_events + ); + assert!(!outbound_payments.has_pending_payments()); + assert!(!pending_events.lock().unwrap().is_empty()); + assert_eq!( + pending_events.lock().unwrap().pop_front(), + Some((Event::InvoiceRequestFailed { payment_id }, None)), + ); + assert!(pending_events.lock().unwrap().is_empty()); + } }