From f11872cbf46128e22e33c3138755c4aa32e80de7 Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Tue, 31 Dec 2019 19:55:18 +0100 Subject: wallet: Reset reused transactions cache If a destination is reused we mark the cache of the other transactions going to that destination dirty so they are not accidentally reported as trusted when the cache is hit. Github-Pull: #17843 Rebased-From: 6fc554f591d8ea1681b8bb25aa12da8d4f023f66 --- test/functional/wallet_avoidreuse.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/functional/wallet_avoidreuse.py') diff --git a/test/functional/wallet_avoidreuse.py b/test/functional/wallet_avoidreuse.py index 55b30afdee..d261fe6343 100755 --- a/test/functional/wallet_avoidreuse.py +++ b/test/functional/wallet_avoidreuse.py @@ -88,7 +88,8 @@ class AvoidReuseTest(BitcoinTestFramework): self.test_fund_send_fund_send("p2sh-segwit") reset_balance(self.nodes[1], self.nodes[0].getnewaddress()) self.test_fund_send_fund_send("bech32") - + reset_balance(self.nodes[1], self.nodes[0].getnewaddress()) + self.test_getbalances_used() def test_persistence(self): '''Test that wallet files persist the avoid_reuse flag.''' @@ -248,5 +249,35 @@ class AvoidReuseTest(BitcoinTestFramework): assert_approx(self.nodes[1].getbalance(), 1, 0.001) assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 11, 0.001) + def test_getbalances_used(self): + ''' + getbalances and listunspent should pick up on reused addresses + immediately, even for address reusing outputs created before the first + transaction was spending from that address + ''' + self.log.info("Test getbalances used category") + + # node under test should be completely empty + assert_equal(self.nodes[1].getbalance(avoid_reuse=False), 0) + + new_addr = self.nodes[1].getnewaddress() + ret_addr = self.nodes[0].getnewaddress() + + # send multiple transactions, reusing one address + for _ in range(11): + self.nodes[0].sendtoaddress(new_addr, 1) + + self.nodes[0].generate(1) + self.sync_all() + + # send transaction that should not use all the available outputs + # per the current coin selection algorithm + self.nodes[1].sendtoaddress(ret_addr, 5) + + # getbalances and listunspent should show the remaining outputs + # in the reused address as used/reused + assert_unspent(self.nodes[1], total_count=2, total_sum=6, reused_count=1, reused_sum=1) + assert_balances(self.nodes[1], mine={"used": 1, "trusted": 5}) + if __name__ == '__main__': AvoidReuseTest().main() -- cgit v1.2.3