I investigated further, and this is indeed a bug. I updated the tests to ensure that the balance was updated correctly, and for the case where this if block was present, the non-dirty balance would become 0 when it should be 5.
diff --git a/test/functional/wallet_avoidreuse.py b/test/functional/wallet_avoidreuse.py
index b7b3eae34..2964d0868 100755
--- a/test/functional/wallet_avoidreuse.py
+++ b/test/functional/wallet_avoidreuse.py
@@ -105,11 +105,15 @@ class AvoidReuseTest(BitcoinTestFramework):
self.nodes[1].sendtoaddress(address=retaddr, amount=10, avoid_reuse=False)
+ # node 1 should now have about 5 btc left (for both cases)
+ assert_approx(self.nodes[1].getbalance(), 5, 0.001)
+ assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 5, 0.001)
+
def test_fund_send_fund_send(self):
'''
Test the simple case where [1] generates a new address A, then
[0] sends 10 BTC to A.
- [1] spends 5 BTC from A. (leaving roughly 4 BTC useable)
+ [1] spends 5 BTC from A. (leaving roughly 5 BTC useable)
[0] sends 10 BTC to A again.
[1] tries to spend 10 BTC (fails; dirty).
[1] tries to spend 4 BTC (succeeds; change address sufficient)
@@ -138,5 +142,9 @@ class AvoidReuseTest(BitcoinTestFramework):
self.nodes[1].sendtoaddress(retaddr, 4)
+ # node 1 should now have about 1 btc left (no dirty) and 11 (including dirty)
+ assert_approx(self.nodes[1].getbalance(), 1, 0.001)
+ assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 11, 0.001)
+
if __name__ == '__main__':
AvoidReuseTest().main()
For case with if (used) [...] present:
2019-05-20T03:18:33.609000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
File "/Users/me/path/bitcoin/test/functional/test_framework/test_framework.py", line 194, in main
self.run_test()
File "./wallet_avoidreuse.py", line 45, in run_test
self.test_fund_send_fund_senddirty()
File "./wallet_avoidreuse.py", line 109, in test_fund_send_fund_senddirty
assert_approx(self.nodes[1].getbalance(), 5, 0.001)
File "./wallet_avoidreuse.py", line 17, in assert_approx
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
AssertionError: 0E-8 < [4.999..5.001]