aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_migration.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/wallet_migration.py')
-rwxr-xr-xtest/functional/wallet_migration.py53
1 files changed, 45 insertions, 8 deletions
diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py
index 7c2959bb89..320f5dd9df 100755
--- a/test/functional/wallet_migration.py
+++ b/test/functional/wallet_migration.py
@@ -6,6 +6,7 @@
import os
import random
+import shutil
from test_framework.descriptors import descsum_create
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
@@ -53,7 +54,7 @@ class WalletMigrationTest(BitcoinTestFramework):
assert_equal(addr_info["address"], addr_info_old["address"])
assert_equal(addr_info["scriptPubKey"], addr_info_old["scriptPubKey"])
assert_equal(addr_info["ismine"], addr_info_old["ismine"])
- assert_equal(addr_info["hdkeypath"], addr_info_old["hdkeypath"])
+ assert_equal(addr_info["hdkeypath"], addr_info_old["hdkeypath"].replace("'","h"))
assert_equal(addr_info["solvable"], addr_info_old["solvable"])
assert_equal(addr_info["ischange"], addr_info_old["ischange"])
assert_equal(addr_info["hdmasterfingerprint"], addr_info_old["hdmasterfingerprint"])
@@ -91,11 +92,11 @@ class WalletMigrationTest(BitcoinTestFramework):
self.assert_is_sqlite("basic0")
# The wallet should create the following descriptors:
- # * BIP32 descriptors in the form of "0'/0'/*" and "0'/1'/*" (2 descriptors)
- # * BIP44 descriptors in the form of "44'/1'/0'/0/*" and "44'/1'/0'/1/*" (2 descriptors)
- # * BIP49 descriptors, P2SH(P2WPKH), in the form of "86'/1'/0'/0/*" and "86'/1'/0'/1/*" (2 descriptors)
- # * BIP84 descriptors, P2WPKH, in the form of "84'/1'/0'/1/*" and "84'/1'/0'/1/*" (2 descriptors)
- # * BIP86 descriptors, P2TR, in the form of "86'/1'/0'/0/*" and "86'/1'/0'/1/*" (2 descriptors)
+ # * BIP32 descriptors in the form of "0h/0h/*" and "0h/1h/*" (2 descriptors)
+ # * BIP44 descriptors in the form of "44h/1h/0h/0/*" and "44h/1h/0h/1/*" (2 descriptors)
+ # * BIP49 descriptors, P2SH(P2WPKH), in the form of "86h/1h/0h/0/*" and "86h/1h/0h/1/*" (2 descriptors)
+ # * BIP84 descriptors, P2WPKH, in the form of "84h/1h/0h/1/*" and "84h/1h/0h/1/*" (2 descriptors)
+ # * BIP86 descriptors, P2TR, in the form of "86h/1h/0h/0/*" and "86h/1h/0h/1/*" (2 descriptors)
# * A combo(PK) descriptor for the wallet master key.
# So, should have a total of 11 descriptors on it.
assert_equal(len(basic0.listdescriptors()["descriptors"]), 11)
@@ -107,7 +108,7 @@ class WalletMigrationTest(BitcoinTestFramework):
self.assert_addr_info_equal(change_addr_info, old_change_addr_info)
addr_info = basic0.getaddressinfo(basic0.getnewaddress("", "bech32"))
- assert_equal(addr_info["hdkeypath"], "m/84'/1'/0'/0/0")
+ assert_equal(addr_info["hdkeypath"], "m/84h/1h/0h/0/0")
self.log.info("Test migration of a basic keys only wallet with a balance")
basic1 = self.create_legacy_wallet("basic1")
@@ -281,7 +282,7 @@ class WalletMigrationTest(BitcoinTestFramework):
imports0.importaddress(import_sent_addr)
received_sent_watchonly_txid = default.sendtoaddress(import_sent_addr, 10)
received_sent_watchonly_vout = find_vout_for_address(self.nodes[0], received_sent_watchonly_txid, import_sent_addr)
- send = default.sendall(recipients=[default.getnewaddress()], options={"inputs": [{"txid": received_sent_watchonly_txid, "vout": received_sent_watchonly_vout}]})
+ send = default.sendall(recipients=[default.getnewaddress()], inputs=[{"txid": received_sent_watchonly_txid, "vout": received_sent_watchonly_vout}])
sent_watchonly_txid = send["txid"]
self.generate(self.nodes[0], 1)
@@ -470,6 +471,40 @@ class WalletMigrationTest(BitcoinTestFramework):
assert_equal(bals, wallet.getbalances())
+ def test_default_wallet(self):
+ self.log.info("Test migration of the wallet named as the empty string")
+ wallet = self.create_legacy_wallet("")
+
+ wallet.migratewallet()
+ info = wallet.getwalletinfo()
+ assert_equal(info["descriptors"], True)
+ assert_equal(info["format"], "sqlite")
+
+ def test_direct_file(self):
+ self.log.info("Test migration of a wallet that is not in a wallet directory")
+ wallet = self.create_legacy_wallet("plainfile")
+ wallet.unloadwallet()
+
+ wallets_dir = os.path.join(self.nodes[0].datadir, "regtest", "wallets")
+ wallet_path = os.path.join(wallets_dir, "plainfile")
+ wallet_dat_path = os.path.join(wallet_path, "wallet.dat")
+ shutil.copyfile(wallet_dat_path, os.path.join(wallets_dir, "plainfile.bak"))
+ shutil.rmtree(wallet_path)
+ shutil.move(os.path.join(wallets_dir, "plainfile.bak"), wallet_path)
+
+ self.nodes[0].loadwallet("plainfile")
+ info = wallet.getwalletinfo()
+ assert_equal(info["descriptors"], False)
+ assert_equal(info["format"], "bdb")
+
+ wallet.migratewallet()
+ info = wallet.getwalletinfo()
+ assert_equal(info["descriptors"], True)
+ assert_equal(info["format"], "sqlite")
+
+ assert os.path.isdir(wallet_path)
+ assert os.path.isfile(wallet_dat_path)
+
def run_test(self):
self.generate(self.nodes[0], 101)
@@ -482,6 +517,8 @@ class WalletMigrationTest(BitcoinTestFramework):
self.test_encrypted()
self.test_unloaded()
self.test_unloaded_by_path()
+ self.test_default_wallet()
+ self.test_direct_file()
if __name__ == '__main__':
WalletMigrationTest().main()