Skip to content

Commit 2bd906e

Browse files
committed
test: cover route_hints_override states in BOLT11 invoice creation
1 parent d5a2473 commit 2bd906e

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12718,7 +12718,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1271812718
let route_hints = match route_hints_override {
1271912719
Some(hints) => hints,
1272012720
None => {
12721-
let channels: Vec<ChannelDetails> = self.list_channels();
12721+
let channels = self.list_channels();
1272212722
super::invoice_utils::sort_and_filter_channels(
1272312723
channels, amount_msats, &self.logger,
1272412724
)
@@ -12774,7 +12774,9 @@ pub struct Bolt11InvoiceParameters {
1277412774

1277512775
/// Override the route hints included in the invoice. If `None`, route hints will be automatically
1277612776
/// selected from eligible channels. If `Some(vec![])`, no route hints will be included. If
12777-
/// `Some(hints)`, the given hints will be used.
12777+
/// `Some(hints)`, the given hints will be used as-is with no validation and no cap (automatic
12778+
/// selection caps at three hints), so the caller is responsible for hint correctness and
12779+
/// invoice/QR size.
1277812780
pub route_hints_override: Option<Vec<RouteHint>>,
1277912781
}
1278012782

lightning/src/ln/invoice_utils.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,64 @@ mod test {
724724
assert_eq!(events.len(), 2);
725725
}
726726

727+
fn make_route_hints_override_test_params(
728+
route_hints_override: Option<Vec<RouteHint>>,
729+
) -> Bolt11InvoiceParameters {
730+
Bolt11InvoiceParameters {
731+
amount_msats: Some(10_000),
732+
description: Bolt11InvoiceDescription::Direct(
733+
Description::new("test".to_string()).unwrap(),
734+
),
735+
invoice_expiry_delta_secs: Some(3600),
736+
route_hints_override,
737+
..Default::default()
738+
}
739+
}
740+
741+
#[test]
742+
fn test_create_bolt11_invoice_route_hints_override() {
743+
let chanmon_cfgs = create_chanmon_cfgs(2);
744+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
745+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
746+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
747+
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 10_001);
748+
749+
let invoice = nodes[1]
750+
.node
751+
.create_bolt11_invoice(make_route_hints_override_test_params(None))
752+
.unwrap();
753+
let chan = &nodes[1].node.list_usable_channels()[0];
754+
assert_eq!(invoice.route_hints().len(), 1);
755+
assert_eq!(
756+
invoice.route_hints()[0].0[0].short_channel_id,
757+
chan.inbound_scid_alias.unwrap()
758+
);
759+
assert_eq!(invoice.route_hints()[0].0[0].htlc_minimum_msat, chan.inbound_htlc_minimum_msat);
760+
assert_eq!(invoice.route_hints()[0].0[0].htlc_maximum_msat, chan.inbound_htlc_maximum_msat);
761+
762+
let invoice = nodes[1]
763+
.node
764+
.create_bolt11_invoice(make_route_hints_override_test_params(Some(vec![])))
765+
.unwrap();
766+
assert!(invoice.route_hints().is_empty());
767+
768+
let custom_hint = RouteHint(vec![RouteHintHop {
769+
src_node_id: nodes[0].node.get_our_node_id(),
770+
short_channel_id: 42,
771+
fees: RoutingFees { base_msat: 1000, proportional_millionths: 500 },
772+
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA,
773+
htlc_minimum_msat: Some(1),
774+
htlc_maximum_msat: Some(1_000_000),
775+
}]);
776+
let invoice = nodes[1]
777+
.node
778+
.create_bolt11_invoice(make_route_hints_override_test_params(Some(vec![
779+
custom_hint.clone()
780+
])))
781+
.unwrap();
782+
assert_eq!(invoice.route_hints(), vec![custom_hint]);
783+
}
784+
727785
fn do_create_invoice_min_final_cltv_delta(with_custom_delta: bool) {
728786
let chanmon_cfgs = create_chanmon_cfgs(2);
729787
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);

0 commit comments

Comments
 (0)