+ const event = get_event(a.chan_man) as ldk.Event_FundingGenerationReady;
+
+ // (very) manually create a funding transaction
+ const witness_pos = event.output_script.length + 58;
+ const funding_tx = new Uint8Array(witness_pos + 7);
+ funding_tx[0] = 2; // 4-byte tx version 2
+ funding_tx[4] = 0; funding_tx[5] = 1; // segwit magic bytes
+ funding_tx[6] = 1; // 1-byte input count 1
+ // 36 bytes previous outpoint all-0s
+ funding_tx[43] = 0; // 1-byte input script length 0
+ funding_tx[44] = 0xff; funding_tx[45] = 0xff; funding_tx[46] = 0xff; funding_tx[47] = 0xff; // 4-byte nSequence
+ funding_tx[48] = 1; // one output
+ assign_u64(funding_tx, 49, event.channel_value_satoshis);
+ funding_tx[57] = event.output_script.length; // 1-byte output script length
+ funding_tx.set(event.output_script, 58);
+ funding_tx[witness_pos] = 1; funding_tx[witness_pos + 1] = 1; funding_tx[witness_pos + 2] = 0xff; // one witness element of size 1 with contents 0xff
+ funding_tx[witness_pos + 3] = 0; funding_tx[witness_pos + 4] = 0; funding_tx[witness_pos + 5] = 0; funding_tx[witness_pos + 6] = 0; // lock time 0
+
+ const funding_res = a.chan_man.funding_transaction_generated(event.temporary_channel_id, event.counterparty_node_id, funding_tx);
+ if (!(funding_res instanceof ldk.Result_NoneAPIErrorZ_OK)) return false;
+
+ if (!exchange_messages(a.chan_man, b.chan_man)) return false;
+
+ const tx_broadcasted: Uint8Array = (await a.tx_broadcasted);
+ if (!array_eq(tx_broadcasted, funding_tx)) return false;
+
+ return true;
+});
+
+tests.push(async () => {
+ const a = get_chanman();
+ const b = get_chanman();
+
+ const ignorer = ldk.IgnoringMessageHandler.constructor_new();
+ const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), a.node_secret, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
+ const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), b.node_secret, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
+
+ var sock_b: ldk.SocketDescriptor;
+ const sock_a = ldk.SocketDescriptor.new_impl({
+ send_data(data: Uint8Array, resume_read: boolean): number {
+ console.assert(pm_b.read_event(sock_b, data) instanceof ldk.Result_boolPeerHandleErrorZ_OK);
+ return data.length;
+ },
+ disconnect_socket(): void {
+ console.assert(false);
+ },
+ eq(other: ldk.SocketDescriptor): boolean {
+ return other.hash() == this.hash();
+ },
+ hash(): bigint {
+ return BigInt(1);