From d671343911c12bd088c3130c1be53d18a345808d Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 21 Mar 2021 12:23:21 -0400 Subject: [PATCH] Test new block connection API and update tests to new API --- src/test/java/org/ldk/HumanObjectPeerTest.java | 17 ++++++++++------- src/test/java/org/ldk/PeerTest.java | 10 +--------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 0bde005b..175a9016 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -342,10 +342,13 @@ class HumanObjectPeerTestInstance { txn = new TwoTuple[]{txp}; } else txn = new TwoTuple[0]; - chan_manager.as_Listen().block_connected(b.bitcoinSerialize(), height); if (chain_monitor != null) { + chan_manager.as_Listen().block_connected(b.bitcoinSerialize(), height); chain_monitor.block_connected(header, txn, height); } else { + chan_manager.transactions_confirmed(header, height, txn); + chan_manager.update_best_block(header, height); + // Connect manually if we aren't using a ChainMonitor and are implementing Watch ourselves synchronized (monitors) { assert monitors.size() == 1; for (ChannelMonitor mon : monitors.values()) { @@ -519,13 +522,13 @@ 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)); - peer1.chan_manager.funding_transaction_generated(chan_id, OutPoint.constructor_new(funding.getTxId().getReversedBytes(), (short) 0)); + Result_NoneAPIErrorZ funding_res = peer1.chan_manager.funding_transaction_generated(chan_id, funding.bitcoinSerialize(), (short) 0); + assert funding_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK; wait_events_processed(peer1, peer2); - events = peer1.chan_manager_events.get_and_clear_pending_events(); - assert events.length == 1; - assert events[0] instanceof Event.FundingBroadcastSafe; - assert ((Event.FundingBroadcastSafe) events[0]).user_channel_id == 42; + assert peer1.broadcast_set.size() == 1; + assert Arrays.equals(peer1.broadcast_set.get(0), funding.bitcoinSerialize()); + peer1.broadcast_set.clear(); Block b = new Block(bitcoinj_net, 2, Sha256Hash.ZERO_HASH, Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[]{funding})); peer1.connect_block(b, 1, 0); @@ -644,7 +647,7 @@ class HumanObjectPeerTestInstance { wait_events_processed(state.peer1, state.peer2); assert state.peer1.broadcast_set.size() == 1; - assert state.peer2.broadcast_set.size() == 0; + assert state.peer2.broadcast_set.size() == 1; NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET); Transaction tx = new Transaction(bitcoinj_net, state.peer1.broadcast_set.getFirst()); diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 97093333..3373c037 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -238,21 +238,13 @@ 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)); - long funding_txo = bindings.OutPoint_new(funding.getTxId().getReversedBytes(), (short) 0); - bindings.ChannelManager_funding_transaction_generated(peer1.chan_manager, chan_id, funding_txo); - bindings.OutPoint_free(funding_txo); + bindings.ChannelManager_funding_transaction_generated(peer1.chan_manager, chan_id, funding.bitcoinSerialize(), (short)0); bindings.PeerManager_process_events(peer1.peer_manager); while (!list.isEmpty()) { list.poll().join(); } bindings.PeerManager_process_events(peer2.peer_manager); while (!list.isEmpty()) { list.poll().join(); } - events = bindings.EventsProvider_get_and_clear_pending_events(peer1.chan_manager_events); - assert events.length == 1; - event = bindings.LDKEvent_ref_from_ptr(events[0]); - assert event instanceof bindings.LDKEvent.FundingBroadcastSafe; - bindings.CVec_EventZ_free(events); - Block b = new Block(NetworkParameters.fromID(NetworkParameters.ID_MAINNET), 2, Sha256Hash.ZERO_HASH, Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[]{funding})); peer1.connect_block(b, funding, 1); peer2.connect_block(b, funding, 1); -- 2.39.5