Skip to content

Commit eede312

Browse files
committed
Use ChannelManager::create_bolt11_invoice in tests
The utility methods in in invoice_utils will be removed or deprecated in an upcoming commit.
1 parent 72a84f4 commit eede312

File tree

1 file changed

+66
-30
lines changed

1 file changed

+66
-30
lines changed

lightning/src/ln/invoice_utils.rs

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ mod test {
715715
use crate::sign::PhantomKeysManager;
716716
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
717717
use crate::types::payment::{PaymentHash, PaymentPreimage};
718-
use crate::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
718+
use crate::ln::channelmanager::{Bolt11InvoiceParameters, PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
719719
use crate::ln::functional_test_utils::*;
720720
use crate::ln::msgs::ChannelMessageHandler;
721721
use crate::routing::router::{PaymentParameters, RouteParameters};
@@ -758,11 +758,17 @@ mod test {
758758
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
759759
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
760760
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
761+
762+
let description = Bolt11InvoiceDescription::Direct(
763+
Description::new("test".to_string()).unwrap()
764+
);
761765
let non_default_invoice_expiry_secs = 4200;
762-
let invoice = create_invoice_from_channelmanager(
763-
nodes[1].node, Currency::BitcoinTestnet, Some(10_000), "test".to_string(),
764-
non_default_invoice_expiry_secs, None,
765-
).unwrap();
766+
let invoice_params = Bolt11InvoiceParameters {
767+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
768+
invoice_expiry_delta_secs: Some(non_default_invoice_expiry_secs),
769+
min_final_cltv_expiry_delta: None, payment_hash: None,
770+
};
771+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
766772
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
767773
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
768774
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
@@ -810,10 +816,14 @@ mod test {
810816
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
811817
let custom_min_final_cltv_expiry_delta = Some(50);
812818

813-
let invoice = create_invoice_from_channelmanager(
814-
nodes[1].node, Currency::BitcoinTestnet, Some(10_000), "".into(), 3600,
815-
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
816-
).unwrap();
819+
let description = Bolt11InvoiceDescription::Direct(Description::empty());
820+
let min_final_cltv_expiry_delta =
821+
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None };
822+
let invoice_params = Bolt11InvoiceParameters {
823+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
824+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta, payment_hash: None,
825+
};
826+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
817827
assert_eq!(invoice.min_final_cltv_expiry_delta(), if with_custom_delta {
818828
custom_min_final_cltv_expiry_delta.unwrap() + 3 /* Buffer */} else { MIN_FINAL_CLTV_EXPIRY_DELTA } as u64);
819829
}
@@ -830,12 +840,16 @@ mod test {
830840
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
831841
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
832842
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
833-
let custom_min_final_cltv_expiry_delta = Some(21);
834843

835-
let invoice = create_invoice_from_channelmanager(
836-
nodes[1].node, Currency::BitcoinTestnet, Some(10_000), "".into(), 3600,
837-
custom_min_final_cltv_expiry_delta,
838-
).unwrap();
844+
let custom_min_final_cltv_expiry_delta = Some(21);
845+
let description = Bolt11InvoiceDescription::Direct(Description::empty());
846+
let invoice_params = Bolt11InvoiceParameters {
847+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
848+
invoice_expiry_delta_secs: Some(3600),
849+
min_final_cltv_expiry_delta: custom_min_final_cltv_expiry_delta,
850+
payment_hash: None,
851+
};
852+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
839853
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
840854
}
841855

@@ -845,10 +859,16 @@ mod test {
845859
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
846860
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
847861
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
848-
let description_hash = Sha256(Hash::hash("Testing description_hash".as_bytes()));
849-
let invoice = create_invoice_from_channelmanager_with_description_hash(
850-
nodes[1].node, Currency::BitcoinTestnet, Some(10_000), description_hash, 3600, None,
851-
).unwrap();
862+
863+
let description = Bolt11InvoiceDescription::Hash(
864+
Sha256(Hash::hash("Testing description_hash".as_bytes()))
865+
);
866+
let invoice_params = Bolt11InvoiceParameters {
867+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
868+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta: None,
869+
payment_hash: None,
870+
};
871+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
852872
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
853873
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
854874
assert_eq!(invoice.description(), Bolt11InvoiceDescriptionRef::Hash(&Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
@@ -860,11 +880,17 @@ mod test {
860880
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
861881
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
862882
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
883+
863884
let payment_hash = PaymentHash([0; 32]);
864-
let invoice = create_invoice_from_channelmanager_with_payment_hash(
865-
nodes[1].node, Currency::BitcoinTestnet, Some(10_000), "test".to_string(), 3600,
866-
payment_hash, None,
867-
).unwrap();
885+
let description = Bolt11InvoiceDescription::Direct(
886+
Description::new("test".to_string()).unwrap()
887+
);
888+
let invoice_params = Bolt11InvoiceParameters {
889+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
890+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta: None,
891+
payment_hash: Some(payment_hash),
892+
};
893+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
868894
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
869895
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
870896
assert_eq!(invoice.description(), Bolt11InvoiceDescriptionRef::Direct(&Description::new("test".to_string()).unwrap()));
@@ -1152,10 +1178,15 @@ mod test {
11521178
invoice_node: &Node<'a, 'b, 'c>,
11531179
mut chan_ids_to_match: HashSet<u64>
11541180
) {
1155-
let invoice = create_invoice_from_channelmanager(
1156-
invoice_node.node, Currency::BitcoinTestnet, invoice_amt, "test".to_string(), 3600,
1157-
None,
1158-
).unwrap();
1181+
let description = Bolt11InvoiceDescription::Direct(
1182+
Description::new("test".to_string()).unwrap()
1183+
);
1184+
let invoice_params = Bolt11InvoiceParameters {
1185+
currency: Some(Currency::BitcoinTestnet), amount_msats: invoice_amt, description,
1186+
invoice_expiry_delta_secs: Some(3600), min_final_cltv_expiry_delta: None,
1187+
payment_hash: None,
1188+
};
1189+
let invoice = invoice_node.node.create_bolt11_invoice(invoice_params).unwrap();
11591190
let hints = invoice.private_routes();
11601191

11611192
for hint in hints {
@@ -1790,11 +1821,16 @@ mod test {
17901821
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
17911822
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
17921823
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1793-
let result = create_invoice_from_channelmanager(
1794-
nodes[1].node, Currency::BitcoinTestnet, Some(10_000), "Some description".into(), 3600,
1795-
Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
1824+
1825+
let description = Bolt11InvoiceDescription::Direct(
1826+
Description::new("Some description".to_string()).unwrap()
17961827
);
1797-
match result {
1828+
let invoice_params = Bolt11InvoiceParameters {
1829+
currency: Some(Currency::BitcoinTestnet), amount_msats: Some(10_000), description,
1830+
invoice_expiry_delta_secs: Some(3600),
1831+
min_final_cltv_expiry_delta: Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4), payment_hash: None,
1832+
};
1833+
match nodes[1].node.create_bolt11_invoice(invoice_params) {
17981834
Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort)) => {},
17991835
_ => panic!(),
18001836
}

0 commit comments

Comments
 (0)