From: Matt Corallo Date: Tue, 2 Nov 2021 15:30:34 +0000 (+0000) Subject: Update tests for latest upstream API X-Git-Tag: v0.0.103.1~1^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=dc707e803064fda58ffb9417ac6b2e9720ba0fa4;p=ldk-java Update tests for latest upstream API Leaks in a full test run is now 89 allocations remained for 1138102 bytes. --- diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 261902b7..656c2ebb 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -168,7 +168,8 @@ class HumanObjectPeerTestInstance { final KeysManager explicit_keys_manager; final KeysInterface keys_interface; final ChainMonitor chain_monitor; - final NetGraphMsgHandler router; + final NetworkGraph router; + NetGraphMsgHandler route_handler; final Watch chain_watch; final HashSet filter_additions; final Option_FilterZ filter; @@ -209,7 +210,7 @@ class HumanObjectPeerTestInstance { this.seed = seed; Persist persister = Persist.new_impl(new Persist.PersistInterface() { @Override - public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, ChannelMonitor data) { + public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, ChannelMonitor data, MonitorUpdateId update_id) { synchronized (monitors) { String key = Arrays.toString(id.to_channel_id()); assert monitors.put(key, data) == null; @@ -221,7 +222,7 @@ class HumanObjectPeerTestInstance { } @Override - public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data) { + public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data, MonitorUpdateId update_id) { synchronized (monitors) { String key = Arrays.toString(id.to_channel_id()); assert monitors.put(key, data) != null; @@ -268,7 +269,8 @@ class HumanObjectPeerTestInstance { this.keys_interface = keys.as_KeysInterface(); this.explicit_keys_manager = keys; } - this.router = NetGraphMsgHandler.of(NetworkGraph.of(new byte[32]), Option_AccessZ.some(Access.new_impl(new Access.AccessInterface() { + this.router = NetworkGraph.of(new byte[32]); + this.route_handler = NetGraphMsgHandler.of(this.router, Option_AccessZ.some(Access.new_impl(new Access.AccessInterface() { @Override public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) { // We don't exchange any gossip, so should never actually get called, but providing a Some(Access) @@ -333,9 +335,8 @@ class HumanObjectPeerTestInstance { Peer(byte seed) { this(null, seed); if (use_chan_manager_constructor) { - NetGraphMsgHandler route_handler = null; - if (!use_ignore_handler) { - route_handler = router; + if (use_ignore_handler) { + this.route_handler = null; } this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, this.keys_interface, this.fee_estimator, this.chain_monitor, route_handler, this.tx_broadcaster, this.logger); @@ -355,7 +356,7 @@ class HumanObjectPeerTestInstance { ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0)); this.chan_manager = ChannelManager.of(this.fee_estimator, chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.with_default(), params); byte[] random_data = keys_interface.get_secure_random_bytes(); - this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); + this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); } this.node_id = chan_manager.get_our_node_id(); @@ -374,8 +375,11 @@ class HumanObjectPeerTestInstance { if (this.filter instanceof Option_FilterZ.Some) { filter_nullable = ((Option_FilterZ.Some) this.filter).some; } + if (use_ignore_handler) { + this.route_handler = null; + } this.constructor = new ChannelManagerConstructor(serialized, monitors, this.keys_interface, - this.fee_estimator, this.chain_monitor, filter_nullable, this.router, this.tx_broadcaster, this.logger); + this.fee_estimator, this.chain_monitor, filter_nullable, this.route_handler, this.tx_broadcaster, this.logger); constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -417,7 +421,7 @@ class HumanObjectPeerTestInstance { this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.get_b(); this.chain_watch.watch_channel(monitors[0].get_funding_txo().get_a(), monitors[0]); byte[] random_data = keys_interface.get_secure_random_bytes(); - this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); + this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) { // When we pass monitors[0] into chain_watch.watch_channel we create a reference from the new Peer to a // field in the old peer, preventing freeing of the original Peer until the new Peer is freed. Thus, we @@ -741,9 +745,11 @@ class HumanObjectPeerTestInstance { InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features(); RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints(); - Result_RouteLightningErrorZ route_res = UtilMethods.get_route( - peer1.chan_manager.get_our_node_id(), peer1.router.get_network_graph(), peer2.node_id, invoice_features, - peer1_chans, route_hints, 10000000, 42, peer1.logger, Scorer.with_default().as_Score()); + Payee payee = Payee.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none()); + RouteParameters route_params = RouteParameters.of(payee, 10000000, 42); + Result_RouteLightningErrorZ route_res = UtilMethods.find_route( + peer1.chan_manager.get_our_node_id(), route_params, peer1.router, + peer1_chans, peer1.logger, Scorer.with_default().as_Score()); assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK; Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res; assert route.get_paths().length == 1; @@ -758,7 +764,7 @@ class HumanObjectPeerTestInstance { hop_pubkey[0] = 3; hop_pubkey[1] = 42; hops[0][0] = RouteHop.of(hop_pubkey, NodeFeatures.known(), 42, ChannelFeatures.known(), 100, 0); - Route r2 = Route.of(hops); + Route r2 = Route.of(hops, payee); payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret); assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err; diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 66098419..8dc85de0 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -24,6 +24,7 @@ public class PeerTest { final long chan_manager_events; final long chan_handler; final long router; + final long router_wrapper; final long route_handler; final long message_handler; final long custom_message_handler; @@ -99,8 +100,9 @@ public class PeerTest { this.chan_manager_events = bindings.ChannelManager_as_EventsProvider(chan_manager); this.chan_handler = bindings.ChannelManager_as_ChannelMessageHandler(chan_manager); - this.router = bindings.NetGraphMsgHandler_new(bindings.NetworkGraph_new(new byte[32]), bindings.COption_AccessZ_none(), logger); - this.route_handler = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(router); + this.router = bindings.NetworkGraph_new(new byte[32]); + this.router_wrapper = bindings.NetGraphMsgHandler_new(router, bindings.COption_AccessZ_none(), logger); + this.route_handler = bindings.NetGraphMsgHandler_as_RoutingMessageHandler(router_wrapper); this.message_handler = bindings.MessageHandler_new(chan_handler, route_handler); this.custom_message_handler = bindings.IgnoringMessageHandler_new(); @@ -142,7 +144,8 @@ public class PeerTest { bindings.ChannelManager_free(chan_manager); bindings.EventsProvider_free(chan_manager_events); bindings.ChannelMessageHandler_free(chan_handler); - bindings.NetGraphMsgHandler_free(router); + bindings.NetworkGraph_free(router); + bindings.NetGraphMsgHandler_free(router_wrapper); bindings.RoutingMessageHandler_free(route_handler); //MessageHandler was actually moved into the route_handler!: bindings.MessageHandler_free(message_handler); bindings.PeerManager_free(peer_manager); @@ -279,16 +282,24 @@ public class PeerTest { long no_min_val = bindings.COption_u64Z_none(); long inbound_payment = bindings.ChannelManager_create_inbound_payment(peer2.chan_manager, no_min_val, 7200, 42); bindings.COption_u64Z_free(no_min_val); - long netgraph = bindings.NetGraphMsgHandler_get_network_graph(peer1.router); long scorer = bindings.Scorer_default(); long scorer_interface = bindings.Scorer_as_Score(scorer); - long route = bindings.get_route(peer1.node_id, netgraph, peer2.node_id, 0L, peer1_chans, - new long[0], 1000, 42, peer1.logger, scorer_interface); + + long no_u64 = bindings.COption_u64Z_none(); + long invoice_features = bindings.InvoiceFeatures_known(); + long payee = bindings.Payee_new(peer2.node_id, invoice_features, new long[0], no_u64); + bindings.InvoiceFeatures_free(invoice_features); + bindings.COption_u64Z_free(no_u64); + long route_params = bindings.RouteParameters_new(payee, 1000, 42); + long route = bindings.find_route(peer1.node_id, route_params, peer1.router, peer1_chans, + peer1.logger, scorer_interface); + bindings.RouteParameters_free(route_params); + bindings.Payee_free(payee); bindings.Score_free(scorer_interface); bindings.Scorer_free(scorer); + for (long chan : peer1_chans) bindings.ChannelDetails_free(chan); assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(route); - bindings.NetworkGraph_free(netgraph); long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager, bindings.LDKCResult_RouteLightningErrorZ_get_ok(route), bindings.C2Tuple_PaymentHashPaymentSecretZ_get_a(inbound_payment), bindings.C2Tuple_PaymentHashPaymentSecretZ_get_b(inbound_payment)); bindings.CResult_RouteLightningErrorZ_free(route);