]> git.bitcoin.ninja Git - ldk-java/commitdiff
Update tests and Constructor to new APIs
authorMatt Corallo <git@bluematt.me>
Mon, 7 Jun 2021 03:19:07 +0000 (03:19 +0000)
committerMatt Corallo <git-ldk-build@bluematt.me>
Tue, 8 Jun 2021 20:26:10 +0000 (20:26 +0000)
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 7a8ce06e3f940491a3a0eed8d29ce28994002785..d55854084053b629f50e2de311fe8a9c04b1c37b 100644 (file)
@@ -1,7 +1,7 @@
 package org.ldk.batteries;
 
 import org.jetbrains.annotations.Nullable;
-import org.ldk.enums.LDKNetwork;
+import org.ldk.enums.Network;
 import org.ldk.structs.*;
 import org.ldk.util.TwoTuple;
 
@@ -100,10 +100,10 @@ public class ChannelManagerConstructor {
     /**
      * Constructs a channel manager from the given interface implementations
      */
-    public ChannelManagerConstructor(LDKNetwork network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height,
+    public ChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height,
                                      KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
                                      @Nullable NetGraphMsgHandler router,
-                                     BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
+                                     BroadcasterInterface tx_broadcaster, Logger logger) {
         channel_monitors = new TwoTuple[0];
         channel_manager_latest_block_hash = null;
         this.chain_monitor = chain_monitor;
index 2de305844ee33eb8f4d9d6e6416cf4fdb6f79af9..576f6d338a2475e2834dfa3a3104426587a0b9c6 100644 (file)
@@ -5,8 +5,8 @@ import org.bitcoinj.script.Script;
 import org.junit.jupiter.api.Test;
 import org.ldk.batteries.ChannelManagerConstructor;
 import org.ldk.batteries.NioPeerHandler;
-import org.ldk.enums.LDKCurrency;
-import org.ldk.enums.LDKNetwork;
+import org.ldk.enums.Currency;
+import org.ldk.enums.Network;
 import org.ldk.impl.bindings;
 import org.ldk.structs.*;
 import org.ldk.util.TwoTuple;
@@ -287,26 +287,22 @@ class HumanObjectPeerTestInstance {
         Peer(byte seed) {
             this(null, seed);
             if (use_chan_manager_constructor) {
-                try {
-                    this.constructor = new ChannelManagerConstructor(LDKNetwork.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);
-                    constructor.chain_sync_completed(new ChannelManagerConstructor.ChannelManagerPersister() {
-                        @Override public void handle_event(Event event) {
-                            synchronized (pending_manager_events) {
-                                pending_manager_events.add(event);
-                                pending_manager_events.notifyAll();
-                            }
+                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);
+                constructor.chain_sync_completed(new ChannelManagerConstructor.ChannelManagerPersister() {
+                    @Override public void handle_event(Event event) {
+                        synchronized (pending_manager_events) {
+                            pending_manager_events.add(event);
+                            pending_manager_events.notifyAll();
                         }
-                        @Override public void persist_manager(byte[] channel_manager_bytes) { }
-                    });
-                    this.chan_manager = constructor.channel_manager;
-                    this.peer_manager = constructor.peer_manager;
-                    must_free_objs.add(new WeakReference<>(this.chan_manager));
-                } catch (ChannelManagerConstructor.InvalidSerializedDataException e) {
-                    assert false;
-                }
+                    }
+                    @Override public void persist_manager(byte[] channel_manager_bytes) { }
+                });
+                this.chan_manager = constructor.channel_manager;
+                this.peer_manager = constructor.peer_manager;
+                must_free_objs.add(new WeakReference<>(this.chan_manager));
             } else {
-                ChainParameters params = ChainParameters.of(LDKNetwork.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0));
+                ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0));
                 this.chan_manager = ChannelManager.of(this.fee_estimator, chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.with_default(), params);
                 byte[] random_data = keys_interface.get_secure_random_bytes();
                 this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
@@ -653,9 +649,10 @@ class HumanObjectPeerTestInstance {
         assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
         assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
 
-        Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, LDKCurrency.LDKCurrency_Bitcoin, Option_u64Z.none(), "Invoice Description");
+        Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.none(), "Invoice Description");
         assert invoice instanceof Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK;
         System.out.println("Got invoice: " + ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str());
+
         Result_InvoiceNoneZ parsed_invoice = Invoice.from_str(((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str());
         assert parsed_invoice instanceof Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK;
         assert Arrays.equals(((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) parsed_invoice).res.payment_hash(), ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash());
index 12fa620e13374da23a0481e7eb6a0a0d1af03e27..091186b89daa23b673fa618c448111fbda7e23e7 100644 (file)
@@ -164,7 +164,7 @@ public class ManualMsgHandlingPeerTest {
         long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, random_data, logger);
 
         // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
-        assert bindings.Level_max() == LDKLevel.LDKLevel_Trace;
+        assert bindings.Level_max() == Level.LDKLevel_Trace;
 
         // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
         bindings.Logger_free(logger);
index e992e53398a6145cb3de3e64b549c5f2463f3e9e..60041991e7a620e741186daf51dfbe3934b8fad8 100644 (file)
@@ -3,7 +3,7 @@ package org.ldk;
 import org.bitcoinj.core.*;
 import org.bitcoinj.script.Script;
 import org.junit.jupiter.api.Test;
-import org.ldk.enums.LDKNetwork;
+import org.ldk.enums.Network;
 import org.ldk.impl.bindings;
 
 import java.util.ArrayList;
@@ -92,7 +92,7 @@ public class PeerTest {
             this.keys = bindings.KeysManager_new(key_seed, System.currentTimeMillis() / 1000, (int)(System.currentTimeMillis() * 1000) & 0xffffffff);
             this.keys_interface = bindings.KeysManager_as_KeysInterface(keys);
             this.config = bindings.UserConfig_default();
-            long params = bindings.ChainParameters_new(LDKNetwork.LDKNetwork_Bitcoin, bindings.BestBlock_new(new byte[32], 0));
+            long params = bindings.ChainParameters_new(Network.LDKNetwork_Bitcoin, bindings.BestBlock_new(new byte[32], 0));
             this.chan_manager = bindings.ChannelManager_new(fee_estimator, chain_monitor, tx_broadcaster, logger, keys_interface, config, params);
             this.node_id = bindings.ChannelManager_get_our_node_id(chan_manager);
             this.chan_manager_events = bindings.ChannelManager_as_EventsProvider(chan_manager);