Skip to content

Commit bac99be

Browse files
committed
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.
1 parent 00f7e51 commit bac99be

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lightning/src/offers/invoice_request.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,24 @@ mod tests {
17211721
Ok(_) => panic!("expected error"),
17221722
Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
17231723
}
1724+
1725+
let invoice_request = OfferBuilder::new(recipient_pubkey())
1726+
.amount(Amount::Currency {iso4217_code: *b"USD", amount: 1000})
1727+
.build_unchecked()
1728+
.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
1729+
.build().unwrap()
1730+
.sign(payer_sign).unwrap();
1731+
assert_eq!(invoice_request.amount(), Some(Amount::Currency {iso4217_code: *b"USD", amount: 1000}));
1732+
1733+
match OfferBuilder::new(recipient_pubkey())
1734+
.amount(Amount::Currency {iso4217_code: *b"USD", amount: 100})
1735+
.build_unchecked()
1736+
.request_invoice(vec![1; 32], payer_pubkey())
1737+
.unwrap().amount_msats(150_000_000)
1738+
{
1739+
Ok(_) => panic!("expected error"),
1740+
Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedCurrency),
1741+
}
17241742
}
17251743

17261744
#[test]

0 commit comments

Comments
 (0)