Skip to content

Commit ce0e182

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 3c6896c commit ce0e182

File tree

1 file changed

+77
-26
lines changed

1 file changed

+77
-26
lines changed

lightning/src/ln/invoice_utils.rs

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ mod test {
709709
use crate::sign::PhantomKeysManager;
710710
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
711711
use crate::types::payment::{PaymentHash, PaymentPreimage};
712-
use crate::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
712+
use crate::ln::channelmanager::{Bolt11InvoiceParameters, PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
713713
use crate::ln::functional_test_utils::*;
714714
use crate::ln::msgs::ChannelMessageHandler;
715715
use crate::routing::router::{PaymentParameters, RouteParameters};
@@ -752,10 +752,18 @@ mod test {
752752
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
753753
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
754754
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
755+
756+
let description = Bolt11InvoiceDescription::Direct(
757+
Description::new("test".to_string()).unwrap()
758+
);
755759
let non_default_invoice_expiry_secs = 4200;
756-
let invoice = create_invoice_from_channelmanager(
757-
nodes[1].node, Some(10_000), "test".to_string(), non_default_invoice_expiry_secs, None,
758-
).unwrap();
760+
let invoice_params = Bolt11InvoiceParameters {
761+
amount_msats: Some(10_000),
762+
description,
763+
invoice_expiry_delta_secs: Some(non_default_invoice_expiry_secs),
764+
..Default::default()
765+
};
766+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
759767
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
760768
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
761769
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
@@ -803,10 +811,17 @@ mod test {
803811
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
804812
let custom_min_final_cltv_expiry_delta = Some(50);
805813

806-
let invoice = create_invoice_from_channelmanager(
807-
nodes[1].node, Some(10_000), "".into(), 3600,
808-
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
809-
).unwrap();
814+
let description = Bolt11InvoiceDescription::Direct(Description::empty());
815+
let min_final_cltv_expiry_delta =
816+
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None };
817+
let invoice_params = Bolt11InvoiceParameters {
818+
amount_msats: Some(10_000),
819+
description,
820+
invoice_expiry_delta_secs: Some(3600),
821+
min_final_cltv_expiry_delta,
822+
..Default::default()
823+
};
824+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
810825
assert_eq!(invoice.min_final_cltv_expiry_delta(), if with_custom_delta {
811826
custom_min_final_cltv_expiry_delta.unwrap() + 3 /* Buffer */} else { MIN_FINAL_CLTV_EXPIRY_DELTA } as u64);
812827
}
@@ -823,11 +838,17 @@ mod test {
823838
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
824839
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
825840
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
826-
let custom_min_final_cltv_expiry_delta = Some(21);
827841

828-
let invoice = create_invoice_from_channelmanager(
829-
nodes[1].node, Some(10_000), "".into(), 3600, custom_min_final_cltv_expiry_delta,
830-
).unwrap();
842+
let custom_min_final_cltv_expiry_delta = Some(21);
843+
let description = Bolt11InvoiceDescription::Direct(Description::empty());
844+
let invoice_params = Bolt11InvoiceParameters {
845+
amount_msats: Some(10_000),
846+
description,
847+
invoice_expiry_delta_secs: Some(3600),
848+
min_final_cltv_expiry_delta: custom_min_final_cltv_expiry_delta,
849+
..Default::default()
850+
};
851+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
831852
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
832853
}
833854

@@ -837,10 +858,17 @@ mod test {
837858
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
838859
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
839860
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
840-
let description_hash = Sha256(Hash::hash("Testing description_hash".as_bytes()));
841-
let invoice = create_invoice_from_channelmanager_with_description_hash(
842-
nodes[1].node, Some(10_000), description_hash, 3600, None,
843-
).unwrap();
861+
862+
let description = Bolt11InvoiceDescription::Hash(
863+
Sha256(Hash::hash("Testing description_hash".as_bytes()))
864+
);
865+
let invoice_params = Bolt11InvoiceParameters {
866+
amount_msats: Some(10_000),
867+
description,
868+
invoice_expiry_delta_secs: Some(3600),
869+
..Default::default()
870+
};
871+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
844872
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
845873
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
846874
assert_eq!(invoice.description(), Bolt11InvoiceDescriptionRef::Hash(&Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
@@ -852,10 +880,19 @@ mod test {
852880
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
853881
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
854882
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
883+
855884
let payment_hash = PaymentHash([0; 32]);
856-
let invoice = create_invoice_from_channelmanager_with_payment_hash(
857-
nodes[1].node, Some(10_000), "test".to_string(), 3600, payment_hash, None,
858-
).unwrap();
885+
let description = Bolt11InvoiceDescription::Direct(
886+
Description::new("test".to_string()).unwrap()
887+
);
888+
let invoice_params = Bolt11InvoiceParameters {
889+
amount_msats: Some(10_000),
890+
description,
891+
invoice_expiry_delta_secs: Some(3600),
892+
payment_hash: Some(payment_hash),
893+
..Default::default()
894+
};
895+
let invoice = nodes[1].node.create_bolt11_invoice(invoice_params).unwrap();
859896
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
860897
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
861898
assert_eq!(invoice.description(), Bolt11InvoiceDescriptionRef::Direct(&Description::new("test".to_string()).unwrap()));
@@ -1143,9 +1180,16 @@ mod test {
11431180
invoice_node: &Node<'a, 'b, 'c>,
11441181
mut chan_ids_to_match: HashSet<u64>
11451182
) {
1146-
let invoice = create_invoice_from_channelmanager(
1147-
invoice_node.node, invoice_amt, "test".to_string(), 3600, None,
1148-
).unwrap();
1183+
let description = Bolt11InvoiceDescription::Direct(
1184+
Description::new("test".to_string()).unwrap()
1185+
);
1186+
let invoice_params = Bolt11InvoiceParameters {
1187+
amount_msats: invoice_amt,
1188+
description,
1189+
invoice_expiry_delta_secs: Some(3600),
1190+
..Default::default()
1191+
};
1192+
let invoice = invoice_node.node.create_bolt11_invoice(invoice_params).unwrap();
11491193
let hints = invoice.private_routes();
11501194

11511195
for hint in hints {
@@ -1780,11 +1824,18 @@ mod test {
17801824
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
17811825
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
17821826
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1783-
let result = create_invoice_from_channelmanager(
1784-
nodes[1].node, Some(10_000), "Some description".into(), 3600,
1785-
Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
1827+
1828+
let description = Bolt11InvoiceDescription::Direct(
1829+
Description::new("Some description".to_string()).unwrap()
17861830
);
1787-
match result {
1831+
let invoice_params = Bolt11InvoiceParameters {
1832+
amount_msats: Some(10_000),
1833+
description,
1834+
invoice_expiry_delta_secs: Some(3600),
1835+
min_final_cltv_expiry_delta: Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
1836+
..Default::default()
1837+
};
1838+
match nodes[1].node.create_bolt11_invoice(invoice_params) {
17881839
Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort)) => {},
17891840
_ => panic!(),
17901841
}

0 commit comments

Comments
 (0)