From: Matt Corallo Date: Mon, 31 Aug 2020 22:44:53 +0000 (-0400) Subject: Test current state of things, which actually doesn't crash! X-Git-Tag: v0.0.1~152 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=323d540882dfdae8247d4e7f2477b39c82380491;p=ldk-java Test current state of things, which actually doesn't crash! --- diff --git a/genbindings.py b/genbindings.py index 838bd271..cf033916 100755 --- a/genbindings.py +++ b/genbindings.py @@ -290,6 +290,13 @@ public class bindings { out_c.write("#include \n") out_c.write("#include \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 4e98b6e8..6b3f1a89 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,23 @@ org.ldk ldk-java 1.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + 1.8 1.8 - \ No newline at end of file + diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index 9a9963cd..947468c3 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -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(); } diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index 1edd9434..d88ef8f7 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -5,6 +5,10 @@ #include #include +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; diff --git a/src/main/jni/org_ldk_impl_bindings.h b/src/main/jni/org_ldk_impl_bindings.h index d2dd2e89..cafe0b4e 100644 --- a/src/main/jni/org_ldk_impl_bindings.h +++ b/src/main/jni/org_ldk_impl_bindings.h @@ -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 index 00000000..b2416442 --- /dev/null +++ b/src/test/java/org/ldk/PeerTest.java @@ -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); + } +}