]> git.bitcoin.ninja Git - ldk-java/commitdiff
Use newly-exposed get_route in HumanObjectPeerTest
authorMatt Corallo <git@bluematt.me>
Mon, 7 Jun 2021 21:16:17 +0000 (21:16 +0000)
committerMatt Corallo <git-ldk-build@bluematt.me>
Tue, 8 Jun 2021 21:25:20 +0000 (21:25 +0000)
src/test/java/org/ldk/HumanObjectPeerTest.java

index 742d388ec8c29047cc8c3744e35340775ff8d9cf..b1661d17ce154886fd729a16e2adbd63bb8fc82e 100644 (file)
@@ -470,21 +470,6 @@ class HumanObjectPeerTestInstance {
             assert res.length == expected_len;
             return res;
         }
-
-        Route get_route(byte[] dest_node, ChannelDetails[] our_chans) {
-            try (LockedNetworkGraph netgraph = this.router.read_locked_graph()) {
-                NetworkGraph graph = netgraph.graph();
-                long res = bindings.get_route(this.node_id, graph._test_only_get_ptr(), dest_node, 0L, new long[]{our_chans[0]._test_only_get_ptr()},
-                        new long[0], 1000000, 42, this.logger._test_only_get_ptr());
-                assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(res);
-                byte[] serialized_route = bindings.Route_write(bindings.LDKCResult_RouteLightningErrorZ_get_ok(res));
-                must_free_objs.add(new WeakReference<>(serialized_route));
-                Result_RouteDecodeErrorZ copy = Route.read(serialized_route);
-                assert copy instanceof Result_RouteDecodeErrorZ.Result_RouteDecodeErrorZ_OK;
-                bindings.CResult_RouteLightningErrorZ_free(res);
-                return ((Result_RouteDecodeErrorZ.Result_RouteDecodeErrorZ_OK) copy).res;
-            }
-        }
     }
 
     static class DescriptorHolder { SocketDescriptor val; }
@@ -664,8 +649,25 @@ class HumanObjectPeerTestInstance {
         assert description_string.equals("Invoice Description");
         byte[] payment_hash = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash();
         byte[] payment_secret = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_secret();
+        byte[] dest_node_id = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.recover_payee_pub_key();
+        assert Arrays.equals(dest_node_id, peer2.node_id);
+        InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features();
+        ArrayList<RouteHintHop> invoice_hops = new ArrayList<RouteHintHop>();
+        for (RouteHint hint: ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.routes()) {
+            RouteHintHop[] hops = hint.into_inner();
+            if (hops.length == 1) {
+                invoice_hops.add(hops[0]);
+            }
+        }
+
+        Route route;
+        try (LockedNetworkGraph netgraph = peer1.router.read_locked_graph()) {
+            NetworkGraph graph = netgraph.graph();
+            Result_RouteLightningErrorZ route_res = UtilMethods.get_route(peer1.chan_manager.get_our_node_id(), graph, peer2.node_id, invoice_features, peer1_chans, invoice_hops.toArray(new RouteHintHop[0]), 1000000, 42, peer1.logger);
+            assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK;
+            route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res;
+        }
 
-        Route route = peer1.get_route(peer2.node_id, peer1_chans);
         Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
         assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
         wait_events_processed(peer1, peer2);