Skip to content

Commit 2c6a75a

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 101a211 commit 2c6a75a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lightning/src/ln/invoice_utils.rs

+48
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ mod test {
555555
use lightning_invoice::{Currency, Description, Bolt11InvoiceDescriptionRef, SignOrCreationError, CreationError};
556556
use bitcoin::hashes::{Hash, sha256};
557557
use bitcoin::hashes::sha256::Hash as Sha256;
558+
use bitcoin::network::Network;
558559
use crate::sign::PhantomKeysManager;
559560
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
560561
use crate::types::payment::{PaymentHash, PaymentPreimage};
@@ -749,6 +750,53 @@ mod test {
749750
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
750751
}
751752

753+
#[cfg(not(feature = "std"))]
754+
#[test]
755+
fn creates_invoice_using_highest_seen_timestamp() {
756+
let chanmon_cfgs = create_chanmon_cfgs(2);
757+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
758+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
759+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
760+
761+
let payment_hash = PaymentHash([0; 32]);
762+
let description = Bolt11InvoiceDescription::Direct(
763+
Description::new("test".to_string()).unwrap()
764+
);
765+
let invoice_params = Bolt11InvoiceParameters {
766+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
767+
duration_since_epoch: None, invoice_expiry_delta_secs: Some(3600),
768+
min_final_cltv_expiry_delta: None, payment_hash: Some(payment_hash),
769+
};
770+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
771+
let best_block = bitcoin::constants::genesis_block(Network::Testnet);
772+
assert_eq!(
773+
invoice.duration_since_epoch(),
774+
Duration::from_secs(best_block.header.time.into()),
775+
);
776+
}
777+
778+
#[test]
779+
fn creates_invoice_using_currency_inferred_from_chain_hash() {
780+
let chanmon_cfgs = create_chanmon_cfgs(2);
781+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
782+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
783+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
784+
785+
let payment_hash = PaymentHash([0; 32]);
786+
let description = Bolt11InvoiceDescription::Direct(
787+
Description::new("test".to_string()).unwrap()
788+
);
789+
let invoice_params = Bolt11InvoiceParameters {
790+
currency: None, amount_msats: Some(10_000), description,
791+
duration_since_epoch: Some(Duration::from_secs(1234567)),
792+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta: None,
793+
payment_hash: Some(payment_hash),
794+
};
795+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
796+
assert_eq!(invoice.currency(), Currency::BitcoinTestnet);
797+
assert_eq!(invoice.network(), Network::Testnet);
798+
}
799+
752800
#[test]
753801
fn test_hints_has_only_public_confd_channels() {
754802
let chanmon_cfgs = create_chanmon_cfgs(2);

0 commit comments

Comments
 (0)