]> git.bitcoin.ninja Git - ldk-java/commitdiff
Test new block connection API and update tests to new API
authorMatt Corallo <git@bluematt.me>
Sun, 21 Mar 2021 16:23:21 +0000 (12:23 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 16 Apr 2021 00:44:11 +0000 (00:44 +0000)
src/test/java/org/ldk/HumanObjectPeerTest.java
src/test/java/org/ldk/PeerTest.java

index 0bde005b66ba08b5c043df58944a486e8e48e095..175a90166ce18a53f8a4edcaef827053fcc36eac 100644 (file)
@@ -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());
index 97093333473684ccab176ab404fbf1ca0960ba98..3373c0376221b947c98f8933061ea76e32c845fe 100644 (file)
@@ -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);