Skip to content

Commit

Permalink
test: roundtrip wallet backwards compat downgrade
Browse files Browse the repository at this point in the history
Test that old nodes don't mess up new wallets by loading a downgraded
wallet in master again.
  • Loading branch information
achow101 committed Jul 4, 2023
1 parent 9ff7873 commit 604440c
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions test/functional/wallet_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,41 @@ def run_test(self):
if node.version == 210000 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
continue
node.loadwallet(wallet_name)
wallet = node.get_wallet_rpc(wallet_name)
info = wallet.getwalletinfo()
if wallet_name == "w1":
assert info['private_keys_enabled'] == True
assert info['keypoolsize'] > 0
txs = wallet.listtransactions()
assert_equal(len(txs), 5)
assert_equal(txs[1]["txid"], tx1_id)
assert_equal(txs[2]["walletconflicts"], [tx1_id])
assert_equal(txs[1]["replaced_by_txid"], tx2_id)
assert not txs[1]["abandoned"]
assert_equal(txs[1]["confirmations"], -1)
assert_equal(txs[2]["blockindex"], 1)
assert txs[3]["abandoned"]
assert_equal(txs[4]["walletconflicts"], [tx3_id])
assert_equal(txs[3]["replaced_by_txid"], tx4_id)
assert not hasattr(txs[3], "blockindex")
elif wallet_name == "w2":
assert info['private_keys_enabled'] == False
assert info['keypoolsize'] == 0
else:
assert info['private_keys_enabled'] == True
assert info['keypoolsize'] == 0
# Also try to reopen on master after opening on old
for n in [node, node_master]:
n.loadwallet(wallet_name)
wallet = n.get_wallet_rpc(wallet_name)
info = wallet.getwalletinfo()
if wallet_name == "w1":
assert info['private_keys_enabled'] == True
assert info['keypoolsize'] > 0
txs = wallet.listtransactions()
assert_equal(len(txs), 5)
assert_equal(txs[1]["txid"], tx1_id)
assert_equal(txs[2]["walletconflicts"], [tx1_id])
assert_equal(txs[1]["replaced_by_txid"], tx2_id)
assert not txs[1]["abandoned"]
assert_equal(txs[1]["confirmations"], -1)
assert_equal(txs[2]["blockindex"], 1)
assert txs[3]["abandoned"]
assert_equal(txs[4]["walletconflicts"], [tx3_id])
assert_equal(txs[3]["replaced_by_txid"], tx4_id)
assert not hasattr(txs[3], "blockindex")
elif wallet_name == "w2":
assert info['private_keys_enabled'] == False
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(os.path.join(node_master.wallets_path, wallet_name))
shutil.copytree(
os.path.join(n.wallets_path, wallet_name),
os.path.join(node_master.wallets_path, wallet_name),
)

# Check that descriptor wallets don't work on legacy only nodes
if self.options.descriptors:
Expand Down

0 comments on commit 604440c

Please sign in to comment.