]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test removing abandoned AwaitingInvoice payments
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 6 Sep 2023 20:17:01 +0000 (15:17 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 7 Sep 2023 21:45:12 +0000 (16:45 -0500)
lightning/src/ln/outbound_payment.rs

index f8989366509b56a482783fbf41af82ae9c67d681..e154b3f0d73d9736eb7afc567d768117e8ff8202 100644 (file)
@@ -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());
+       }
 }