mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-26 14:59:16 +02:00
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: 6fc554f591
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user