Merge pull request #50 from TheBlueMatt/main
[ldk-java] / src / test / java / org / ldk / HumanObjectPeerTest.java
index f37b671bc526b735ffea53577d5fb4ac771715cf..261902b7f059197387feae6e9b6b78fbfdcac770 100644 (file)
@@ -659,8 +659,8 @@ class HumanObjectPeerTestInstance {
 
         connect_peers(peer1, peer2);
 
-        Result_NoneAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, 42, null);
-        assert cc_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK;
+        Result__u832APIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, 42, null);
+        assert cc_res instanceof Result__u832APIErrorZ.Result__u832APIErrorZ_OK;
 
         // Previously, this was a SEGFAULT instead of get_funding_txo() returning null.
         ChannelDetails pre_funding_chan = peer1.chan_manager.list_channels()[0];
@@ -741,15 +741,17 @@ class HumanObjectPeerTestInstance {
         InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features();
         RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints();
 
-        Result_RouteLightningErrorZ route_res = UtilMethods.get_route(peer1.chan_manager.get_our_node_id(), peer1.router.get_network_graph(), peer2.node_id, invoice_features, peer1_chans, route_hints, 10000000, 42, peer1.logger);
+        Result_RouteLightningErrorZ route_res = UtilMethods.get_route(
+                peer1.chan_manager.get_our_node_id(), peer1.router.get_network_graph(), peer2.node_id, invoice_features,
+                peer1_chans, route_hints, 10000000, 42, peer1.logger, Scorer.with_default().as_Score());
         assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK;
         Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res;
         assert route.get_paths().length == 1;
         assert route.get_paths()[0].length == 1;
         assert route.get_paths()[0][0].get_fee_msat() == 10000000;
 
-        Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
-        assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
+        Result_PaymentIdPaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
+        assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_OK;
 
         RouteHop[][] hops = new RouteHop[1][1];
         byte[] hop_pubkey = new byte[33];
@@ -758,7 +760,7 @@ class HumanObjectPeerTestInstance {
         hops[0][0] = RouteHop.of(hop_pubkey, NodeFeatures.known(), 42, ChannelFeatures.known(), 100, 0);
         Route r2 = Route.of(hops);
         payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret);
-        assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
+        assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err;
 
         if (reload_peers) {
             if (use_chan_manager_constructor) {
@@ -860,6 +862,11 @@ class HumanObjectPeerTestInstance {
             assert state.peer2.broadcast_set.size() == 1;
         }
 
+        events = state.peer2.get_manager_events(1, state.peer1, state.peer2);
+        assert events[0] instanceof Event.ChannelClosed;
+        events = state.peer1.get_manager_events(1, state.peer1, state.peer2);
+        assert events[0] instanceof Event.ChannelClosed;
+
         if (state.peer1.chain_monitor != null) {
             Balance[] peer1_balances = state.peer1.chain_monitor.get_claimable_balances(state.peer1.chan_manager.list_channels());
             assert peer1_balances.length == 1;
@@ -914,19 +921,22 @@ class HumanObjectPeerTestInstance {
             }
         }
 
-        // Test exchanging a custom message
-        byte[] custom_message_bytes = new byte[] { 0x42, 0x44, 0x43, 0x00 };
-        state.peer1.custom_messages_to_send.add(custom_message_bytes);
-        state.peer1.peer_manager.process_events();
-        synchronized (state.peer2.received_custom_messages) {
-            while (true) {
-                if (state.peer2.received_custom_messages.isEmpty()) {
-                    state.peer2.received_custom_messages.wait();
-                    continue;
+        // Test exchanging a custom message (note that ChannelManagerConstructor) always loads an IgnorimgMessageHandler
+        // so we cannot exchange custom messages with it
+        if (!use_chan_manager_constructor) {
+            byte[] custom_message_bytes = new byte[]{0x42, 0x44, 0x43, 0x00};
+            state.peer1.custom_messages_to_send.add(custom_message_bytes);
+            state.peer1.peer_manager.process_events();
+            synchronized (state.peer2.received_custom_messages) {
+                while (true) {
+                    if (state.peer2.received_custom_messages.isEmpty()) {
+                        state.peer2.received_custom_messages.wait();
+                        continue;
+                    }
+                    assert state.peer2.received_custom_messages.size() == 1;
+                    assert Arrays.equals(state.peer2.received_custom_messages.get(0), custom_message_bytes);
+                    break;
                 }
-                assert state.peer2.received_custom_messages.size() == 1;
-                assert Arrays.equals(state.peer2.received_custom_messages.get(0), custom_message_bytes);
-                break;
             }
         }
 
@@ -985,7 +995,7 @@ public class HumanObjectPeerTest {
     }
     @Test
     public void test_message_handler() throws InterruptedException {
-        for (int i = 0; i < (1 << 7) - 1; i++) {
+        for (int i = 0; i < (1 << 8) - 1; i++) {
             boolean nice_close =                   (i & (1 << 0)) != 0;
             boolean use_km_wrapper =               (i & (1 << 1)) != 0;
             boolean use_manual_watch =             (i & (1 << 2)) != 0;