Skip to content

Commit

Permalink
wallet: Test for descriptor wallet sethdseed and createwalletdescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Nov 28, 2023
1 parent 5fca05b commit 9bb2ecd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
13 changes: 10 additions & 3 deletions test/functional/wallet_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,20 @@ def run_test(self):
expected_xprv_count = 8
assert_equal(found_xprv_count, expected_xprv_count)

if encrypt:
wallet.walletlock()

# Make backup so the wallet can be copied back to old node
down_wallet_name = f"re_down_{node.version}{'_enc' if encrypt else ''}"
down_backup_path = os.path.join(self.options.tmpdir, f"{down_wallet_name}.dat")
wallet.backupwallet(down_backup_path)

# Check that taproot descriptors can be added to 0.21 wallets
# This must be done after the backup is created so that 0.21 can still load
# the backup
if self.options.descriptors and self.major_version_equals(node, 21):
wallet.createwalletdescriptor("bech32m")

if encrypt:
wallet.walletlock()

wallet.unloadwallet()

# Check that no automatic upgrade broke the downgrading the wallet
Expand Down
33 changes: 32 additions & 1 deletion test/functional/wallet_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
except ImportError:
pass

import re

from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
Expand All @@ -25,7 +27,7 @@ def add_options(self, parser):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
self.extra_args = [['-keypool=100']]
self.extra_args = [['-keypool=100', "-unsafesqlitesync=0"]]
self.wallet_names = []

def skip_test_if_missing_module(self):
Expand Down Expand Up @@ -239,6 +241,35 @@ def run_test(self):
conn.close()
assert_raises_rpc_error(-4, "Unexpected legacy entry in descriptor wallet found.", self.nodes[0].loadwallet, "crashme")

self.log.info("Test adding new autogenerated descriptors")
self.nodes[0].createwallet(wallet_name="autogen", descriptors=True, blank=True)
wallet = self.nodes[0].get_wallet_rpc("autogen")

# Set a new seed without adding new descriptors
wallet.sethdseed(False)

# seed cannot be rotated
assert_raises_rpc_error(-4, "The wallet already has an active HD key set. Create a new wallet if you want to rotate your keys.", wallet.sethdseed)

# Now add new autogenerated descriptors
addr_types = ["legacy", "p2sh-segwit", "bech32", "bech32m"]
for t in addr_types[0:2]:
wallet.createwalletdescriptor(t)
assert_raises_rpc_error(-4, "Descriptor already exists", wallet.createwalletdescriptor, t)

# We can make new change descriptors now
# Also testing the second parameter
for t in addr_types[2:]:
wallet.createwalletdescriptor(t, True)
wallet.createwalletdescriptor(t, False)

# Check that all descriptors use the same xpub
descs = wallet.listdescriptors()["descriptors"]
xpub = re.search(r"tpub.+?\/", descs[0]["desc"]).group()
for d in descs:
desc_xpub = re.search(r"tpub.+?\/", descs[0]["desc"])
assert desc_xpub
assert_equal(xpub, desc_xpub.group())

if __name__ == '__main__':
WalletDescriptorTest().main ()

0 comments on commit 9bb2ecd

Please sign in to comment.