Skip to content

Commit 313d665

Browse files
committed
test: Fix 0.16 wallet paths and downgrade test
The test for 0.16 wallet downgrading was using the wrong wallet path and thus incorrectly finding that 0.16 could open wallets created in master.
1 parent 5d84693 commit 313d665

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

test/functional/wallet_backwards_compatibility.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ def setup_nodes(self):
7272
self.start_nodes()
7373
self.import_deterministic_coinbase_privkeys()
7474

75-
def nodes_wallet_dir(self, node):
76-
if node.version < 170000:
77-
return node.chain_path
78-
return node.wallets_path
79-
8075
def split_version(self, node):
8176
major = node.version // 10000
8277
minor = (node.version % 10000) // 100
@@ -178,18 +173,21 @@ def run_test(self):
178173
node_master_wallets_dir = node_master.wallets_path
179174
node_v19_wallets_dir = node_v19.wallets_path
180175
node_v17_wallets_dir = node_v17.wallets_path
181-
node_v16_wallets_dir = node_v16.chain_path
176+
node_v16_wallets_dir = node_v16.wallets_path
182177
node_master.unloadwallet("w1")
183178
node_master.unloadwallet("w2")
184179
node_master.unloadwallet("w3")
185180

186181
for node in legacy_nodes:
187182
# Copy wallets to previous version
188183
for wallet in os.listdir(node_master_wallets_dir):
189-
shutil.copytree(
190-
os.path.join(node_master_wallets_dir, wallet),
191-
os.path.join(self.nodes_wallet_dir(node), wallet)
192-
)
184+
dest = node.wallets_path / wallet
185+
source = node_master_wallets_dir / wallet
186+
if self.major_version_equals(node, 16):
187+
# 0.16 node expect the wallet to be in the wallet dir but as a plain file rather than in directories
188+
shutil.copyfile(source / "wallet.dat", dest)
189+
else:
190+
shutil.copytree(source, dest)
193191

194192
if not self.options.descriptors:
195193
# Descriptor wallets break compatibility, only run this test for legacy wallet
@@ -249,13 +247,14 @@ def run_test(self):
249247
node_v17.assert_start_raises_init_error(["-wallet=w3"], "Error: Error loading w3: Wallet requires newer version of Bitcoin Core")
250248
self.start_node(node_v17.index)
251249

252-
if not self.options.descriptors:
253-
# Descriptor wallets break compatibility, only run this test for legacy wallets
254-
# Open most recent wallet in v0.16 (no loadwallet RPC)
255-
self.restart_node(node_v16.index, extra_args=["-wallet=w2"])
256-
wallet = node_v16.get_wallet_rpc("w2")
257-
info = wallet.getwalletinfo()
258-
assert info['keypoolsize'] == 1
250+
# No wallet created in master can be opened in 0.16
251+
self.log.info("Test that wallets created in master are too new for 0.16")
252+
self.stop_node(node_v16.index)
253+
for wallet_name in ["w1", "w2", "w3"]:
254+
if self.options.descriptors:
255+
node_v16.assert_start_raises_init_error([f"-wallet={wallet_name}"], f"Error: {wallet_name} corrupt, salvage failed")
256+
else:
257+
node_v16.assert_start_raises_init_error([f"-wallet={wallet_name}"], f"Error: Error loading {wallet_name}: Wallet requires newer version of Bitcoin Core")
259258

260259
# Create upgrade wallet in v0.16
261260
self.restart_node(node_v16.index, extra_args=["-wallet=u1_v16"])
@@ -278,7 +277,7 @@ def run_test(self):
278277
# Old wallets are BDB and will only work if BDB is compiled
279278
# Copy the 0.16 wallet to the last Bitcoin Core version and open it:
280279
shutil.copyfile(
281-
os.path.join(node_v16_wallets_dir, "wallets/u1_v16"),
280+
os.path.join(node_v16_wallets_dir, "u1_v16"),
282281
os.path.join(node_master_wallets_dir, "u1_v16")
283282
)
284283
load_res = node_master.loadwallet("u1_v16")
@@ -297,10 +296,10 @@ def run_test(self):
297296

298297
# Now copy that same wallet back to 0.16 to make sure no automatic upgrade breaks it
299298
node_master.unloadwallet("u1_v16")
300-
os.remove(os.path.join(node_v16_wallets_dir, "wallets/u1_v16"))
299+
os.remove(os.path.join(node_v16_wallets_dir, "u1_v16"))
301300
shutil.copyfile(
302301
os.path.join(node_master_wallets_dir, "u1_v16"),
303-
os.path.join(node_v16_wallets_dir, "wallets/u1_v16")
302+
os.path.join(node_v16_wallets_dir, "u1_v16")
304303
)
305304
self.start_node(node_v16.index, extra_args=["-wallet=u1_v16"])
306305
wallet = node_v16.get_wallet_rpc("u1_v16")

0 commit comments

Comments
 (0)