Clarify decode_update_add_htlc_onion comment
[rust-lightning] / lightning / src / ln / functional_tests.rs
index 359ba40fb0d7ddc58963bc3639adf8ae1d2a509b..d866693ffec93a73dc54ac085bedbf66db663da9 100644 (file)
@@ -23,7 +23,7 @@ use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOr
 use ln::channel::{Channel, ChannelError};
 use ln::{chan_utils, onion_utils};
 use ln::chan_utils::HTLC_SUCCESS_TX_WEIGHT;
-use routing::router::{Route, RouteHop, RouteHint, RouteHintHop, get_route};
+use routing::router::{Route, RouteHop, RouteHint, RouteHintHop, get_route, get_keysend_route};
 use routing::network_graph::RoutingFees;
 use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
 use ln::msgs;
@@ -4197,7 +4197,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) {
                assert_eq!(events.len(), 1);
                // Now do the relevant commitment_signed/RAA dances along the path, noting that the final
                // hop should *not* yet generate any PaymentReceived event(s).
-               pass_along_path(&nodes[0], &[&nodes[1]], 100000, our_payment_hash, payment_secret, events.drain(..).next().unwrap(), false, None);
+               pass_along_path(&nodes[0], &[&nodes[1]], 100000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
                our_payment_hash
        } else {
                route_payment(&nodes[0], &[&nodes[1]], 100000).1
@@ -9623,6 +9623,36 @@ fn test_keysend_payments_to_public_node() {
        assert_eq!(events.len(), 1);
        let event = events.pop().unwrap();
        let path = vec![&nodes[1]];
-       pass_along_path(&nodes[0], &path, 10000, payment_hash, PaymentSecret([0; 32]), event, true, Some(test_preimage));
+       pass_along_path(&nodes[0], &path, 10000, payment_hash, None, event, true, Some(test_preimage));
+       claim_payment(&nodes[0], &path, test_preimage);
+}
+
+#[test]
+fn test_keysend_payments_to_private_node() {
+       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]);
+       let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+       let payer_pubkey = nodes[0].node.get_our_node_id();
+       let payee_pubkey = nodes[1].node.get_our_node_id();
+       nodes[0].node.peer_connected(&payee_pubkey, &msgs::Init { features: InitFeatures::known() });
+       nodes[1].node.peer_connected(&payer_pubkey, &msgs::Init { features: InitFeatures::known() });
+
+       let _chan = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known());
+       let network_graph = nodes[0].net_graph_msg_handler.network_graph.read().unwrap();
+       let first_hops = nodes[0].node.list_usable_channels();
+       let route = get_keysend_route(&payer_pubkey, &network_graph, &payee_pubkey,
+                                Some(&first_hops.iter().collect::<Vec<_>>()), &vec![], 10000, 40,
+                                nodes[0].logger).unwrap();
+
+       let test_preimage = PaymentPreimage([42; 32]);
+       let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
+       check_added_monitors!(nodes[0], 1);
+       let mut events = nodes[0].node.get_and_clear_pending_msg_events();
+       assert_eq!(events.len(), 1);
+       let event = events.pop().unwrap();
+       let path = vec![&nodes[1]];
+       pass_along_path(&nodes[0], &path, 10000, payment_hash, None, event, true, Some(test_preimage));
        claim_payment(&nodes[0], &path, test_preimage);
 }