@@ -3,18 +3,21 @@ import * as ldk from "../index.mjs";
33
44const tests : Array < Function > = [ ] ;
55
6+ function assert ( val : boolean ) {
7+ if ( ! val ) throw new Error ( "Assertion failed" ) ;
8+ }
69function array_eq ( a : Uint8Array , b : Uint8Array ) : boolean {
710 return a . length == b . length && a . every ( ( v , idx ) => v == b [ idx ] ) ;
811}
912
1013tests . push ( async ( ) => {
1114 const result = rawldk . CResult_boolLightningErrorZ_ok ( true ) ;
12- console . assert ( rawldk . CResult_boolLightningErrorZ_is_ok ( result ) ) ;
13- console . assert ( rawldk . CResult_boolLightningErrorZ_get_ok ( result ) ) ;
15+ assert ( rawldk . CResult_boolLightningErrorZ_is_ok ( result ) ) ;
16+ assert ( rawldk . CResult_boolLightningErrorZ_get_ok ( result ) ) ;
1417 rawldk . CResult_boolLightningErrorZ_free ( result ) ;
1518 const second_res = rawldk . CResult_boolLightningErrorZ_ok ( false ) ;
16- console . assert ( rawldk . CResult_boolLightningErrorZ_is_ok ( second_res ) ) ;
17- console . assert ( ! rawldk . CResult_boolLightningErrorZ_get_ok ( second_res ) ) ;
19+ assert ( rawldk . CResult_boolLightningErrorZ_is_ok ( second_res ) ) ;
20+ assert ( ! rawldk . CResult_boolLightningErrorZ_get_ok ( second_res ) ) ;
1821 rawldk . CResult_boolLightningErrorZ_free ( second_res ) ;
1922
2023 return true ;
@@ -160,7 +163,7 @@ function get_event(chan_man: ldk.ChannelManager): ldk.Event {
160163 } as ldk . EventHandlerInterface ) ;
161164
162165 chan_man . as_EventsProvider ( ) . process_pending_events ( event_handler ) ;
163- console . assert ( events . length == 1 ) ;
166+ assert ( events . length == 1 ) ;
164167 return events [ 0 ] ;
165168}
166169
@@ -224,11 +227,11 @@ tests.push(async () => {
224227 var sock_b : ldk . SocketDescriptor ;
225228 const sock_a = ldk . SocketDescriptor . new_impl ( {
226229 send_data ( data : Uint8Array , resume_read : boolean ) : number {
227- console . assert ( pm_b . read_event ( sock_b , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
230+ assert ( pm_b . read_event ( sock_b , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
228231 return data . length ;
229232 } ,
230233 disconnect_socket ( ) : void {
231- console . assert ( false ) ;
234+ assert ( false ) ;
232235 } ,
233236 eq ( other : ldk . SocketDescriptor ) : boolean {
234237 return other . hash ( ) == this . hash ( ) ;
@@ -239,11 +242,11 @@ tests.push(async () => {
239242 } as ldk . SocketDescriptorInterface ) ;
240243 sock_b = ldk . SocketDescriptor . new_impl ( {
241244 send_data ( data : Uint8Array , resume_read : boolean ) : number {
242- console . assert ( pm_a . read_event ( sock_a , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
245+ assert ( pm_a . read_event ( sock_a , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
243246 return data . length ;
244247 } ,
245248 disconnect_socket ( ) : void {
246- console . assert ( false ) ;
249+ assert ( false ) ;
247250 } ,
248251 eq ( other : ldk . SocketDescriptor ) : boolean {
249252 return other . hash ( ) == this . hash ( ) ;
@@ -261,20 +264,20 @@ tests.push(async () => {
261264 if ( update_done ) return false ;
262265
263266 const v4_netaddr = ldk . NetAddress . constructor_ipv4 ( Uint8Array . from ( [ 42 , 0 , 42 , 1 ] ) , 9735 ) ;
264- console . assert ( pm_b . new_inbound_connection ( sock_b , ldk . Option_NetAddressZ . constructor_some ( v4_netaddr ) ) instanceof ldk . Result_NonePeerHandleErrorZ_OK ) ;
267+ assert ( pm_b . new_inbound_connection ( sock_b , ldk . Option_NetAddressZ . constructor_some ( v4_netaddr ) ) instanceof ldk . Result_NonePeerHandleErrorZ_OK ) ;
265268 const init_bytes = pm_a . new_outbound_connection ( b . node_id , sock_a , ldk . Option_NetAddressZ . constructor_none ( ) ) ;
266269 if ( ! ( init_bytes instanceof ldk . Result_CVec_u8ZPeerHandleErrorZ_OK ) ) return false ;
267- console . assert ( pm_b . read_event ( sock_b , init_bytes . res ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
270+ assert ( pm_b . read_event ( sock_b , init_bytes . res ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
268271
269- console . assert ( pm_a . get_peer_node_ids ( ) . length == 0 ) ;
270- console . assert ( pm_b . get_peer_node_ids ( ) . length == 0 ) ;
272+ assert ( pm_a . get_peer_node_ids ( ) . length == 0 ) ;
273+ assert ( pm_b . get_peer_node_ids ( ) . length == 0 ) ;
271274
272275 pm_b . process_events ( ) ;
273276 pm_a . process_events ( ) ;
274277 pm_b . process_events ( ) ;
275278
276- console . assert ( pm_a . get_peer_node_ids ( ) . length == 1 ) ;
277- console . assert ( pm_b . get_peer_node_ids ( ) . length == 1 ) ;
279+ assert ( pm_a . get_peer_node_ids ( ) . length == 1 ) ;
280+ assert ( pm_b . get_peer_node_ids ( ) . length == 1 ) ;
278281
279282 const chan_create_res = a . chan_man . create_channel ( b . node_id , BigInt ( 1000000 ) , BigInt ( 400 ) , BigInt ( 0 ) , ldk . UserConfig . constructor_default ( ) ) ;
280283 if ( ! chan_create_res . is_ok ( ) ) return false ;
@@ -299,16 +302,16 @@ tests.push(async () => {
299302 var a_handled_msg = false ;
300303 const om_handler_a = ldk . CustomOnionMessageHandler . new_impl ( {
301304 read_custom_message ( message_type : bigint , buffer : Uint8Array ) : ldk . Result_COption_CustomOnionMessageContentsZDecodeErrorZ {
302- console . assert ( message_type == 4343n ) ;
303- console . assert ( buffer . length == 44 ) ;
304- for ( var i = 0 ; i < 44 ; i ++ ) console . assert ( buffer [ i ] == 67 ) ;
305+ assert ( message_type == 4343n ) ;
306+ assert ( buffer . length == 44 ) ;
307+ for ( var i = 0 ; i < 44 ; i ++ ) assert ( buffer [ i ] == 67 ) ;
305308 return ldk . Result_COption_CustomOnionMessageContentsZDecodeErrorZ . constructor_ok ( ldk . Option_CustomOnionMessageContentsZ . constructor_some ( ldk . CustomOnionMessageContents . new_impl ( {
306309 tlv_type ( ) : bigint { return 9998n ; } ,
307- write ( ) : Uint8Array { console . assert ( false ) ; return null ; }
310+ write ( ) : Uint8Array { assert ( false ) ; return null ; }
308311 } as ldk . CustomOnionMessageContentsInterface ) ) ) ;
309312 } ,
310313 handle_custom_message ( msg : ldk . CustomOnionMessageContents ) {
311- console . assert ( msg . tlv_type ( ) == 9998n ) ;
314+ assert ( msg . tlv_type ( ) == 9998n ) ;
312315 a_handled_msg = true ;
313316 } ,
314317 } as ldk . CustomOnionMessageHandlerInterface ) ;
@@ -340,16 +343,16 @@ tests.push(async () => {
340343 var b_handled_msg = false ;
341344 const om_handler_b = ldk . CustomOnionMessageHandler . new_impl ( {
342345 read_custom_message ( message_type : bigint , buffer : Uint8Array ) : ldk . Result_COption_CustomOnionMessageContentsZDecodeErrorZ {
343- console . assert ( message_type == 4242n ) ;
344- console . assert ( buffer . length == 43 ) ;
345- for ( var i = 0 ; i < 43 ; i ++ ) console . assert ( buffer [ i ] == 66 ) ;
346+ assert ( message_type == 4242n ) ;
347+ assert ( buffer . length == 43 ) ;
348+ for ( var i = 0 ; i < 43 ; i ++ ) assert ( buffer [ i ] == 66 ) ;
346349 return ldk . Result_COption_CustomOnionMessageContentsZDecodeErrorZ . constructor_ok ( ldk . Option_CustomOnionMessageContentsZ . constructor_some ( ldk . CustomOnionMessageContents . new_impl ( {
347350 tlv_type ( ) : bigint { return 9999n ; } ,
348- write ( ) : Uint8Array { console . assert ( false ) ; return null ; }
351+ write ( ) : Uint8Array { assert ( false ) ; return null ; }
349352 } as ldk . CustomOnionMessageContentsInterface ) ) ) ;
350353 } ,
351354 handle_custom_message ( msg : ldk . CustomOnionMessageContents ) {
352- console . assert ( msg . tlv_type ( ) == 9999n ) ;
355+ assert ( msg . tlv_type ( ) == 9999n ) ;
353356 b_handled_msg = true ;
354357 } ,
355358 } as ldk . CustomOnionMessageHandlerInterface ) ;
@@ -361,11 +364,11 @@ tests.push(async () => {
361364 var sock_b : ldk . SocketDescriptor ;
362365 const sock_a = ldk . SocketDescriptor . new_impl ( {
363366 send_data ( data : Uint8Array , resume_read : boolean ) : number {
364- console . assert ( pm_b . read_event ( sock_b , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
367+ assert ( pm_b . read_event ( sock_b , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
365368 return data . length ;
366369 } ,
367370 disconnect_socket ( ) : void {
368- console . assert ( false ) ;
371+ assert ( false ) ;
369372 } ,
370373 eq ( other : ldk . SocketDescriptor ) : boolean {
371374 return other . hash ( ) == this . hash ( ) ;
@@ -376,11 +379,11 @@ tests.push(async () => {
376379 } as ldk . SocketDescriptorInterface ) ;
377380 sock_b = ldk . SocketDescriptor . new_impl ( {
378381 send_data ( data : Uint8Array , resume_read : boolean ) : number {
379- console . assert ( pm_a . read_event ( sock_a , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
382+ assert ( pm_a . read_event ( sock_a , data ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
380383 return data . length ;
381384 } ,
382385 disconnect_socket ( ) : void {
383- console . assert ( false ) ;
386+ assert ( false ) ;
384387 } ,
385388 eq ( other : ldk . SocketDescriptor ) : boolean {
386389 return other . hash ( ) == this . hash ( ) ;
@@ -391,20 +394,20 @@ tests.push(async () => {
391394 } as ldk . SocketDescriptorInterface ) ;
392395
393396 const v4_netaddr = ldk . NetAddress . constructor_ipv4 ( Uint8Array . from ( [ 42 , 0 , 42 , 1 ] ) , 9735 ) ;
394- console . assert ( pm_b . new_inbound_connection ( sock_b , ldk . Option_NetAddressZ . constructor_some ( v4_netaddr ) ) instanceof ldk . Result_NonePeerHandleErrorZ_OK ) ;
397+ assert ( pm_b . new_inbound_connection ( sock_b , ldk . Option_NetAddressZ . constructor_some ( v4_netaddr ) ) instanceof ldk . Result_NonePeerHandleErrorZ_OK ) ;
395398 const init_bytes = pm_a . new_outbound_connection ( b . node_id , sock_a , ldk . Option_NetAddressZ . constructor_none ( ) ) ;
396399 if ( ! ( init_bytes instanceof ldk . Result_CVec_u8ZPeerHandleErrorZ_OK ) ) return false ;
397- console . assert ( pm_b . read_event ( sock_b , init_bytes . res ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
400+ assert ( pm_b . read_event ( sock_b , init_bytes . res ) instanceof ldk . Result_boolPeerHandleErrorZ_OK ) ;
398401
399- console . assert ( pm_a . get_peer_node_ids ( ) . length == 0 ) ;
400- console . assert ( pm_b . get_peer_node_ids ( ) . length == 0 ) ;
402+ assert ( pm_a . get_peer_node_ids ( ) . length == 0 ) ;
403+ assert ( pm_b . get_peer_node_ids ( ) . length == 0 ) ;
401404
402405 pm_b . process_events ( ) ;
403406 pm_a . process_events ( ) ;
404407 pm_b . process_events ( ) ;
405408
406- console . assert ( pm_a . get_peer_node_ids ( ) . length == 1 ) ;
407- console . assert ( pm_b . get_peer_node_ids ( ) . length == 1 ) ;
409+ assert ( pm_a . get_peer_node_ids ( ) . length == 1 ) ;
410+ assert ( pm_b . get_peer_node_ids ( ) . length == 1 ) ;
408411
409412 underlying_om_a . send_custom_onion_message ( [ ] , ldk . Destination . constructor_node ( b . node_id ) , ldk . CustomOnionMessageContents . new_impl ( {
410413 tlv_type ( ) : bigint { return 4242n ; } ,
@@ -415,7 +418,7 @@ tests.push(async () => {
415418 }
416419 } as ldk . CustomOnionMessageContentsInterface ) , null ) ;
417420 pm_a . process_events ( ) ;
418- console . assert ( b_handled_msg ) ;
421+ assert ( b_handled_msg ) ;
419422
420423 om_b . send_custom_onion_message ( [ ] , ldk . Destination . constructor_node ( a . node_id ) , ldk . CustomOnionMessageContents . new_impl ( {
421424 tlv_type ( ) : bigint { return 4343n ; } ,
@@ -426,7 +429,7 @@ tests.push(async () => {
426429 }
427430 } as ldk . CustomOnionMessageContentsInterface ) , null ) ;
428431 pm_b . process_events ( ) ;
429- console . assert ( a_handled_msg ) ;
432+ assert ( a_handled_msg ) ;
430433
431434 return true ;
432435} ) ;
0 commit comments