Update tests to new enum API
[ldk-java] / src / test / java / org / ldk / HumanObjectPeerTest.java
index 484f63b47350d0844c3dbc5d98ee967ab30a4644..5694bcf81cd16a503fbfd85c0d85c37d37f023eb 100644 (file)
@@ -126,7 +126,7 @@ class HumanObjectPeerTestInstance {
                     synchronized (monitors) {
                         assert monitors.put(Arrays.toString(funding_txo.get_txid()), monitor) == null;
                     }
-                    return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
+                    return Result_NoneChannelMonitorUpdateErrZ.constructor_ok();
                 }
 
                 public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {
@@ -136,7 +136,7 @@ class HumanObjectPeerTestInstance {
                         Result_NoneMonitorUpdateErrorZ update_res = monitors.get(txid).update_monitor(update, tx_broadcaster, fee_estimator, logger);
                         assert update_res instanceof Result_NoneMonitorUpdateErrorZ.Result_NoneMonitorUpdateErrorZ_OK;
                     }
-                    return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
+                    return Result_NoneChannelMonitorUpdateErrZ.constructor_ok();
                 }
 
                 @Override
@@ -174,6 +174,7 @@ class HumanObjectPeerTestInstance {
         final HashMap<String, ChannelMonitor> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
         byte[] node_id;
         final LinkedList<byte[]> broadcast_set = new LinkedList<>();
+        GcCheck obj = new GcCheck();
 
         private TwoTuple<OutPoint, byte[]> test_mon_roundtrip(ChannelMonitor mon) {
             // Because get_funding_txo() returns an OutPoint in a tuple that is a reference to an OutPoint inside the
@@ -204,7 +205,7 @@ class HumanObjectPeerTestInstance {
                         assert Arrays.equals(res.a.get_txid(), id.get_txid());
                         assert res.a.get_index() == id.get_index();
                     }
-                    return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
+                    return Result_NoneChannelMonitorUpdateErrZ.constructor_ok();
                 }
 
                 @Override
@@ -216,7 +217,7 @@ class HumanObjectPeerTestInstance {
                         assert Arrays.equals(res.a.get_txid(), id.get_txid());
                         assert res.a.get_index() == id.get_index();
                     }
-                    return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
+                    return Result_NoneChannelMonitorUpdateErrZ.constructor_ok();
                 }
             });
 
@@ -226,8 +227,9 @@ class HumanObjectPeerTestInstance {
                     @Override public void register_tx(byte[] txid, byte[] script_pubkey) {
                         filter_additions.add(Arrays.toString(txid));
                     }
-                    @Override public void register_output(OutPoint outpoint, byte[] script_pubkey) {
-                        filter_additions.add(Arrays.toString(outpoint.get_txid()) + ":" + outpoint.get_index());
+                    @Override public Option_C2Tuple_usizeTransactionZZ register_output(WatchedOutput output) {
+                        filter_additions.add(Arrays.toString(output.get_outpoint().get_txid()) + ":" + output.get_outpoint().get_index());
+                        return Option_C2Tuple_usizeTransactionZZ.constructor_none();
                     }
                 });
             } else {
@@ -548,12 +550,15 @@ class HumanObjectPeerTestInstance {
         wait_events_processed(peer1, peer2);
 
         peer1.chan_manager.list_channels();
-        ChannelDetails[] peer1_chans = peer1.chan_manager.list_channels();
-        ChannelDetails[] peer2_chans = peer2.chan_manager.list_channels();
+        ChannelDetails[] peer1_chans = peer1.chan_manager.list_usable_channels();
+        ChannelDetails[] peer2_chans = peer2.chan_manager.list_usable_channels();
         assert peer1_chans.length == 1;
         assert peer2_chans.length == 1;
         assert peer1_chans[0].get_channel_value_satoshis() == 10000;
         assert peer1_chans[0].get_is_live();
+        Option_u64Z short_chan_id = peer1_chans[0].get_short_channel_id();
+        assert short_chan_id instanceof Option_u64Z.Some;
+        assert ((Option_u64Z.Some)short_chan_id).some == (1L << 40); // 0th output in the 0th transaction in the 1st block
         assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
         assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
 
@@ -683,11 +688,13 @@ class HumanObjectPeerTestInstance {
     }
 
     java.util.LinkedList<WeakReference<Object>> must_free_objs = new java.util.LinkedList();
-    boolean gc_ran = false;
+    int gc_count = 0;
+    int gc_exp_count = 0;
     class GcCheck {
+        GcCheck() { gc_exp_count += 1; }
         @Override
         protected void finalize() throws Throwable {
-            gc_ran = true;
+            gc_count += 1;
             super.finalize();
         }
     }
@@ -701,7 +708,7 @@ public class HumanObjectPeerTest {
     }
     void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler) throws InterruptedException {
         HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler);
-        while (!instance.gc_ran) {
+        while (instance.gc_count != instance.gc_exp_count) {
             System.gc();
             System.runFinalization();
         }