Skip to content

Commit

Permalink
Add tests for handling Offers with fiat amount
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slanesuke committed Jul 25, 2024
1 parent 9d08ba6 commit 2731746
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lightning/src/offers/invoice_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2731746

Please sign in to comment.