test: roundtrip wallet backwards compat downgrade

Test that old nodes don't mess up new wallets by loading a downgraded
wallet in master again.
This commit is contained in:
Andrew Chow 2023-07-03 22:51:09 -04:00
parent bbf43c63b9
commit afd9a673c4

View file

@ -226,30 +226,41 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
if self.major_version_less_than(node, 22) and wallet_name == "w1" and self.options.descriptors: if self.major_version_less_than(node, 22) and wallet_name == "w1" and self.options.descriptors:
# Descriptor wallets created after 0.21 have taproot descriptors which 0.21 does not support, tested below # Descriptor wallets created after 0.21 have taproot descriptors which 0.21 does not support, tested below
continue continue
node.loadwallet(wallet_name) # Also try to reopen on master after opening on old
wallet = node.get_wallet_rpc(wallet_name) for n in [node, node_master]:
info = wallet.getwalletinfo() n.loadwallet(wallet_name)
if wallet_name == "w1": wallet = n.get_wallet_rpc(wallet_name)
assert info['private_keys_enabled'] == True info = wallet.getwalletinfo()
assert info['keypoolsize'] > 0 if wallet_name == "w1":
txs = wallet.listtransactions() assert info['private_keys_enabled'] == True
assert_equal(len(txs), 5) assert info['keypoolsize'] > 0
assert_equal(txs[1]["txid"], tx1_id) txs = wallet.listtransactions()
assert_equal(txs[2]["walletconflicts"], [tx1_id]) assert_equal(len(txs), 5)
assert_equal(txs[1]["replaced_by_txid"], tx2_id) assert_equal(txs[1]["txid"], tx1_id)
assert not txs[1]["abandoned"] assert_equal(txs[2]["walletconflicts"], [tx1_id])
assert_equal(txs[1]["confirmations"], -1) assert_equal(txs[1]["replaced_by_txid"], tx2_id)
assert_equal(txs[2]["blockindex"], 1) assert not txs[1]["abandoned"]
assert txs[3]["abandoned"] assert_equal(txs[1]["confirmations"], -1)
assert_equal(txs[4]["walletconflicts"], [tx3_id]) assert_equal(txs[2]["blockindex"], 1)
assert_equal(txs[3]["replaced_by_txid"], tx4_id) assert txs[3]["abandoned"]
assert not hasattr(txs[3], "blockindex") assert_equal(txs[4]["walletconflicts"], [tx3_id])
elif wallet_name == "w2": assert_equal(txs[3]["replaced_by_txid"], tx4_id)
assert info['private_keys_enabled'] == False assert not hasattr(txs[3], "blockindex")
assert info['keypoolsize'] == 0 elif wallet_name == "w2":
else: assert info['private_keys_enabled'] == False
assert info['private_keys_enabled'] == True assert info['keypoolsize'] == 0
assert info['keypoolsize'] == 0 else:
assert info['private_keys_enabled'] == True
assert info['keypoolsize'] == 0
# Copy back to master
wallet.unloadwallet()
if n == node:
shutil.rmtree(node_master.wallets_path / wallet_name)
shutil.copytree(
n.wallets_path / wallet_name,
node_master.wallets_path / wallet_name,
)
# Check that descriptor wallets don't work on legacy only nodes # Check that descriptor wallets don't work on legacy only nodes
if self.options.descriptors: if self.options.descriptors: