From 9c5dccd79d80179cb623ea3e244206a8b3e8b39f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 27 Oct 2021 22:22:48 +0000 Subject: [PATCH] Add integration test for InvoicePayerretry on an immediate failure --- lightning-invoice/src/payment.rs | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index 028711a63..f75464689 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -1259,4 +1259,49 @@ mod tests { assert_eq!(htlc_msgs.len(), 2); check_added_monitors!(nodes[0], 2); } + + #[test] + fn immediate_retry_on_failure() { + // Tests that we can/will retry immediately after a failure + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known()); + let chans = nodes[0].node.list_usable_channels(); + let mut route = Route { + paths: vec![ + vec![RouteHop { + pubkey: nodes[1].node.get_our_node_id(), + node_features: NodeFeatures::known(), + short_channel_id: chans[0].short_channel_id.unwrap(), + channel_features: ChannelFeatures::known(), + fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than + cltv_expiry_delta: 100, + }], + ], + payee: Some(Payee::new(nodes[1].node.get_our_node_id())), + }; + let router = ManualRouter(RefCell::new(VecDeque::new())); + router.expect_find_route(Ok(route.clone())); + // On retry, split the payment across both channels. + route.paths.push(route.paths[0].clone()); + route.paths[0][0].short_channel_id = chans[1].short_channel_id.unwrap(); + route.paths[0][0].fee_msat = 50_000_000; + route.paths[1][0].fee_msat = 50_000_001; + router.expect_find_route(Ok(route.clone())); + + let event_handler = |_: &_| { panic!(); }; + let scorer = RefCell::new(TestScorer::new()); + let invoice_payer = InvoicePayer::new(nodes[0].node, router, &scorer, nodes[0].logger, event_handler, RetryAttempts(1)); + + assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager( + &nodes[1].node, nodes[1].keys_manager, Currency::Bitcoin, Some(100_010_000), "Invoice".to_string()).unwrap()) + .is_ok()); + let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events(); + assert_eq!(htlc_msgs.len(), 2); + check_added_monitors!(nodes[0], 2); + } } -- 2.39.5