diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2019-12-31 19:55:18 +0100 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2020-01-13 13:40:06 +0100 |
commit | 6fc554f591d8ea1681b8bb25aa12da8d4f023f66 (patch) | |
tree | 2ab3afcf7114c8bab9630dd255685958123c4dd6 /test | |
parent | 6196e930018181301b5972842ae384ea4288ff34 (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.
Diffstat (limited to 'test')
-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 0ca8c80956..7a4f345b6e 100755 --- a/test/functional/wallet_avoidreuse.py +++ b/test/functional/wallet_avoidreuse.py @@ -91,7 +91,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.''' @@ -257,5 +258,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() |