From: Matt Corallo Date: Fri, 6 Oct 2023 17:55:17 +0000 (+0000) Subject: [TS] Update tests and node-net for new LDK 0.0.117 API X-Git-Tag: v0.0.117.0~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0800f52508a2f2665042a0c41ca5e8b525160277;p=ldk-java [TS] Update tests and node-net for new LDK 0.0.117 API --- diff --git a/node-net/net.mts b/node-net/net.mts index 9e16ab32..c70bf8f0 100644 --- a/node-net/net.mts +++ b/node-net/net.mts @@ -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(); } /** diff --git a/node-net/test/test.mts b/node-net/test/test.mts index d796335d..b9dac1b6 100644 --- a/node-net/test/test.mts +++ b/node-net/test/test.mts @@ -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])); diff --git a/ts/test/tests.mts b/ts/test/tests.mts index 0528e51b..3d82697f 100644 --- a/ts/test/tests.mts +++ b/ts/test/tests.mts @@ -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);