Skip to content

Commit

Permalink
test: Test descriptor wallet sethdseed
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Dec 19, 2023
1 parent b06e2ef commit 04657fa
Showing 1 changed file with 32 additions and 1 deletion.
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 04657fa

Please sign in to comment.