]> git.bitcoin.ninja Git - ldk-java/commitdiff
Expand HumanObjectPeerTest to cover get_claimable_balances
authorMatt Corallo <git@bluematt.me>
Mon, 27 Sep 2021 00:34:32 +0000 (00:34 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 27 Sep 2021 05:22:38 +0000 (05:22 +0000)
Memory leaks during tests are unchanged

src/test/java/org/ldk/HumanObjectPeerTest.java

index 996382795d19d06ebd0d93a03131c0406a58eaad..f37b671bc526b735ffea53577d5fb4ac771715cf 100644 (file)
@@ -824,6 +824,13 @@ class HumanObjectPeerTestInstance {
             Thread.sleep(100);
         }
 
+        if (state.peer1.chain_monitor != null) {
+            Balance[] peer1_balances = state.peer1.chain_monitor.get_claimable_balances(state.peer1.chan_manager.list_channels());
+            assert peer1_balances.length == 0;
+            Balance[] peer2_balances = state.peer2.chain_monitor.get_claimable_balances(state.peer2.chan_manager.list_channels());
+            assert peer2_balances.length == 0;
+        }
+
         ChannelDetails[] peer1_chans = state.peer1.chan_manager.list_channels();
 
         if (nice_close) {
@@ -851,7 +858,25 @@ class HumanObjectPeerTestInstance {
 
             assert state.peer1.broadcast_set.size() == 1;
             assert state.peer2.broadcast_set.size() == 1;
+        }
+
+        if (state.peer1.chain_monitor != null) {
+            Balance[] peer1_balances = state.peer1.chain_monitor.get_claimable_balances(state.peer1.chan_manager.list_channels());
+            assert peer1_balances.length == 1;
+            for (Balance bal : peer1_balances) {
+                assert bal instanceof Balance.ClaimableOnChannelClose;
+                long expected_tx_fee = 183;
+                assert ((Balance.ClaimableOnChannelClose) bal).claimable_amount_satoshis == 100000 - 1 - 10000 - expected_tx_fee;
+            }
+            Balance[] peer2_balances = state.peer2.chain_monitor.get_claimable_balances(state.peer2.chan_manager.list_channels());
+            assert peer2_balances.length == 1;
+            for (Balance bal : peer2_balances) {
+                assert bal instanceof Balance.ClaimableOnChannelClose;
+                assert ((Balance.ClaimableOnChannelClose) bal).claimable_amount_satoshis == 10000 + 1;
+            }
+        }
 
+        if (!nice_close) {
             NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
             Transaction tx = new Transaction(bitcoinj_net, state.peer1.broadcast_set.getFirst());
             Block b = new Block(bitcoinj_net, 2, state.best_blockhash, Sha256Hash.ZERO_HASH, 42, 0, 0,