Skip to content

Commit fbd0a95

Browse files
committed
Test new behavior in create_bolt11_invoice
Bolt11InvoiceParameters allows for setting currency and duration_since_epoch. If currency is not set, test that the one corresponding to ChannelManager's chain hash is usd. If duration_since_epoch, is not set then highest seen timestamp is used in non-std compilations.
1 parent 1166460 commit fbd0a95

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lightning/src/ln/invoice_utils.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ mod test {
716716
use lightning_invoice::{Currency, Description, Bolt11InvoiceDescriptionRef, SignOrCreationError, CreationError};
717717
use bitcoin::hashes::{Hash, sha256};
718718
use bitcoin::hashes::sha256::Hash as Sha256;
719+
use bitcoin::network::Network;
719720
use crate::sign::PhantomKeysManager;
720721
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
721722
use crate::types::payment::{PaymentHash, PaymentPreimage};
@@ -901,6 +902,52 @@ mod test {
901902
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
902903
}
903904

905+
#[cfg(not(feature = "std"))]
906+
#[test]
907+
fn creates_invoice_using_highest_seen_timestamp() {
908+
let chanmon_cfgs = create_chanmon_cfgs(2);
909+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
910+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
911+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
912+
913+
let payment_hash = PaymentHash([0; 32]);
914+
let description = Bolt11InvoiceDescription::Direct(
915+
Description::new("test".to_string()).unwrap()
916+
);
917+
let invoice_params = Bolt11InvoiceParameters {
918+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
919+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta: None,
920+
payment_hash: Some(payment_hash),
921+
};
922+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
923+
let best_block = bitcoin::constants::genesis_block(Network::Testnet);
924+
assert_eq!(
925+
invoice.duration_since_epoch(),
926+
Duration::from_secs(best_block.header.time.into()),
927+
);
928+
}
929+
930+
#[test]
931+
fn creates_invoice_using_currency_inferred_from_chain_hash() {
932+
let chanmon_cfgs = create_chanmon_cfgs(2);
933+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
934+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
935+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
936+
937+
let payment_hash = PaymentHash([0; 32]);
938+
let description = Bolt11InvoiceDescription::Direct(
939+
Description::new("test".to_string()).unwrap()
940+
);
941+
let invoice_params = Bolt11InvoiceParameters {
942+
currency: None, amount_msats: Some(10_000), description,
943+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta: None,
944+
payment_hash: Some(payment_hash),
945+
};
946+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
947+
assert_eq!(invoice.currency(), Currency::BitcoinTestnet);
948+
assert_eq!(invoice.network(), Network::Testnet);
949+
}
950+
904951
#[test]
905952
fn test_hints_has_only_public_confd_channels() {
906953
let chanmon_cfgs = create_chanmon_cfgs(2);

0 commit comments

Comments
 (0)