aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2024-01-08 14:41:02 +0000
committerfanquake <fanquake@gmail.com>2024-01-08 14:44:47 +0000
commitc2d04f1319a6af6140d17339c4814e0cfc605dd2 (patch)
treeafe78dcd386ab65eb41337bab8e683c55c5421d9 /test/functional
parent04b9df0f9fd95e907b2e8bf823d63e9dfb37b4ad (diff)
parent406b71abcb72f234ddf9245a3f57e748343c774f (diff)
downloadbitcoin-c2d04f1319a6af6140d17339c4814e0cfc605dd2.tar.xz
Merge bitcoin/bitcoin#28610: wallet: Migrate entire address book entries to watchonly and solvables too
406b71abcb72f234ddf9245a3f57e748343c774f wallet: Migrate entire address book entries (Andrew Chow) Pull request description: Not all of the data in an address book entry was being copied to the watchonly and solvables wallets. This includes information such as whether the address was previously spent, and any receive requests that may exist. A test has been added to check that the previously spent information is copied, although it passes without the changes in this PR since this information is also regenerated when a transaction is loaded/added into a wallet. ACKs for top commit: ryanofsky: Code review ACK 406b71abcb72f234ddf9245a3f57e748343c774f. Just suggested change since last review furszy: Code review ACK 406b71ab Tree-SHA512: 13de42b16a1d8524fe0555764744139566b2e7d29741ceffc1158a905dd537136b762330568b3b5cac28cbee1bfd363a20de97d0a6c5296738cb3aa99133945b
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/wallet_migration.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py
index e2edaef4da..b171673be5 100755
--- a/test/functional/wallet_migration.py
+++ b/test/functional/wallet_migration.py
@@ -877,6 +877,61 @@ class WalletMigrationTest(BitcoinTestFramework):
assert_equal(magic, BTREE_MAGIC)
+ def test_avoidreuse(self):
+ self.log.info("Test that avoidreuse persists after migration")
+ def_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
+
+ wallet = self.create_legacy_wallet("avoidreuse")
+ wallet.setwalletflag("avoid_reuse", True)
+
+ # Import a pubkey to the test wallet and send some funds to it
+ reused_imported_addr = def_wallet.getnewaddress()
+ wallet.importpubkey(def_wallet.getaddressinfo(reused_imported_addr)["pubkey"])
+ imported_utxos = self.create_outpoints(def_wallet, outputs=[{reused_imported_addr: 2}])
+ def_wallet.lockunspent(False, imported_utxos)
+
+ # Send funds to the test wallet
+ reused_addr = wallet.getnewaddress()
+ def_wallet.sendtoaddress(reused_addr, 2)
+
+ self.generate(self.nodes[0], 1)
+
+ # Send funds from the test wallet with both its own and the imported
+ wallet.sendall([def_wallet.getnewaddress()])
+ def_wallet.sendall(recipients=[def_wallet.getnewaddress()], inputs=imported_utxos)
+ self.generate(self.nodes[0], 1)
+ balances = wallet.getbalances()
+ assert_equal(balances["mine"]["trusted"], 0)
+ assert_equal(balances["watchonly"]["trusted"], 0)
+
+ # Reuse the addresses
+ def_wallet.sendtoaddress(reused_addr, 1)
+ def_wallet.sendtoaddress(reused_imported_addr, 1)
+ self.generate(self.nodes[0], 1)
+ balances = wallet.getbalances()
+ assert_equal(balances["mine"]["used"], 1)
+ # Reused watchonly will not show up in balances
+ assert_equal(balances["watchonly"]["trusted"], 0)
+ assert_equal(balances["watchonly"]["untrusted_pending"], 0)
+ assert_equal(balances["watchonly"]["immature"], 0)
+
+ utxos = wallet.listunspent()
+ assert_equal(len(utxos), 2)
+ for utxo in utxos:
+ assert_equal(utxo["reused"], True)
+
+ # Migrate
+ migrate_res = wallet.migratewallet()
+ watchonly_wallet = self.nodes[0].get_wallet_rpc(migrate_res["watchonly_name"])
+
+ # One utxo in each wallet, marked used
+ utxos = wallet.listunspent()
+ assert_equal(len(utxos), 1)
+ assert_equal(utxos[0]["reused"], True)
+ watchonly_utxos = watchonly_wallet.listunspent()
+ assert_equal(len(watchonly_utxos), 1)
+ assert_equal(watchonly_utxos[0]["reused"], True)
+
def run_test(self):
self.generate(self.nodes[0], 101)
@@ -896,6 +951,7 @@ class WalletMigrationTest(BitcoinTestFramework):
self.test_conflict_txs()
self.test_hybrid_pubkey()
self.test_failed_migration_cleanup()
+ self.test_avoidreuse()
if __name__ == '__main__':
WalletMigrationTest().main()