Go all the way through to channel creation in PeerTest
authorMatt Corallo <git@bluematt.me>
Tue, 6 Oct 2020 23:25:17 +0000 (19:25 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 6 Oct 2020 23:25:17 +0000 (19:25 -0400)
genbindings.py
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

index a230ca09c456688f3d186b50e264932dd4c1e307..b4f9323db3b6b6eb44d77395aa81f7d97213e41c 100755 (executable)
@@ -545,6 +545,7 @@ void __attribute__((destructor)) check_leaks() {
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
        public static native long vec_slice_len(long vec);
+       public static native long new_empty_slice_vec();
 
 """)
     out_c.write("""
@@ -585,6 +586,17 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env
        LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
        return (long)vec->datalen;
 }
+JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
+        // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
+       LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
+       vec->data = NULL;
+       vec->datalen = 0;
+       return (long)vec;
+}
 
 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
index 4e4ba083e41a37d0bf1dd87f3335153116458240..6ff047a13fbed1846526d8fbce71235660639a42 100644 (file)
@@ -14,6 +14,7 @@ public class bindings {
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
        public static native long vec_slice_len(long vec);
+       public static native long new_empty_slice_vec();
 
        public static native long LDKSecretKey_new();
 
index a1a0506d558fa981eb9669d1357af06e1b9a5e37..dcbd2cc58b6527417349906e3d8286b749d328ac 100644 (file)
@@ -86,6 +86,17 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env
        LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
        return (long)vec->datalen;
 }
+JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
+        // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
+       LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
+       vec->data = NULL;
+       vec->datalen = 0;
+       return (long)vec;
+}
 
 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
index a68656f67287e3ea6a0afc24ae32a4b6bcfa08c2..c7b69658a5d8cfcab3ed039ecaa9c6da09adee9e 100644 (file)
@@ -63,6 +63,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len
   (JNIEnv *, jclass, jlong);
 
+/*
+ * Class:     org_ldk_impl_bindings
+ * Method:    new_empty_slice_vec
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec
+  (JNIEnv *, jclass);
+
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    LDKSecretKey_new
index c082a7c86bfd0307c9db5910defaa4cb9a7dc2c3..3420de0b97c29094d237b3415755ff99f7e75d50 100644 (file)
@@ -30,17 +30,17 @@ public class PeerTest {
             this.chain_monitor = bindings.LDKWatch_new(new bindings.LDKWatch() {
                 @Override
                 public long watch_channel(long funding_txo, long monitor) {
-                    return 0;
+                    return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok();
                 }
 
                 @Override
                 public long update_channel(long funding_txo, long update) {
-                    return 0;
+                    return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok();
                 }
 
                 @Override
                 public long release_pending_monitor_events() {
-                    return 0;
+                    return bindings.new_empty_slice_vec();
                 }
             });
 
@@ -134,9 +134,23 @@ public class PeerTest {
         do_read_event(list, peer2.peer_manager, descriptor2, bindings.LDKCResult_CVec_u8ZPeerHandleErrorZ_get_inner(init_vec));
         bindings.CResult_CVec_u8ZPeerHandleErrorZ_free(init_vec);
 
-        while (!list.isEmpty()) {
-            list.poll().join();
-        }
+        while (!list.isEmpty()) { list.poll().join(); }
+
+        long cc_res = bindings.ChannelManager_create_channel(peer1.chan_manager, bindings.ChannelManager_get_our_node_id(peer2.chan_manager), 10000, 1000, 0, bindings.LDKUserConfig_optional_none());
+        assert bindings.LDKCResult_NoneAPIErrorZ_result_ok(cc_res);
+        bindings.CResult_NoneAPIErrorZ_free(cc_res);
+
+        bindings.PeerManager_process_events(peer1.peer_manager);
+        while (!list.isEmpty()) { list.poll().join(); }
+        bindings.PeerManager_process_events(peer2.peer_manager);
+        while (!list.isEmpty()) { list.poll().join(); }
+
+        long peer1_chans = bindings.ChannelManager_list_channels(peer1.chan_manager);
+        long peer2_chans = bindings.ChannelManager_list_channels(peer2.chan_manager);
+        assert bindings.vec_slice_len(peer1_chans) == 1;
+        assert bindings.vec_slice_len(peer2_chans) == 1;
+        bindings.CVec_ChannelDetailsZ_free(peer1_chans);
+        bindings.CVec_ChannelDetailsZ_free(peer2_chans);
 
         peer1.free();
         peer2.free();