From 2a4a470c988146c1f7a8f3aad7d7e4029d736984 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Tue, 29 Oct 2024 09:58:37 -0500 Subject: [PATCH] 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. --- lightning/src/ln/invoice_utils.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lightning/src/ln/invoice_utils.rs b/lightning/src/ln/invoice_utils.rs index a39222c3f..07e108dab 100644 --- a/lightning/src/ln/invoice_utils.rs +++ b/lightning/src/ln/invoice_utils.rs @@ -710,6 +710,7 @@ mod test { use lightning_invoice::{Currency, Description, Bolt11InvoiceDescriptionRef, SignOrCreationError, CreationError}; use bitcoin::hashes::{Hash, sha256}; use bitcoin::hashes::sha256::Hash as Sha256; + use bitcoin::network::Network; use crate::sign::PhantomKeysManager; use crate::events::{MessageSendEvent, MessageSendEventsProvider}; use crate::types::payment::{PaymentHash, PaymentPreimage}; @@ -903,6 +904,36 @@ mod test { assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap()); } + #[cfg(not(feature = "std"))] + #[test] + fn creates_invoice_using_highest_seen_timestamp() { + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + let invoice_params = Bolt11InvoiceParameters::default(); + let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap(); + let best_block = bitcoin::constants::genesis_block(Network::Testnet); + assert_eq!( + invoice.duration_since_epoch(), + Duration::from_secs(best_block.header.time.into()), + ); + } + + #[test] + fn creates_invoice_using_currency_inferred_from_chain_hash() { + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + let invoice_params = Bolt11InvoiceParameters::default(); + let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap(); + assert_eq!(invoice.currency(), Currency::BitcoinTestnet); + assert_eq!(invoice.network(), Network::Testnet); + } + #[test] fn test_hints_has_only_public_confd_channels() { let chanmon_cfgs = create_chanmon_cfgs(2); -- 2.39.5