Add integration test for InvoicePayerretry on an immediate failure
authorMatt Corallo <git@bluematt.me>
Wed, 27 Oct 2021 22:22:48 +0000 (22:22 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 31 Oct 2021 17:43:26 +0000 (17:43 +0000)
lightning-invoice/src/payment.rs

index 028711a630e65587f291d2df783c1dd51fbdf980..f75464689ec73b425f2f1651e39f3d829376c81e 100644 (file)
@@ -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);
+       }
 }