From df2ad7bd23428f6955c551a82bd943bf9c9f7996 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 28 Oct 2022 03:29:07 +0000 Subject: [PATCH] [Java] Update Java Tests to latest upstream API --- .../java/org/ldk/HumanObjectPeerTest.java | 30 +++++++++++-------- .../org/ldk/ManualMsgHandlingPeerTest.java | 9 +++--- src/test/java/org/ldk/PeerTest.java | 15 ++++++---- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index f12bd785..d155e93f 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -46,6 +46,7 @@ class HumanObjectPeerTestInstance { KeysInterface manual_keysif(KeysInterface underlying_if) { return KeysInterface.new_impl(new KeysInterface.KeysInterfaceInterface() { @Override public Result_SecretKeyNoneZ get_node_secret(Recipient recipient) { return underlying_if.get_node_secret(recipient); } + @Override public Result_PublicKeyNoneZ get_node_id(Recipient recipient) { return underlying_if.get_node_id(recipient); } @Override public Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, Option_ScalarZ tweak) { return underlying_if.ecdh(recipient, other_key, tweak); } @Override public byte[] get_destination_script() { return underlying_if.get_destination_script(); } @@ -89,6 +90,9 @@ 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_holder_anchor_input(byte[] anchor_tx, long input) { + return underlying_base.sign_holder_anchor_input(anchor_tx, input); + } @Override public Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) { return underlying_base.sign_channel_announcement(msg); } @@ -135,21 +139,21 @@ class HumanObjectPeerTestInstance { Watch get_manual_watch() { Watch.WatchInterface watch_impl = new Watch.WatchInterface() { - public Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor) { + public ChannelMonitorUpdateStatus watch_channel(OutPoint funding_txo, ChannelMonitor monitor) { synchronized (monitors) { assert monitors.put(Arrays.toString(funding_txo.get_txid()), monitor) == null; } - return Result_NoneChannelMonitorUpdateErrZ.ok(); + return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; } - public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) { + public ChannelMonitorUpdateStatus update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) { synchronized (monitors) { String txid = Arrays.toString(funding_txo.get_txid()); assert monitors.containsKey(txid); Result_NoneNoneZ update_res = monitors.get(txid).update_monitor(update, tx_broadcaster, fee_estimator, logger); assert update_res instanceof Result_NoneNoneZ.Result_NoneNoneZ_OK; } - return Result_NoneChannelMonitorUpdateErrZ.ok(); + return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; } @Override @@ -245,17 +249,17 @@ class HumanObjectPeerTestInstance { this.seed = seed; Persist persister = Persist.new_impl(new Persist.PersistInterface() { @Override - public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, ChannelMonitor data, MonitorUpdateId update_id) { + public ChannelMonitorUpdateStatus persist_new_channel(OutPoint id, ChannelMonitor data, MonitorUpdateId update_id) { synchronized (monitors) { String key = Arrays.toString(id.to_channel_id()); ChannelMonitor res = test_mon_roundtrip(id, data.write()); assert monitors.put(key, res) == null; } - return Result_NoneChannelMonitorUpdateErrZ.ok(); + return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; } @Override - public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data, MonitorUpdateId update_id) { + public ChannelMonitorUpdateStatus update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data, MonitorUpdateId update_id) { synchronized (monitors) { String key = Arrays.toString(id.to_channel_id()); ChannelMonitor res = test_mon_roundtrip(id, data.write()); @@ -263,7 +267,7 @@ class HumanObjectPeerTestInstance { // expose the JVM JIT bug where it finalize()s things still being called. assert monitors.put(key, res) != null; } - return Result_NoneChannelMonitorUpdateErrZ.ok(); + return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; } }); @@ -401,7 +405,7 @@ class HumanObjectPeerTestInstance { assert node_secret.is_ok(); this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), IgnoringMessageHandler.of().as_OnionMessageHandler(), - ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, System.currentTimeMillis() / 1000, + ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, (int)(System.currentTimeMillis() / 1000), 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() { @@ -540,7 +544,7 @@ class HumanObjectPeerTestInstance { assert node_secret.is_ok(); this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), IgnoringMessageHandler.of().as_OnionMessageHandler(), - ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, System.currentTimeMillis() / 1000, + ((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res, (int)(System.currentTimeMillis() / 1000), 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 @@ -873,7 +877,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.some(10000000), "Invoice Description", 7200); + Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, peer2.logger, Currency.LDKCurrency_Bitcoin, Option_u64Z.some(10000000), "Invoice Description", 7200); assert invoice instanceof Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK; System.out.println("Got invoice: " + ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str()); @@ -913,7 +917,9 @@ class HumanObjectPeerTestInstance { 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); + NodeFeatures node_features = NodeFeatures.empty(); + ChannelFeatures channel_features = ChannelFeatures.empty(); + hops[0][0] = RouteHop.of(hop_pubkey, node_features, 42, channel_features, 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; diff --git a/src/test/java/org/ldk/ManualMsgHandlingPeerTest.java b/src/test/java/org/ldk/ManualMsgHandlingPeerTest.java index 1cd1eb30..fd9fa7ef 100644 --- a/src/test/java/org/ldk/ManualMsgHandlingPeerTest.java +++ b/src/test/java/org/ldk/ManualMsgHandlingPeerTest.java @@ -94,8 +94,9 @@ public class ManualMsgHandlingPeerTest { } @Override - public void peer_connected(byte[] their_node_id, long msg) { - + public long peer_connected(byte[] their_node_id, long msg) { + assert false; + return 0; } @Override @@ -148,7 +149,7 @@ public class ManualMsgHandlingPeerTest { return 0; } - @Override public void peer_connected(byte[] their_node_id, long init) { } + @Override public long peer_connected(byte[] their_node_id, long init) { assert false; return 0; } @Override public long handle_reply_channel_range(byte[] their_node_id, long msg) { @@ -189,7 +190,7 @@ public class ManualMsgHandlingPeerTest { byte[] random_data = new byte[32]; for (byte i = 0; i < 32; i++) { random_data[i] = i; our_node_secret[i] = (byte) (i ^ 0xff); } - long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, System.currentTimeMillis() / 1000, + long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, (int)(System.currentTimeMillis() / 1000), random_data, logger, bindings.IgnoringMessageHandler_as_CustomMessageHandler(ignoring_message_handler)); diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 63a4e169..14dfa65e 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -3,6 +3,7 @@ package org.ldk; import org.bitcoinj.core.*; import org.bitcoinj.script.Script; import org.junit.jupiter.api.Test; +import org.ldk.enums.ChannelMonitorUpdateStatus; import org.ldk.enums.Network; import org.ldk.enums.Recipient; import org.ldk.impl.bindings; @@ -57,16 +58,16 @@ public class PeerTest { this.monitors = new HashMap<>(); this.watcher = new bindings.LDKWatch() { @Override - public long watch_channel(long funding_txo, long monitor) { + public ChannelMonitorUpdateStatus watch_channel(long funding_txo, long monitor) { synchronized (monitors) { assert monitors.put(Arrays.toString(bindings.OutPoint_get_txid(funding_txo)), monitor) == null; } bindings.OutPoint_free(funding_txo); - return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; } @Override - public long update_channel(long funding_txo, long update) { + public ChannelMonitorUpdateStatus update_channel(long funding_txo, long update) { synchronized (monitors) { String txid = Arrays.toString(bindings.OutPoint_get_txid(funding_txo)); assert monitors.containsKey(txid); @@ -76,7 +77,7 @@ public class PeerTest { } bindings.OutPoint_free(funding_txo); bindings.ChannelMonitorUpdate_free(update); - return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; } @Override @@ -123,7 +124,7 @@ public class PeerTest { long node_id_result = bindings.KeysInterface_get_node_secret(keys_interface, Recipient.LDKRecipient_Node); assert bindings.CResult_SecretKeyNoneZ_is_ok(node_id_result); this.peer_manager = bindings.PeerManager_new(message_handler, bindings.CResult_SecretKeyNoneZ_get_ok(node_id_result), - System.currentTimeMillis() / 1000, random_data, logger, this.custom_message_handler); + (int)(System.currentTimeMillis() / 1000), random_data, logger, this.custom_message_handler); bindings.CResult_SecretKeyNoneZ_free(node_id_result); } @@ -323,7 +324,9 @@ public class PeerTest { long scorer_interface = bindings.ProbabilisticScorer_as_Score(scorer); long no_u64 = bindings.COption_u64Z_none(); - long invoice_features = bindings.InvoiceFeatures_known(); + long invoice_features = bindings.InvoiceFeatures_empty(); + bindings.InvoiceFeatures_set_payment_secret_required(invoice_features); + bindings.InvoiceFeatures_set_variable_length_onion_required(invoice_features); long payee = bindings.PaymentParameters_new(peer2.node_id, invoice_features, new long[0], no_u64, 6*24*14, (byte)1, (byte)1, new long[0]); bindings.InvoiceFeatures_free(invoice_features); bindings.COption_u64Z_free(no_u64); -- 2.30.2