Skip to content

Commit 2a4a470

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 b6ceafb commit 2a4a470

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lightning/src/ln/invoice_utils.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ mod test {
710710
use lightning_invoice::{Currency, Description, Bolt11InvoiceDescriptionRef, SignOrCreationError, CreationError};
711711
use bitcoin::hashes::{Hash, sha256};
712712
use bitcoin::hashes::sha256::Hash as Sha256;
713+
use bitcoin::network::Network;
713714
use crate::sign::PhantomKeysManager;
714715
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
715716
use crate::types::payment::{PaymentHash, PaymentPreimage};
@@ -903,6 +904,36 @@ mod test {
903904
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
904905
}
905906

907+
#[cfg(not(feature = "std"))]
908+
#[test]
909+
fn creates_invoice_using_highest_seen_timestamp() {
910+
let chanmon_cfgs = create_chanmon_cfgs(2);
911+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
912+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
913+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
914+
915+
let invoice_params = Bolt11InvoiceParameters::default();
916+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
917+
let best_block = bitcoin::constants::genesis_block(Network::Testnet);
918+
assert_eq!(
919+
invoice.duration_since_epoch(),
920+
Duration::from_secs(best_block.header.time.into()),
921+
);
922+
}
923+
924+
#[test]
925+
fn creates_invoice_using_currency_inferred_from_chain_hash() {
926+
let chanmon_cfgs = create_chanmon_cfgs(2);
927+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
928+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
929+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
930+
931+
let invoice_params = Bolt11InvoiceParameters::default();
932+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
933+
assert_eq!(invoice.currency(), Currency::BitcoinTestnet);
934+
assert_eq!(invoice.network(), Network::Testnet);
935+
}
936+
906937
#[test]
907938
fn test_hints_has_only_public_confd_channels() {
908939
let chanmon_cfgs = create_chanmon_cfgs(2);

0 commit comments

Comments
 (0)