test: Run downgrade test on descriptor wallets

This commit is contained in:
Andrew Chow committed 2023-08-23 16:49:41 -04:00
1 parent f158573be1
commit 6d4699028b
1 file changed
+56 -46
@@ -135,7 +135,9 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
node_v17 = self.nodes[self.num_nodes - 2] node_v17 = self.nodes[self.num_nodes - 2]
node_v16 = self.nodes[self.num_nodes - 1] node_v16 = self.nodes[self.num_nodes - 1]
legacy_nodes = self.nodes[2:] legacy_nodes = self.nodes[2:] # Nodes that support legacy wallets
legacy_only_nodes = self.nodes[-5:] # Nodes that only support legacy wallets
descriptors_nodes = self.nodes[2:-5] # Nodes that support descriptor wallets
self.generatetoaddress(node_miner, COINBASE_MATURITY + 1, node_miner.getnewaddress()) self.generatetoaddress(node_miner, COINBASE_MATURITY + 1, node_miner.getnewaddress())
@@ -209,52 +211,60 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
self.test_v19_addmultisigaddress() self.test_v19_addmultisigaddress()
if not self.options.descriptors: self.log.info("Test that a wallet made on master can be opened on:")
# Descriptor wallets break compatibility, only run this test for legacy wallet # In descriptors wallet mode, run this test on the nodes that support descriptor wallets
# Load modern wallet with older nodes # In legacy wallets mode, run this test on the nodes that support legacy wallets
for node in legacy_nodes: for node in descriptors_nodes if self.options.descriptors else legacy_nodes:
for wallet_name in ["w1", "w2", "w3"]: if self.major_version_less_than(node, 17):
if node.version < 170000: # loadwallet was introduced in v0.17.0
# loadwallet was introduced in v0.17.0 continue
continue self.log.info(f"- {node.version}")
if node.version < 180000 and wallet_name == "w3": for wallet_name in ["w1", "w2", "w3"]:
# Blank wallets were introduced in v0.18.0. We test the loading error below. if self.major_version_less_than(node, 18) and wallet_name == "w3":
continue # Blank wallets were introduced in v0.18.0. We test the loading error below.
node.loadwallet(wallet_name) continue
wallet = node.get_wallet_rpc(wallet_name) if self.major_version_less_than(node, 22) and wallet_name == "w1" and self.options.descriptors:
info = wallet.getwalletinfo() # Descriptor wallets created after 0.21 have taproot descriptors which 0.21 does not support, tested below
if wallet_name == "w1": continue
assert info['private_keys_enabled'] == True node.loadwallet(wallet_name)
assert info['keypoolsize'] > 0 wallet = node.get_wallet_rpc(wallet_name)
txs = wallet.listtransactions() info = wallet.getwalletinfo()
assert_equal(len(txs), 5) if wallet_name == "w1":
assert_equal(txs[1]["txid"], tx1_id) assert info['private_keys_enabled'] == True
assert_equal(txs[2]["walletconflicts"], [tx1_id]) assert info['keypoolsize'] > 0
assert_equal(txs[1]["replaced_by_txid"], tx2_id) txs = wallet.listtransactions()
assert not txs[1]["abandoned"] assert_equal(len(txs), 5)
assert_equal(txs[1]["confirmations"], -1) assert_equal(txs[1]["txid"], tx1_id)
assert_equal(txs[2]["blockindex"], 1) assert_equal(txs[2]["walletconflicts"], [tx1_id])
assert txs[3]["abandoned"] assert_equal(txs[1]["replaced_by_txid"], tx2_id)
assert_equal(txs[4]["walletconflicts"], [tx3_id]) assert not txs[1]["abandoned"]
assert_equal(txs[3]["replaced_by_txid"], tx4_id) assert_equal(txs[1]["confirmations"], -1)
assert not hasattr(txs[3], "blockindex") assert_equal(txs[2]["blockindex"], 1)
elif wallet_name == "w2": assert txs[3]["abandoned"]
assert info['private_keys_enabled'] == False assert_equal(txs[4]["walletconflicts"], [tx3_id])
assert info['keypoolsize'] == 0 assert_equal(txs[3]["replaced_by_txid"], tx4_id)
else: assert not hasattr(txs[3], "blockindex")
assert info['private_keys_enabled'] == True elif wallet_name == "w2":
assert info['keypoolsize'] == 0 assert info['private_keys_enabled'] == False
else: assert info['keypoolsize'] == 0
for node in legacy_nodes: else:
# Descriptor wallets appear to be corrupted wallets to old software assert info['private_keys_enabled'] == True
# and loadwallet is introduced in v0.17.0 assert info['keypoolsize'] == 0
if node.version >= 170000 and node.version < 210000:
for wallet_name in ["w1", "w2", "w3"]:
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node.loadwallet, wallet_name)
# RPC loadwallet failure causes bitcoind to exit, in addition to the RPC # Check that descriptor wallets don't work on legacy only nodes
# call failure, so the following test won't work: if self.options.descriptors:
# assert_raises_rpc_error(-4, "Wallet loading failed.", node_v17.loadwallet, 'w3') self.log.info("Test descriptor wallet incompatibility on:")
for node in legacy_only_nodes:
# RPC loadwallet failure causes bitcoind to exit in <= 0.17, in addition to the RPC
# call failure, so the following test won't work:
# assert_raises_rpc_error(-4, "Wallet loading failed.", node_v17.loadwallet, 'w3')
if self.major_version_less_than(node, 18):
continue
self.log.info(f"- {node.version}")
# Descriptor wallets appear to be corrupted wallets to old software
assert self.major_version_at_least(node, 18) and self.major_version_less_than(node, 21)
for wallet_name in ["w1", "w2", "w3"]:
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node.loadwallet, wallet_name)
# Instead, we stop node and try to launch it with the wallet: # Instead, we stop node and try to launch it with the wallet:
self.stop_node(node_v17.index) self.stop_node(node_v17.index)