]> git.bitcoin.ninja Git - ldk-java/commitdiff
[TS] Update tests and node-net for new LDK 0.0.117 API
authorMatt Corallo <git@bluematt.me>
Fri, 6 Oct 2023 17:55:17 +0000 (17:55 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 7 Oct 2023 17:23:07 +0000 (17:23 +0000)
node-net/net.mts
node-net/test/test.mts
ts/test/tests.mts

index 9e16ab32601da75ded82e13e98d505ee9f27fac5..c70bf8f077ab1b7c6c416b3ea957175d8e9c123d 100644 (file)
@@ -97,11 +97,11 @@ export class NodeLDKNet {
                return descriptor;
        }
 
-       private static v4_addr_from_ip(ip: string, port: number): ldk.NetAddress {
+       private static v4_addr_from_ip(ip: string, port: number): ldk.SocketAddress {
                const sockaddr = ip.split(".").map(parseFloat);
-               return ldk.NetAddress.constructor_ipv4(new Uint8Array(sockaddr), port);
+               return ldk.SocketAddress.constructor_tcp_ip_v4(new Uint8Array(sockaddr), port);
        }
-       private static v6_addr_from_ip(ip: string, port: number): ldk.NetAddress {
+       private static v6_addr_from_ip(ip: string, port: number): ldk.SocketAddress {
                const sockaddr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
                const halves = ip.split("::"); // either one or two elements
                const first_half = halves[0].split(":");
@@ -118,20 +118,20 @@ export class NodeLDKNet {
                                sockaddr[15 - idx*2] = v & 0xff;
                        }
                }
-               return ldk.NetAddress.constructor_ipv6(new Uint8Array(sockaddr), port);
+               return ldk.SocketAddress.constructor_tcp_ip_v6(new Uint8Array(sockaddr), port);
        }
 
-       private static get_addr_from_socket(socket: net.Socket): ldk.Option_NetAddressZ {
+       private static get_addr_from_socket(socket: net.Socket): ldk.Option_SocketAddressZ {
                const addr = socket.remoteAddress;
                if (addr === undefined)
-                       return ldk.Option_NetAddressZ.constructor_none();
+                       return ldk.Option_SocketAddressZ.constructor_none();
                if (net.isIPv4(addr)) {
-                       return ldk.Option_NetAddressZ.constructor_some(NodeLDKNet.v4_addr_from_ip(addr, socket.remotePort));
+                       return ldk.Option_SocketAddressZ.constructor_some(NodeLDKNet.v4_addr_from_ip(addr, socket.remotePort));
                }
                if (net.isIPv6(addr)) {
-                       return ldk.Option_NetAddressZ.constructor_some(NodeLDKNet.v6_addr_from_ip(addr, socket.remotePort));
+                       return ldk.Option_SocketAddressZ.constructor_some(NodeLDKNet.v6_addr_from_ip(addr, socket.remotePort));
                }
-               return ldk.Option_NetAddressZ.constructor_none();
+               return ldk.Option_SocketAddressZ.constructor_none();
        }
 
        /**
index d796335df2546b23a0ec8910a31547799c9ce337..b9dac1b62c0cce09d48d726e7d78e9e58845c4c7 100644 (file)
@@ -84,19 +84,19 @@ function arr_eq(a: number[]|Uint8Array, b: number[]|Uint8Array): boolean {
 }
 
 const v4_parse = node_net.NodeLDKNet["v4_addr_from_ip"];
-console.assert((v4_parse("127.0.0.1", 4242) as ldk.NetAddress_IPv4).port == 4242);
-console.assert(arr_eq((v4_parse("127.0.0.1", 4242) as ldk.NetAddress_IPv4).addr, [127,0,0,1]));
-console.assert(arr_eq((v4_parse("0.0.0.0", 4242) as ldk.NetAddress_IPv4).addr, [0,0,0,0]));
+console.assert((v4_parse("127.0.0.1", 4242) as ldk.SocketAddress_TcpIpV4).port == 4242);
+console.assert(arr_eq((v4_parse("127.0.0.1", 4242) as ldk.SocketAddress_TcpIpV4).addr, [127,0,0,1]));
+console.assert(arr_eq((v4_parse("0.0.0.0", 4242) as ldk.SocketAddress_TcpIpV4).addr, [0,0,0,0]));
 
 const v6_parse = node_net.NodeLDKNet["v6_addr_from_ip"];
-console.assert((v6_parse("::", 4242) as ldk.NetAddress_IPv4).port == 4242);
-console.assert(arr_eq((v6_parse("::", 4242) as ldk.NetAddress_IPv6).addr,
+console.assert((v6_parse("::", 4242) as ldk.SocketAddress_TcpIpV4).port == 4242);
+console.assert(arr_eq((v6_parse("::", 4242) as ldk.SocketAddress_TcpIpV6).addr,
        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]));
-console.assert(arr_eq((v6_parse("fe80::", 4242) as ldk.NetAddress_IPv6).addr,
+console.assert(arr_eq((v6_parse("fe80::", 4242) as ldk.SocketAddress_TcpIpV6).addr,
        [0xfe,0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0]));
-console.assert(arr_eq((v6_parse("fe80::42", 4242) as ldk.NetAddress_IPv6).addr,
+console.assert(arr_eq((v6_parse("fe80::42", 4242) as ldk.SocketAddress_TcpIpV6).addr,
        [0xfe,0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0x42]));
-console.assert(arr_eq((v6_parse("fe80:A:b::", 4242) as ldk.NetAddress_IPv6).addr,
+console.assert(arr_eq((v6_parse("fe80:A:b::", 4242) as ldk.SocketAddress_TcpIpV6).addr,
        [0xfe,0x80,0,0xa,0,0xb,0,0,0,0,0,0,0,0,0,0]));
-console.assert(arr_eq((v6_parse("2001:1:bad::beef:cafe", 4242) as ldk.NetAddress_IPv6).addr,
+console.assert(arr_eq((v6_parse("2001:1:bad::beef:cafe", 4242) as ldk.SocketAddress_TcpIpV6).addr,
        [0x20, 0x01, 0, 1, 0xb, 0xad, 0, 0, 0, 0, 0, 0, 0xbe, 0xef, 0xca, 0xfe]));
index 0528e51b1e91758b2e1e66f4ed8f046931534057..3d82697ff8f354a046a7133cd74ba1f4ee3e4797 100644 (file)
@@ -179,12 +179,12 @@ tests.push(async () => {
 
        const features = a.chan_man.as_ChannelMessageHandler().provided_init_features(b.chan_man.get_our_node_id());
 
-       a.chan_man.as_ChannelMessageHandler().peer_connected(b.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_CVec_ChainHashZZ.constructor_none(), ldk.Option_NetAddressZ.constructor_none()), false);
-       b.chan_man.as_ChannelMessageHandler().peer_connected(a.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_CVec_ChainHashZZ.constructor_none(), ldk.Option_NetAddressZ.constructor_none()), true);
+       a.chan_man.as_ChannelMessageHandler().peer_connected(b.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_CVec_ThirtyTwoBytesZZ.constructor_none(), ldk.Option_SocketAddressZ.constructor_none()), false);
+       b.chan_man.as_ChannelMessageHandler().peer_connected(a.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_CVec_ThirtyTwoBytesZZ.constructor_none(), ldk.Option_SocketAddressZ.constructor_none()), true);
 
        const chan_create_err = a.chan_man.create_channel(b.chan_man.get_our_node_id(), BigInt(0), BigInt(400), BigInt(0), ldk.UserConfig.constructor_default());
        if (chan_create_err.is_ok()) return false;
-       if (!(chan_create_err instanceof ldk.Result__u832APIErrorZ_Err)) return false;
+       if (!(chan_create_err instanceof ldk.Result_ThirtyTwoBytesAPIErrorZ_Err)) return false;
        if (!(chan_create_err.err instanceof ldk.APIError_APIMisuseError)) return false;
        if (chan_create_err.err.err != "Channel value must be at least 1000 satoshis. It was 0") return false;
 
@@ -268,16 +268,16 @@ tests.push(async () => {
                }
        } as ldk.SocketDescriptorInterface);
 
-       const update_fut = a.chan_man.get_persistable_update_future();
+       const update_fut = a.chan_man.get_event_or_persistence_needed_future();
        var update_done = false;
        update_fut.register_callback_fn(ldk.FutureCallback.new_impl({
                call(): void { update_done = true; }
        }));
        if (update_done) return false;
 
-       const v4_netaddr = ldk.NetAddress.constructor_ipv4(Uint8Array.from([42,0,42,1]), 9735);
-       assert(pm_b.new_inbound_connection(sock_b, ldk.Option_NetAddressZ.constructor_some(v4_netaddr)) instanceof ldk.Result_NonePeerHandleErrorZ_OK);
-       const init_bytes = pm_a.new_outbound_connection(b.node_id, sock_a, ldk.Option_NetAddressZ.constructor_none());
+       const v4_netaddr = ldk.SocketAddress.constructor_tcp_ip_v4(Uint8Array.from([42,0,42,1]), 9735);
+       assert(pm_b.new_inbound_connection(sock_b, ldk.Option_SocketAddressZ.constructor_some(v4_netaddr)) instanceof ldk.Result_NonePeerHandleErrorZ_OK);
+       const init_bytes = pm_a.new_outbound_connection(b.node_id, sock_a, ldk.Option_SocketAddressZ.constructor_none());
        if (!(init_bytes instanceof ldk.Result_CVec_u8ZPeerHandleErrorZ_OK)) return false;
        assert(pm_b.read_event(sock_b, init_bytes.res) instanceof ldk.Result_boolPeerHandleErrorZ_OK);
 
@@ -415,9 +415,9 @@ tests.push(async () => {
                }
        } as ldk.SocketDescriptorInterface);
 
-       const v4_netaddr = ldk.NetAddress.constructor_ipv4(Uint8Array.from([42,0,42,1]), 9735);
-       assert(pm_b.new_inbound_connection(sock_b, ldk.Option_NetAddressZ.constructor_some(v4_netaddr)) instanceof ldk.Result_NonePeerHandleErrorZ_OK);
-       const init_bytes = pm_a.new_outbound_connection(b.node_id, sock_a, ldk.Option_NetAddressZ.constructor_none());
+       const v4_netaddr = ldk.SocketAddress.constructor_tcp_ip_v4(Uint8Array.from([42,0,42,1]), 9735);
+       assert(pm_b.new_inbound_connection(sock_b, ldk.Option_SocketAddressZ.constructor_some(v4_netaddr)) instanceof ldk.Result_NonePeerHandleErrorZ_OK);
+       const init_bytes = pm_a.new_outbound_connection(b.node_id, sock_a, ldk.Option_SocketAddressZ.constructor_none());
        if (!(init_bytes instanceof ldk.Result_CVec_u8ZPeerHandleErrorZ_OK)) return false;
        assert(pm_b.read_event(sock_b, init_bytes.res) instanceof ldk.Result_boolPeerHandleErrorZ_OK);