X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fldk%2FHumanObjectPeerTest.java;h=64ec216277ec7d42ec631bd881ed157bf472d28b;hb=07a77b3acfead3fa199dd42c763cd8e71a7cf9ab;hp=948544b6f7868391055a0eb46352004aa2731ad6;hpb=d2925e24ac4643ec22eb73495f0424e27def2545;p=ldk-java diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 948544b6..64ec2162 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -5,17 +5,16 @@ import org.bitcoinj.script.Script; import org.junit.jupiter.api.Test; import org.ldk.batteries.ChannelManagerConstructor; import org.ldk.batteries.NioPeerHandler; -import org.ldk.enums.AccessError; +import org.ldk.enums.*; import org.ldk.enums.Currency; -import org.ldk.enums.Level; -import org.ldk.enums.Network; import org.ldk.structs.*; -import org.ldk.util.TwoTuple; +import org.ldk.util.UInt5; import java.io.IOException; import java.lang.ref.WeakReference; import java.net.InetSocketAddress; import java.util.*; +import java.util.function.IntConsumer; class HumanObjectPeerTestInstance { private final boolean nice_close; @@ -45,7 +44,7 @@ class HumanObjectPeerTestInstance { class Peer { KeysInterface manual_keysif(KeysInterface underlying_if) { return KeysInterface.new_impl(new KeysInterface.KeysInterfaceInterface() { - @Override public byte[] get_node_secret() { return underlying_if.get_node_secret(); } + @Override public Result_SecretKeyNoneZ get_node_secret(Recipient recipient) { return underlying_if.get_node_secret(recipient); } @Override public byte[] get_destination_script() { return underlying_if.get_destination_script(); } @Override public ShutdownScript get_shutdown_scriptpubkey() { return underlying_if.get_shutdown_scriptpubkey(); } @@ -60,14 +59,14 @@ class HumanObjectPeerTestInstance { @Override public byte[] release_commitment_secret(long idx) { return underlying_base.release_commitment_secret(idx); } - @Override public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx) { - return underlying_base.validate_holder_commitment(holder_tx); + @Override public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages) { + return underlying_base.validate_holder_commitment(holder_tx, preimages); } @Override public byte[] channel_keys_id() { return new byte[32]; } - @Override public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx) { - return underlying_base.sign_counterparty_commitment(commitment_tx); + @Override public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] preimages) { + return underlying_base.sign_counterparty_commitment(commitment_tx, preimages); } @Override public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) { return underlying_base.validate_counterparty_revocation(idx, secret); @@ -87,7 +86,7 @@ class HumanObjectPeerTestInstance { @Override public Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx) { return underlying_base.sign_closing_transaction(closing_tx); } - @Override public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) { + @Override public Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) { return underlying_base.sign_channel_announcement(msg); } @Override public void ready_channel(ChannelTransactionParameters params) { @@ -120,8 +119,8 @@ class HumanObjectPeerTestInstance { } @Override - public Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage) { - return underlying_if.sign_invoice(invoice_preimage); + public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient receipient) { + return underlying_if.sign_invoice(hrp_bytes, invoice_data, receipient); } @Override @@ -358,8 +357,11 @@ class HumanObjectPeerTestInstance { 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); } + Result_ScorerDecodeErrorZ score_res = Scorer.read(Scorer.with_default().write()); + assert score_res.is_ok(); + Score score = ((Result_ScorerDecodeErrorZ.Result_ScorerDecodeErrorZ_OK) score_res).res.as_Score(); MultiThreadedLockableScore scorer = null; - if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(Scorer.with_default().as_Score()); } + if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(score); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -377,7 +379,10 @@ 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(), route_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); + Result_SecretKeyNoneZ node_secret = keys_interface.get_node_secret(Recipient.LDKRecipient_Node); + assert node_secret.is_ok(); + this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), + ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, 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 @@ -386,7 +391,7 @@ class HumanObjectPeerTestInstance { } }), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() { @Override public void payment_path_failed(RouteHop[] path, long scid) {} - @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, Option_u64Z channel_capacity_msat, NodeId source, NodeId target) { return 0; } + @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, long channel_capacity_msat, NodeId source, NodeId target) { return 0; } @Override public void payment_path_successful(RouteHop[] path) {} @Override public byte[] write() { assert false; return null; } })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() { @@ -480,7 +485,11 @@ 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(), route_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); + Result_SecretKeyNoneZ node_secret = keys_interface.get_node_secret(Recipient.LDKRecipient_Node); + assert node_secret.is_ok(); + this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), + ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, + 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 @@ -494,7 +503,7 @@ class HumanObjectPeerTestInstance { return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); } }), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() { - @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, Option_u64Z channel_capacity_msat, NodeId source, NodeId target) { return 0; } + @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, long channel_capacity_msat, NodeId source, NodeId target) { return 0; } @Override public void payment_path_failed(RouteHop[] path, long scid) {} @Override public void payment_path_successful(RouteHop[] path) {} @Override public byte[] write() { assert false; return null; } @@ -828,7 +837,7 @@ 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(); - Payee payee = Payee.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none()); + PaymentParameters payee = PaymentParameters.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none(), 6*24*14); 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, @@ -1075,13 +1084,13 @@ 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, boolean use_invoice_payer) throws InterruptedException { + static 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, boolean use_invoice_payer) throws InterruptedException { + static 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(); @@ -1090,8 +1099,8 @@ public class HumanObjectPeerTest { for (WeakReference o : instance.must_free_objs) assert o.get() == null; } - @Test - public void test_message_handler() throws InterruptedException { + public static final int TEST_ITERATIONS = (1 << 9); + public static void do_test_message_handler(IntConsumer statusFunction) throws InterruptedException { Thread gc_thread = new Thread(() -> { while (true) { System.gc(); @@ -1100,7 +1109,7 @@ public class HumanObjectPeerTest { } }, "Test GC Thread"); gc_thread.start(); - for (int i = 0; i < (1 << 9) - 1; i++) { + for (int i = 0; i < TEST_ITERATIONS; i++) { boolean nice_close = (i & (1 << 0)) != 0; boolean use_km_wrapper = (i & (1 << 1)) != 0; boolean use_manual_watch = (i & (1 << 2)) != 0; @@ -1129,17 +1138,21 @@ public class HumanObjectPeerTest { // InvoicePayer to send payments in this case. continue; } - System.err.println("Running test with flags " + i); + statusFunction.accept(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, use_invoice_payer); } gc_thread.interrupt(); gc_thread.join(); } + @Test + public void test_message_handler() throws InterruptedException { + do_test_message_handler(i -> System.err.println("Running test with flags " + i)); + } // This is used in the test jar to test the built jar is runnable public static void main(String[] args) { try { - new HumanObjectPeerTest().test_message_handler(); + do_test_message_handler(i -> System.err.println("Running test with flags " + i)); } catch (Exception e) { System.err.println("Caught exception:"); System.err.println(e);