]> git.bitcoin.ninja Git - ldk-java/commitdiff
Update tests and batteries for new 0.0.104 API, fix Java 18 build
authorMatt Corallo <git@bluematt.me>
Mon, 20 Dec 2021 07:18:32 +0000 (07:18 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 21 Dec 2021 04:29:40 +0000 (04:29 +0000)
As of this commit, leaks in the full test suite are:
    20 allocations remained for 1115206 bytes.

src/main/java/org/ldk/batteries/ChannelManagerConstructor.java
src/test/java/org/ldk/HumanObjectPeerTest.java
src/test/java/org/ldk/ManualMsgHandlingPeerTest.java
src/test/java/org/ldk/PeerTest.java

index 1ea16afc20a88a470a848b0f6359ee6a5f24d69d..7399ccb3fb18ffae950ca9e1ed445212dad88890 100644 (file)
@@ -184,7 +184,7 @@ public class ChannelManagerConstructor {
      * This also spawns a background thread which will call the appropriate methods on the provided
      * EventHandler as required.
      */
-    public void chain_sync_completed(EventHandler event_handler, @Nullable LockableScore scorer) {
+    public void chain_sync_completed(EventHandler event_handler, @Nullable MultiThreadedLockableScore scorer) {
         if (background_processor != null) { return; }
         for (TwoTuple_BlockHashChannelMonitorZ monitor: channel_monitors) {
             this.chain_monitor.as_Watch().watch_channel(monitor.get_b().get_funding_txo().get_a(), monitor.get_b());
index 58d707645fec969532c1daab1f2fdd85363d4f2e..948544b6f7868391055a0eb46352004aa2731ad6 100644 (file)
@@ -123,6 +123,11 @@ class HumanObjectPeerTestInstance {
                 public Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage) {
                     return underlying_if.sign_invoice(invoice_preimage);
                 }
+
+                @Override
+                public byte[] get_inbound_payment_key_material() {
+                    return underlying_if.get_inbound_payment_key_material();
+                }
             });
         }
 
@@ -139,8 +144,8 @@ class HumanObjectPeerTestInstance {
                     synchronized (monitors) {
                         String txid = Arrays.toString(funding_txo.get_txid());
                         assert monitors.containsKey(txid);
-                        Result_NoneMonitorUpdateErrorZ update_res = monitors.get(txid).update_monitor(update, tx_broadcaster, fee_estimator, logger);
-                        assert update_res instanceof Result_NoneMonitorUpdateErrorZ.Result_NoneMonitorUpdateErrorZ_OK;
+                        Result_NoneNoneZ update_res = monitors.get(txid).update_monitor(update, tx_broadcaster, fee_estimator, logger);
+                        assert update_res instanceof Result_NoneNoneZ.Result_NoneNoneZ_OK;
                     }
                     return Result_NoneChannelMonitorUpdateErrZ.ok();
                 }
@@ -206,7 +211,7 @@ class HumanObjectPeerTestInstance {
         }
 
         private Peer(Object _dummy, byte seed) {
-            logger = Logger.new_impl((Record arg)->{
+            logger = Logger.new_impl((org.ldk.structs.Record arg)->{
                 if (arg.get_level() == Level.LDKLevel_Error)
                     System.err.println(seed + ": " + arg.get_module_path() + " - " + arg.get_args());
                 else
@@ -353,8 +358,8 @@ class HumanObjectPeerTestInstance {
                     this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0,
                                                        this.keys_interface, this.fee_estimator, this.chain_monitor, this.router, this.tx_broadcaster, this.logger);
                 }
-                LockableScore scorer = null;
-                if (use_invoice_payer) { scorer = LockableScore.of(Scorer.with_default().as_Score()); }
+                MultiThreadedLockableScore scorer = null;
+                if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(Scorer.with_default().as_Score()); }
                 constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() {
                     @Override public void handle_event(Event event) {
                         synchronized (pending_manager_events) {
@@ -376,12 +381,13 @@ class HumanObjectPeerTestInstance {
                 if (use_invoice_payer) {
                     this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() {
                         @Override
-                        public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer) {
+                        public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, byte[] payment_hash, ChannelDetails[] first_hops, Score scorer) {
                             return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer);
                         }
-                    }), LockableScore.of(Score.new_impl(new Score.ScoreInterface() {
+                    }), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() {
                         @Override public void payment_path_failed(RouteHop[] path, long scid) {}
-                        @Override public long channel_penalty_msat(long scid, NodeId src, NodeId dst) { return 0; }
+                        @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, Option_u64Z channel_capacity_msat, NodeId source, NodeId target) { return 0; }
+                        @Override public void payment_path_successful(RouteHop[] path) {}
                         @Override public byte[] write() { assert false; return null; }
                     })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() {
                         @Override public void handle_event(Event event) {
@@ -430,8 +436,8 @@ class HumanObjectPeerTestInstance {
                             assert false;
                         } catch (ChannelManagerConstructor.InvalidSerializedDataException e) {}
                     }
-                    LockableScore scorer = null;
-                    if (use_invoice_payer) { scorer = LockableScore.of(Scorer.with_default().as_Score()); }
+                    MultiThreadedLockableScore scorer = null;
+                    if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(Scorer.with_default().as_Score()); }
                     constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() {
                         @Override public void handle_event(Event event) {
                             synchronized (pending_manager_events) {
@@ -484,12 +490,13 @@ class HumanObjectPeerTestInstance {
                 if (use_invoice_payer) {
                     this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() {
                         @Override
-                        public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer) {
+                        public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, byte[] _payment_hash, ChannelDetails[] first_hops, Score scorer) {
                             return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer);
                         }
-                    }), LockableScore.of(Score.new_impl(new Score.ScoreInterface() {
+                    }), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() {
+                        @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, Option_u64Z channel_capacity_msat, NodeId source, NodeId target) { return 0; }
                         @Override public void payment_path_failed(RouteHop[] path, long scid) {}
-                        @Override public long channel_penalty_msat(long scid, NodeId src, NodeId dst) { return 0; }
+                        @Override public void payment_path_successful(RouteHop[] path) {}
                         @Override public byte[] write() { assert false; return null; }
                     })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() {
                         @Override public void handle_event(Event event) {
@@ -593,9 +600,11 @@ class HumanObjectPeerTestInstance {
             if (use_chan_manager_constructor) {
                 while (res.length < expected_len) {
                     synchronized (this.pending_manager_events) {
-                        res = this.pending_manager_events.toArray(res);
-                        assert res.length == expected_len || res.length == 0; // We don't handle partial results
-                        this.pending_manager_events.clear();
+                        if (this.pending_manager_events.size() >= expected_len) {
+                            res = this.pending_manager_events.toArray(res);
+                            assert res.length == expected_len;
+                            this.pending_manager_events.clear();
+                        }
                         if (res.length < expected_len) {
                             try { this.pending_manager_events.wait(); } catch (InterruptedException e) { assert false; }
                         }
@@ -610,7 +619,6 @@ class HumanObjectPeerTestInstance {
                         peer2.nio_peer_handler.check_events();
                     }
                     chan_manager.as_EventsProvider().process_pending_events(EventHandler.new_impl(l::add));
-                    assert l.size() == expected_len || l.size() == 0; // We don't handle partial results
                 }
                 return l.toArray(new Event[0]);
             }
@@ -900,9 +908,11 @@ class HumanObjectPeerTestInstance {
         assert !Arrays.equals(payment_preimage, new byte[32]);
         state.peer2.chan_manager.claim_funds(payment_preimage);
 
-        events = state.peer1.get_manager_events(1, state.peer1, state.peer2);
+        events = state.peer1.get_manager_events(2, state.peer1, state.peer2);
         assert events[0] instanceof Event.PaymentSent;
         assert Arrays.equals(((Event.PaymentSent) events[0]).payment_preimage, payment_preimage);
+        assert events[1] instanceof Event.PaymentPathSuccessful;
+        assert Arrays.equals(((Event.PaymentPathSuccessful) events[1]).payment_hash, ((Event.PaymentSent) events[0]).payment_hash);
 
         if (use_nio_peer_handler) {
             // We receive PaymentSent immediately upon receipt of the payment preimage, but we expect to not have an
index ed01a847a3635e642a7bc95ba8081953920d4b9b..cbdf55eb967cea839eb1d157e5d89466d8ca2416 100644 (file)
@@ -165,7 +165,7 @@ public class ManualMsgHandlingPeerTest {
                 bindings.IgnoringMessageHandler_as_CustomMessageHandler(ignoring_message_handler));
 
         // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
-        assert bindings.Level_max() == Level.LDKLevel_Trace;
+        assert bindings.Level_max() == Level.LDKLevel_Gossip;
 
         // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
         bindings.Logger_free(logger);
index 28b5c75e3dab42f0539ccd3fc21eaf1fe0dd7402..cc51260d6bf46a748688517bb19ea6cd0c3b68db 100644 (file)
@@ -65,8 +65,8 @@ public class PeerTest {
                         String txid = Arrays.toString(bindings.OutPoint_get_txid(funding_txo));
                         assert monitors.containsKey(txid);
                         long update_res = bindings.ChannelMonitor_update_monitor(monitors.get(txid), update, tx_broadcaster, fee_estimator, logger);
-                        assert bindings.CResult_NoneMonitorUpdateErrorZ_is_ok(update_res);
-                        bindings.CResult_NoneMonitorUpdateErrorZ_free(update_res);
+                        assert bindings.CResult_NoneNoneZ_is_ok(update_res);
+                        bindings.CResult_NoneNoneZ_free(update_res);
                     }
                     bindings.OutPoint_free(funding_txo);
                     bindings.ChannelMonitorUpdate_free(update);
@@ -274,7 +274,9 @@ public class PeerTest {
         for (long chan : peer2_chans) bindings.ChannelDetails_free(chan);
 
         long no_min_val = bindings.COption_u64Z_none();
-        long inbound_payment = bindings.ChannelManager_create_inbound_payment(peer2.chan_manager, no_min_val, 7200, 42);
+        long inbound_payment = bindings.ChannelManager_create_inbound_payment(peer2.chan_manager, no_min_val, 7200);
+        assert bindings.CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_is_ok(inbound_payment);
+        long payment_tuple = bindings.LDKCResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_get_ok(inbound_payment);
         bindings.COption_u64Z_free(no_min_val);
         long scorer = bindings.Scorer_default();
         long scorer_interface = bindings.Scorer_as_Score(scorer);
@@ -295,9 +297,9 @@ public class PeerTest {
         for (long chan : peer1_chans) bindings.ChannelDetails_free(chan);
         assert bindings.CResult_RouteLightningErrorZ_is_ok(route);
         long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager, bindings.LDKCResult_RouteLightningErrorZ_get_ok(route),
-                bindings.C2Tuple_PaymentHashPaymentSecretZ_get_a(inbound_payment), bindings.C2Tuple_PaymentHashPaymentSecretZ_get_b(inbound_payment));
+                bindings.C2Tuple_PaymentHashPaymentSecretZ_get_a(payment_tuple), bindings.C2Tuple_PaymentHashPaymentSecretZ_get_b(payment_tuple));
         bindings.CResult_RouteLightningErrorZ_free(route);
-        bindings.C2Tuple_PaymentHashPaymentSecretZ_free(inbound_payment);
+        bindings.CResult_C2Tuple_PaymentHashPaymentSecretZNoneZ_is_ok(inbound_payment);
         assert bindings.CResult_NonePaymentSendFailureZ_is_ok(payment_res);
         bindings.CResult_NonePaymentSendFailureZ_free(payment_res);
 
@@ -322,10 +324,13 @@ public class PeerTest {
         deliver_peer_messages(list, peer1.peer_manager, peer2.peer_manager);
 
         bindings.EventsProvider_process_pending_events(peer1.chan_manager_events, handler);
-        assert events.size() == 1;
+        assert events.size() == 2;
         bindings.LDKEvent sent = bindings.LDKEvent_ref_from_ptr(events.get(0));
         assert sent instanceof bindings.LDKEvent.PaymentSent;
         bindings.Event_free(events.remove(0));
+        bindings.LDKEvent sent_path = bindings.LDKEvent_ref_from_ptr(events.get(0));
+        assert sent_path instanceof bindings.LDKEvent.PaymentPathSuccessful;
+        bindings.Event_free(events.remove(0));
 
         bindings.EventHandler_free(handler);