X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fldk%2FHumanObjectPeerTest.java;h=80c7cf61e1e5dd8bc6c986bdb8432fdbc8e40745;hb=e30b350e325e7d517ea744578876d473839ad495;hp=f37b671bc526b735ffea53577d5fb4ac771715cf;hpb=7aa095f42a570229656ab5fade9d966823b72e06;p=ldk-java diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index f37b671b..80c7cf61 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -7,6 +7,7 @@ import org.ldk.batteries.ChannelManagerConstructor; import org.ldk.batteries.NioPeerHandler; import org.ldk.enums.AccessError; import org.ldk.enums.Currency; +import org.ldk.enums.Level; import org.ldk.enums.Network; import org.ldk.structs.*; import org.ldk.util.TwoTuple; @@ -26,8 +27,9 @@ class HumanObjectPeerTestInstance { private final boolean use_filter; private final boolean use_ignore_handler; private final boolean use_chan_manager_constructor; + private final boolean use_invoice_payer; - HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_ignore_handler, boolean use_chan_manager_constructor) { + HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_ignore_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) { this.nice_close = nice_close; this.use_km_wrapper = use_km_wrapper; this.use_manual_watch = use_manual_watch; @@ -37,6 +39,7 @@ class HumanObjectPeerTestInstance { this.use_filter = use_filter; this.use_ignore_handler = use_ignore_handler; this.use_chan_manager_constructor = use_chan_manager_constructor; + this.use_invoice_payer = use_invoice_payer; } class Peer { @@ -168,10 +171,11 @@ 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; + Option_FilterZ filter; ChannelManager chan_manager; PeerManager peer_manager; final HashMap monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here. @@ -183,6 +187,7 @@ class HumanObjectPeerTestInstance { final LinkedList received_custom_messages = new LinkedList<>(); final LinkedList custom_messages_to_send = new LinkedList<>(); ChannelManagerConstructor constructor = null; + InvoicePayer payer = null; GcCheck obj = new GcCheck(); private TwoTuple_OutPointScriptZ test_mon_roundtrip(ChannelMonitor mon) { @@ -197,7 +202,12 @@ class HumanObjectPeerTestInstance { } private Peer(Object _dummy, byte seed) { - logger = Logger.new_impl((String arg) -> System.out.println(seed + ": " + arg)); + logger = Logger.new_impl((Record arg)->{ + if (arg.get_level() == Level.LDKLevel_Error) + System.err.println(seed + ": " + arg.get_module_path() + " - " + arg.get_args()); + else + System.out.println(seed + ": " + arg.get_module_path() + " - " + arg.get_args()); + }); fee_estimator = FeeEstimator.new_impl((confirmation_target -> 253)); tx_broadcaster = BroadcasterInterface.new_impl(tx -> { synchronized (broadcast_set) { @@ -209,7 +219,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 +231,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 +278,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,12 +344,15 @@ 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.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, + this.keys_interface, this.fee_estimator, this.chain_monitor, null, this.tx_broadcaster, this.logger); + } else { + this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, + this.keys_interface, this.fee_estimator, this.chain_monitor, this.router, this.tx_broadcaster, this.logger); } - 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); + LockableScore scorer = null; + if (use_invoice_payer) { scorer = LockableScore.of(Scorer.with_default().as_Score()); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -347,18 +361,39 @@ class HumanObjectPeerTestInstance { } } @Override public void persist_manager(byte[] channel_manager_bytes) { assert channel_manager_bytes.length > 1; } - }); + }, scorer); this.chan_manager = constructor.channel_manager; this.peer_manager = constructor.peer_manager; + this.payer = constructor.payer; must_free_objs.add(new WeakReference<>(this.chan_manager)); } else { 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); + if (use_invoice_payer) { + this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() { + @Override + public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer) { + return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); + } + }), LockableScore.of(Score.new_impl(new Score.ScoreInterface() { + @Override public void payment_path_failed(RouteHop[] path, long scid) {} + @Override public long channel_penalty_msat(long scid, NodeId src, NodeId dst) { return 0; } + @Override public byte[] write() { assert false; return null; } + })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() { + @Override public void handle_event(Event event) { + synchronized (pending_manager_events) { + pending_manager_events.add(event); + pending_manager_events.notifyAll(); + } + } + }), RetryAttempts.of(0)); + } } this.node_id = chan_manager.get_our_node_id(); + this.filter = null; bind_nio(); System.gc(); } @@ -374,8 +409,17 @@ class HumanObjectPeerTestInstance { if (this.filter instanceof Option_FilterZ.Some) { filter_nullable = ((Option_FilterZ.Some) this.filter).some; } - this.constructor = new ChannelManagerConstructor(serialized, monitors, this.keys_interface, - this.fee_estimator, this.chain_monitor, filter_nullable, this.router, this.tx_broadcaster, this.logger); + if (use_ignore_handler) { + this.constructor = new ChannelManagerConstructor(serialized, monitors, UserConfig.with_default(), + this.keys_interface, this.fee_estimator, this.chain_monitor, filter_nullable, + null, this.tx_broadcaster, this.logger); + } else { + this.constructor = new ChannelManagerConstructor(serialized, monitors, UserConfig.with_default(), + this.keys_interface, this.fee_estimator, this.chain_monitor, filter_nullable, + this.router, this.tx_broadcaster, this.logger); + } + LockableScore scorer = null; + if (use_invoice_payer) { scorer = LockableScore.of(Scorer.with_default().as_Score()); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -384,8 +428,9 @@ class HumanObjectPeerTestInstance { } } @Override public void persist_manager(byte[] channel_manager_bytes) { assert channel_manager_bytes.length > 1; } - }); + }, scorer); this.chan_manager = constructor.channel_manager; + this.payer = constructor.payer; this.peer_manager = constructor.peer_manager; must_free_objs.add(new WeakReference<>(this.chan_manager)); // If we are using a ChannelManagerConstructor, we may have pending events waiting on the old peer @@ -417,13 +462,32 @@ 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 // shouldn't bother waiting for the original to be freed later on. cross_reload_ref_pollution = true; } + if (use_invoice_payer) { + this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() { + @Override + public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer) { + return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); + } + }), LockableScore.of(Score.new_impl(new Score.ScoreInterface() { + @Override public void payment_path_failed(RouteHop[] path, long scid) {} + @Override public long channel_penalty_msat(long scid, NodeId src, NodeId dst) { return 0; } + @Override public byte[] write() { assert false; return null; } + })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() { + @Override public void handle_event(Event event) { + synchronized (pending_manager_events) { + pending_manager_events.add(event); + pending_manager_events.notifyAll(); + } + } + }), RetryAttempts.of(0)); + } } this.node_id = chan_manager.get_our_node_id(); bind_nio(); @@ -438,6 +502,7 @@ class HumanObjectPeerTestInstance { // the ChannelSigner. this.ptr_to = orig.chan_manager; } + this.filter = null; } TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] connect_block(Block b, int height, long expected_monitor_update_len) { @@ -659,8 +724,8 @@ class HumanObjectPeerTestInstance { connect_peers(peer1, peer2); - Result_NoneAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, 42, null); - assert cc_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK; + Result__u832APIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, 42, null); + assert cc_res instanceof Result__u832APIErrorZ.Result__u832APIErrorZ_OK; // Previously, this was a SEGFAULT instead of get_funding_txo() returning null. ChannelDetails pre_funding_chan = peer1.chan_manager.list_channels()[0]; @@ -721,7 +786,7 @@ class HumanObjectPeerTestInstance { assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes()); assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes()); - Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.none(), "Invoice Description"); + Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.some(10000000), "Invoice Description"); assert invoice instanceof Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK; System.out.println("Got invoice: " + ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str()); @@ -734,31 +799,41 @@ class HumanObjectPeerTestInstance { Description raw_invoice_description = raw_invoice.description(); String description_string = raw_invoice_description.into_inner(); assert description_string.equals("Invoice Description"); - byte[] payment_hash = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash(); - byte[] payment_secret = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_secret(); - byte[] dest_node_id = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.recover_payee_pub_key(); - assert Arrays.equals(dest_node_id, peer2.node_id); - 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); - 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; - assert route.get_paths()[0].length == 1; - assert route.get_paths()[0][0].get_fee_msat() == 10000000; - - Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret); - assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK; - - RouteHop[][] hops = new RouteHop[1][1]; - byte[] hop_pubkey = new byte[33]; - 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); - payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret); - assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err; + + if (!use_invoice_payer) { + byte[] payment_hash = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash(); + byte[] payment_secret = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_secret(); + byte[] dest_node_id = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.recover_payee_pub_key(); + assert Arrays.equals(dest_node_id, peer2.node_id); + InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features(); + RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints(); + + 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; + assert route.get_paths()[0].length == 1; + assert route.get_paths()[0][0].get_fee_msat() == 10000000; + + Result_PaymentIdPaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret); + assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_OK; + + RouteHop[][] hops = new RouteHop[1][1]; + byte[] hop_pubkey = new byte[33]; + 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, payee); + payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret); + assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err; + } else { + Result_PaymentIdPaymentErrorZ send_res = peer1.payer.pay_invoice(((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) parsed_invoice).res); + assert send_res instanceof Result_PaymentIdPaymentErrorZ.Result_PaymentIdPaymentErrorZ_OK; + } if (reload_peers) { if (use_chan_manager_constructor) { @@ -860,6 +935,11 @@ class HumanObjectPeerTestInstance { assert state.peer2.broadcast_set.size() == 1; } + events = state.peer2.get_manager_events(1, state.peer1, state.peer2); + assert events[0] instanceof Event.ChannelClosed; + events = state.peer1.get_manager_events(1, state.peer1, state.peer2); + assert events[0] instanceof Event.ChannelClosed; + if (state.peer1.chain_monitor != null) { Balance[] peer1_balances = state.peer1.chain_monitor.get_claimable_balances(state.peer1.chan_manager.list_channels()); assert peer1_balances.length == 1; @@ -914,19 +994,22 @@ class HumanObjectPeerTestInstance { } } - // Test exchanging a custom message - byte[] custom_message_bytes = new byte[] { 0x42, 0x44, 0x43, 0x00 }; - state.peer1.custom_messages_to_send.add(custom_message_bytes); - state.peer1.peer_manager.process_events(); - synchronized (state.peer2.received_custom_messages) { - while (true) { - if (state.peer2.received_custom_messages.isEmpty()) { - state.peer2.received_custom_messages.wait(); - continue; + // Test exchanging a custom message (note that ChannelManagerConstructor) always loads an IgnorimgMessageHandler + // so we cannot exchange custom messages with it + if (!use_chan_manager_constructor) { + byte[] custom_message_bytes = new byte[]{0x42, 0x44, 0x43, 0x00}; + state.peer1.custom_messages_to_send.add(custom_message_bytes); + state.peer1.peer_manager.process_events(); + synchronized (state.peer2.received_custom_messages) { + while (true) { + if (state.peer2.received_custom_messages.isEmpty()) { + state.peer2.received_custom_messages.wait(); + continue; + } + assert state.peer2.received_custom_messages.size() == 1; + assert Arrays.equals(state.peer2.received_custom_messages.get(0), custom_message_bytes); + break; } - assert state.peer2.received_custom_messages.size() == 1; - assert Arrays.equals(state.peer2.received_custom_messages.get(0), custom_message_bytes); - break; } } @@ -948,6 +1031,8 @@ class HumanObjectPeerTestInstance { t.interrupt(); + state.peer1.router.write(); + // Construct the only Option_Enum::Variant(OpaqueStruct) we have in the codebase as this used to cause double-frees: byte[] serd = new byte[] {(byte)0xd9,(byte)0x77,(byte)0xcb,(byte)0x9b,(byte)0x53,(byte)0xd9,(byte)0x3a,(byte)0x6f,(byte)0xf6,(byte)0x4b,(byte)0xb5,(byte)0xf1,(byte)0xe1,(byte)0x58,(byte)0xb4,(byte)0x09,(byte)0x4b,(byte)0x66,(byte)0xe7,(byte)0x98,(byte)0xfb,(byte)0x12,(byte)0x91,(byte)0x11,(byte)0x68,(byte)0xa3,(byte)0xcc,(byte)0xdf,(byte)0x80,(byte)0xa8,(byte)0x30,(byte)0x96,(byte)0x34,(byte)0x0a,(byte)0x6a,(byte)0x95,(byte)0xda,(byte)0x0a,(byte)0xe8,(byte)0xd9,(byte)0xf7,(byte)0x76,(byte)0x52,(byte)0x8e,(byte)0xec,(byte)0xdb,(byte)0xb7,(byte)0x47,(byte)0xeb,(byte)0x6b,(byte)0x54,(byte)0x54,(byte)0x95,(byte)0xa4,(byte)0x31,(byte)0x9e,(byte)0xd5,(byte)0x37,(byte)0x8e,(byte)0x35,(byte)0xb2,(byte)0x1e,(byte)0x07,(byte)0x3a,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x19,(byte)0xd6,(byte)0x68,(byte)0x9c,(byte)0x08,(byte)0x5a,(byte)0xe1,(byte)0x65,(byte)0x83,(byte)0x1e,(byte)0x93,(byte)0x4f,(byte)0xf7,(byte)0x63,(byte)0xae,(byte)0x46,(byte)0xa2,(byte)0xa6,(byte)0xc1,(byte)0x72,(byte)0xb3,(byte)0xf1,(byte)0xb6,(byte)0x0a,(byte)0x8c,(byte)0xe2,(byte)0x6f,(byte)0x00,(byte)0x08,(byte)0x3a,(byte)0x84,(byte)0x00,(byte)0x00,(byte)0x03,(byte)0x4d,(byte)0x01,(byte)0x34,(byte)0x13,(byte)0xa7,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x90,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x0f,(byte)0x42,(byte)0x40,(byte)0x00,(byte)0x00,(byte)0x27,(byte)0x10,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x14,}; Result_ChannelUpdateDecodeErrorZ upd_msg = ChannelUpdate.read(serd); @@ -968,14 +1053,14 @@ class HumanObjectPeerTestInstance { } } public class HumanObjectPeerTest { - HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor) throws InterruptedException { - HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor); + HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { + HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); HumanObjectPeerTestInstance.TestState state = instance.do_test_message_handler(); instance.do_test_message_handler_b(state); return instance; } - void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor) throws InterruptedException { - HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor); + void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { + HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); while (instance.gc_count != instance.gc_exp_count) { System.gc(); System.runFinalization(); @@ -985,15 +1070,16 @@ public class HumanObjectPeerTest { } @Test public void test_message_handler() throws InterruptedException { - for (int i = 0; i < (1 << 7) - 1; i++) { + for (int i = 0; i < (1 << 9) - 1; i++) { boolean nice_close = (i & (1 << 0)) != 0; boolean use_km_wrapper = (i & (1 << 1)) != 0; boolean use_manual_watch = (i & (1 << 2)) != 0; boolean reload_peers = (i & (1 << 3)) != 0; boolean break_cross_refs = (i & (1 << 4)) != 0; - boolean nio_peer_handler = (i & (1 << 5)) != 0; - boolean use_ignoring_routing_handler = (i & (1 << 6)) != 0; - boolean use_chan_manager_constructor = (i & (1 << 7)) != 0; + boolean use_ignoring_routing_handler = (i & (1 << 5)) != 0; + boolean use_chan_manager_constructor = (i & (1 << 6)) != 0; + boolean use_invoice_payer = (i & (1 << 7)) != 0; + boolean nio_peer_handler = (i & (1 << 8)) != 0; if (break_cross_refs && !reload_peers) { // There are no cross refs to break without reloading peers. continue; @@ -1002,13 +1088,19 @@ public class HumanObjectPeerTest { // ChannelManagerConstructor requires a ChainMonitor as the Watch and creates a NioPeerHandler for us. continue; } - if (!use_chan_manager_constructor && use_ignoring_routing_handler) { + if (!use_chan_manager_constructor && (use_ignoring_routing_handler)) { // We rely on the ChannelManagerConstructor to convert null into an IgnoringMessageHandler, so don't // try to run with an IgnoringMessageHandler unless we're also using a ChannelManagerConstructor. continue; } + if (use_chan_manager_constructor && use_ignoring_routing_handler && use_invoice_payer) { + // As documented on ChannelManagerConstructor, if we provide a `null` NetworkGraph (because we want to + // use an IgnoringMessageHandler), no InvoicePayer will be constructored for us, thus we cannot use an + // InvoicePayer to send payments in this case. + continue; + } System.err.println("Running test with flags " + i); - do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor); + do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); } }