Add test for requesting invoice from expired offer
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 31 Jan 2023 20:34:04 +0000 (14:34 -0600)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 3 Feb 2023 21:23:43 +0000 (15:23 -0600)
lightning/src/offers/invoice.rs

index 66642dec7b2d30a6dc04643bcc19bea0c49838e8..ad59bf35b0c9c2cd2cf54b7d19297471e757d099 100644 (file)
@@ -1032,6 +1032,42 @@ mod tests {
                }
        }
 
+       #[cfg(feature = "std")]
+       #[test]
+       fn builds_invoice_from_offer_with_expiration() {
+               let future_expiry = Duration::from_secs(u64::max_value());
+               let past_expiry = Duration::from_secs(0);
+
+               if let Err(e) = OfferBuilder::new("foo".into(), recipient_pubkey())
+                       .amount_msats(1000)
+                       .absolute_expiry(future_expiry)
+                       .build().unwrap()
+                       .request_invoice(vec![1; 32], payer_pubkey()).unwrap()
+                       .build().unwrap()
+                       .sign(payer_sign).unwrap()
+                       .respond_with(payment_paths(), payment_hash())
+                       .unwrap()
+                       .build()
+               {
+                       panic!("error building invoice: {:?}", e);
+               }
+
+               match OfferBuilder::new("foo".into(), recipient_pubkey())
+                       .amount_msats(1000)
+                       .absolute_expiry(past_expiry)
+                       .build().unwrap()
+                       .request_invoice(vec![1; 32], payer_pubkey()).unwrap()
+                       .build_unchecked()
+                       .sign(payer_sign).unwrap()
+                       .respond_with(payment_paths(), payment_hash())
+                       .unwrap()
+                       .build()
+               {
+                       Ok(_) => panic!("expected error"),
+                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+               }
+       }
+
        #[cfg(feature = "std")]
        #[test]
        fn builds_invoice_from_refund_with_expiration() {