From 502589786542336214b743a101b29e9f69e598c9 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 16 Apr 2021 00:38:28 +0000 Subject: [PATCH] Update tests for latest upstream API, sadly disabling the Sign wrapper test --- .../batteries/ChannelManagerConstructor.java | 6 ++++-- src/test/java/org/ldk/HumanObjectPeerTest.java | 18 ++++++++++-------- src/test/java/org/ldk/PeerTest.java | 7 +++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java index 43bea055..61bec8e3 100644 --- a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java +++ b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java @@ -81,7 +81,8 @@ public class ChannelManagerConstructor { channel_monitors = new TwoTuple[0]; channel_manager_latest_block_hash = null; this.chain_monitor = chain_monitor; - channel_manager = ChannelManager.constructor_new(fee_estimator, chain_monitor.as_Watch(), tx_broadcaster, logger, keys_interface, config, network, current_blockchain_tip_hash, current_blockchain_tip_height); + BestBlock block = BestBlock.constructor_new(current_blockchain_tip_hash, current_blockchain_tip_height); + channel_manager = ChannelManager.constructor_new(fee_estimator, chain_monitor.as_Watch(), tx_broadcaster, logger, keys_interface, config, network, block); } /** @@ -118,6 +119,7 @@ public class ChannelManagerConstructor { need_persist = true; } events = this.chain_monitor.as_EventsProvider().get_and_clear_pending_events(); + if (events.length != 0) { persister.handle_events(events); need_persist = true; @@ -129,7 +131,7 @@ public class ChannelManagerConstructor { return; } if (lastTimerTick < System.currentTimeMillis() - 60 * 1000) { - this.channel_manager.timer_chan_freshness_every_min(); + this.channel_manager.timer_tick_occurred(); lastTimerTick = System.currentTimeMillis(); } } diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 175a9016..bd4510ca 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -43,7 +43,8 @@ class HumanObjectPeerTestInstance { @Override public Sign get_channel_signer(boolean inbound, long channel_value_satoshis) { Sign underlying_ck = underlying_if.get_channel_signer(inbound, channel_value_satoshis); - Sign.SignInterface si = new Sign.SignInterface() { + // TODO: Expose the underlying signer from a Sign + /*BaseSign.BaseSignInterface si = new BaseSign.BaseSignInterface() { @Override public byte[] get_per_commitment_point(long idx) { return underlying_ck.get_per_commitment_point(idx); @@ -98,12 +99,13 @@ class HumanObjectPeerTestInstance { public byte[] write() { return underlying_ck.write(); } - }; - Sign resp = Sign.new_impl(si, underlying_ck.get_pubkeys()); - must_free_objs.add(new WeakReference<>(si)); - must_free_objs.add(new WeakReference<>(resp)); + };*/ + //Sign resp = Sign.new_impl(si, underlying_ck.get_pubkeys()); + //must_free_objs.add(new WeakReference<>(si)); + //must_free_objs.add(new WeakReference<>(resp)); must_free_objs.add(new WeakReference<>(underlying_ck)); - return resp; + //return resp; + return underlying_ck; } @Override @@ -270,7 +272,7 @@ class HumanObjectPeerTestInstance { } Peer(byte seed) { this(null, seed); - this.chan_manager = ChannelManager.constructor_new(FeeEstimator.new_impl(confirmation_target -> 0), chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.constructor_default(), LDKNetwork.LDKNetwork_Bitcoin, new byte[32], 0); + this.chan_manager = ChannelManager.constructor_new(FeeEstimator.new_impl(confirmation_target -> 0), chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.constructor_default(), LDKNetwork.LDKNetwork_Bitcoin, BestBlock.constructor_new(new byte[32], 0)); this.node_id = chan_manager.get_our_node_id(); this.chan_manager_events = chan_manager.as_EventsProvider(); @@ -522,7 +524,7 @@ class HumanObjectPeerTestInstance { funding.getInputs().get(0).setWitness(new TransactionWitness(2)); // Make sure we don't complain about lack of witness funding.getInput(0).getWitness().setPush(0, new byte[]{0x1}); funding.addOutput(Coin.SATOSHI.multiply(10000), new Script(funding_spk)); - Result_NoneAPIErrorZ funding_res = peer1.chan_manager.funding_transaction_generated(chan_id, funding.bitcoinSerialize(), (short) 0); + Result_NoneAPIErrorZ funding_res = peer1.chan_manager.funding_transaction_generated(chan_id, funding.bitcoinSerialize()); assert funding_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK; wait_events_processed(peer1, peer2); diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 3373c037..2de927c7 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -3,9 +3,8 @@ package org.ldk; import org.bitcoinj.core.*; import org.bitcoinj.script.Script; import org.junit.jupiter.api.Test; +import org.ldk.enums.LDKNetwork; import org.ldk.impl.bindings; -import org.ldk.enums.*; -import org.ldk.structs.Result_NoneChannelMonitorUpdateErrZ; import java.util.ArrayList; import java.util.Arrays; @@ -93,7 +92,7 @@ public class PeerTest { this.keys = bindings.KeysManager_new(key_seed, System.currentTimeMillis() / 1000, (int)(System.currentTimeMillis() * 1000) & 0xffffffff); this.keys_interface = bindings.KeysManager_as_KeysInterface(keys); this.config = bindings.UserConfig_default(); - long params = bindings.ChainParameters_new(LDKNetwork.LDKNetwork_Bitcoin, new byte[32], 0); + long params = bindings.ChainParameters_new(LDKNetwork.LDKNetwork_Bitcoin, bindings.BestBlock_new(new byte[32], 0)); this.chan_manager = bindings.ChannelManager_new(fee_estimator, chain_monitor, tx_broadcaster, logger, keys_interface, config, params); this.node_id = bindings.ChannelManager_get_our_node_id(chan_manager); this.chan_manager_events = bindings.ChannelManager_as_EventsProvider(chan_manager); @@ -238,7 +237,7 @@ public class PeerTest { funding.getInputs().get(0).setWitness(new TransactionWitness(2)); // Make sure we don't complain about lack of witness funding.getInput(0).getWitness().setPush(0, new byte[] {0x1}); funding.addOutput(Coin.SATOSHI.multiply(10000), new Script(funding_spk)); - bindings.ChannelManager_funding_transaction_generated(peer1.chan_manager, chan_id, funding.bitcoinSerialize(), (short)0); + bindings.ChannelManager_funding_transaction_generated(peer1.chan_manager, chan_id, funding.bitcoinSerialize()); bindings.PeerManager_process_events(peer1.peer_manager); while (!list.isEmpty()) { list.poll().join(); } -- 2.39.5