]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test new behavior in create_bolt11_invoice
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 29 Oct 2024 14:58:37 +0000 (09:58 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 8 Nov 2024 18:14:51 +0000 (12:14 -0600)
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

index a39222c3fcbae38d21a11ffea0922af8e5d9a2fe..07e108dab06afc8c1821d111119ccd3afa06cb47 100644 (file)
@@ -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);