diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2019-12-31 19:55:18 +0100 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2020-02-06 05:17:18 +0000 |
commit | f11872cbf46128e22e33c3138755c4aa32e80de7 (patch) | |
tree | 8f56238d58781f002188ee6ce9dc90981d9060c2 /test/functional | |
parent | 178a8346871e17d621ac780a5c47be65508ce176 (diff) |
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
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/wallet_avoidreuse.py | 33 |
1 files changed, 32 insertions, 1 deletions
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() |