From 27317462280e04da1a35a7e6e9f6a76c31757ccd Mon Sep 17 00:00:00 2001 From: Ian Slane Date: Thu, 25 Jul 2024 10:24:57 -0600 Subject: [PATCH] Add tests for handling Offers with fiat amount Ensure successful creation of InvoiceRequest when a currency amount is specified without amount_msats. Then ideally fail when both currency amount and amount_msats are provided. However, the return behavior isn't what's expected; its a work in progress. --- lightning/src/offers/invoice_request.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 3b7f0ed763e..1f62b2766e7 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -1721,6 +1721,24 @@ mod tests { Ok(_) => panic!("expected error"), Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount), } + + let invoice_request = OfferBuilder::new(recipient_pubkey()) + .amount(Amount::Currency {iso4217_code: *b"USD", amount: 1000}) + .build_unchecked() + .request_invoice(vec![1; 32], payer_pubkey()).unwrap() + .build().unwrap() + .sign(payer_sign).unwrap(); + assert_eq!(invoice_request.amount(), Some(Amount::Currency {iso4217_code: *b"USD", amount: 1000})); + + match OfferBuilder::new(recipient_pubkey()) + .amount(Amount::Currency {iso4217_code: *b"USD", amount: 100}) + .build_unchecked() + .request_invoice(vec![1; 32], payer_pubkey()) + .unwrap().amount_msats(150_000_000) + { + Ok(_) => panic!("expected error"), + Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedCurrency), + } } #[test]