]> git.bitcoin.ninja Git - ldk-java/commitdiff
Test current state of things, which actually doesn't crash!
authorMatt Corallo <git@bluematt.me>
Mon, 31 Aug 2020 22:44:53 +0000 (18:44 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 31 Aug 2020 22:44:53 +0000 (18:44 -0400)
genbindings.py
pom.xml
src/main/java/org/ldk/impl/bindings.java
src/main/jni/bindings.c
src/main/jni/org_ldk_impl_bindings.h
src/test/java/org/ldk/PeerTest.java [new file with mode: 0644]

index 838bd2710a9c98448f6afb8b529f441009dcdc9e..cf033916ee719da00482740e0f8f33fd109f63f1 100755 (executable)
@@ -290,6 +290,13 @@ public class bindings {
     out_c.write("#include <string.h>\n")
     out_c.write("#include <stdatomic.h>\n\n")
 
+    # XXX: Temporarily write out a manual SecretKey_new() for testing, we should auto-gen this kind of thing
+    out_java.write("\tpublic static native long LDKSecretKey_new();\n\n") # TODO: rm me
+    out_c.write("JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSecretKey_1new(JNIEnv * _env, jclass _b) {\n") # TODO: rm me
+    out_c.write("\tLDKSecretKey* key = (LDKSecretKey*)malloc(sizeof(LDKSecretKey));\n") # TODO: rm me
+    out_c.write("\treturn (long)key;\n") # TODO: rm me
+    out_c.write("}\n") # TODO: rm me
+
     in_block_comment = False
     in_block_enum = False
     cur_block_struct = None
diff --git a/pom.xml b/pom.xml
index 4e98b6e8dcb31b46b974168b8d5a5e3c3a636c02..6b3f1a89bc3fa022b0a90771797c28c35927749b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,9 +7,23 @@
     <groupId>org.ldk</groupId>
     <artifactId>ldk-java</artifactId>
     <version>1.0-SNAPSHOT</version>
+    <dependencies>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
     <properties>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
     </properties>
 
-</project>
\ No newline at end of file
+</project>
index 9a9963cd7e1f74ef69dd32e5c3f673c170c6d0f4..947468c35abb8269d2eed8762519dbd9a40f9964 100644 (file)
@@ -5,6 +5,8 @@ public class bindings {
                System.loadLibrary("lightningjni");
        }
 
+       public static native long LDKSecretKey_new();
+
        public interface LDKMessageSendEventsProvider {
                 long get_and_clear_pending_msg_events();
        }
index 1edd94344500677394c1a742f24f780d0dd755f0..d88ef8f7723f710cce06731d4d87175d0e78f4aa 100644 (file)
@@ -5,6 +5,10 @@
 #include <string.h>
 #include <stdatomic.h>
 
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSecretKey_1new(JNIEnv * _env, jclass _b) {
+       LDKSecretKey* key = (LDKSecretKey*)malloc(sizeof(LDKSecretKey));
+       return (long)key;
+}
 typedef struct LDKMessageSendEventsProvider_JCalls {
        atomic_size_t refcnt;
        JNIEnv *env;
index d2dd2e89c453c294d9a30988a7d208482d3f1098..cafe0b4e9b47cc184b26228f6d32da8998b805e1 100644 (file)
@@ -7,6 +7,14 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+/*
+ * Class:     org_ldk_impl_bindings
+ * Method:    LDKSecretKey_new
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSecretKey_1new
+  (JNIEnv *, jclass);
+
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    LDKMessageSendEventsProvider_new
diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java
new file mode 100644 (file)
index 0000000..b241644
--- /dev/null
@@ -0,0 +1,145 @@
+package org.ldk;
+
+import org.junit.jupiter.api.Test;
+import org.ldk.impl.bindings;
+
+public class PeerTest {
+    @Test
+    void test_message_handler() {
+        long logger = bindings.LDKLogger_new((String arg)->{
+            System.out.println(arg);
+        });
+        long chan_handler = bindings.LDKChannelMessageHandler_new(new bindings.LDKChannelMessageHandler() {
+            @Override
+            public void handle_open_channel(long their_node_id, long their_features, long msg) {
+
+            }
+
+            @Override
+            public void handle_accept_channel(long their_node_id, long their_features, long msg) {
+
+            }
+
+            @Override
+            public void handle_funding_created(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_funding_signed(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_funding_locked(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_shutdown(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_closing_signed(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_update_add_htlc(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_update_fulfill_htlc(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_update_fail_htlc(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_update_fail_malformed_htlc(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_commitment_signed(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_revoke_and_ack(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_update_fee(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_announcement_signatures(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void peer_disconnected(long their_node_id, boolean no_connection_possible) {
+
+            }
+
+            @Override
+            public void peer_connected(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_channel_reestablish(long their_node_id, long msg) {
+
+            }
+
+            @Override
+            public void handle_error(long their_node_id, long msg) {
+
+            }
+        }, () -> 0);
+        long route_handler = bindings.LDKRoutingMessageHandler_new(new bindings.LDKRoutingMessageHandler() {
+            @Override public long handle_node_announcement(long msg) {
+                return 0;
+            }
+            @Override public long handle_channel_announcement(long msg) {
+                return 0;
+            }
+            @Override public long handle_channel_update(long msg) {
+                return 0;
+            }
+            @Override public void handle_htlc_fail_channel_update(long update) {
+
+            }
+            @Override public long get_next_channel_announcements(long starting_point, byte batch_amount) {
+                return 0;
+            }
+            @Override public long get_next_node_announcements(long starting_point, byte batch_amount) {
+                return 0;
+            }
+            @Override public boolean should_request_full_sync(long node_id) {
+                return false;
+            }
+        });
+        long message_handler = bindings.MessageHandler_new(chan_handler, route_handler);
+        long our_node_secret = bindings.LDKSecretKey_new(); //TODO: Need LDKSecretKey constructor
+        byte[] random_data = new byte[32];
+        for (byte i = 0; i < 32; i++) { random_data[i] = i; }
+
+        long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, random_data, logger);
+
+        // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
+        bindings.Logger_free(logger);
+        bindings.ChannelMessageHandler_free(chan_handler);
+        bindings.RoutingMessageHandler_free(route_handler);
+        //bindings.MessageHandler_free(message_handler);
+        bindings.PeerManager_free(peer_manager);
+    }
+}