Skip to content

Commit 871e937

Browse files
committed
wallet: Test for descriptor wallet sethdseed and createwalletdescriptor
1 parent 09d860e commit 871e937

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

test/functional/wallet_descriptor.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
except ImportError:
1111
pass
1212

13+
import re
14+
1315
from test_framework.blocktools import COINBASE_MATURITY
1416
from test_framework.test_framework import BitcoinTestFramework
1517
from test_framework.util import (
@@ -25,7 +27,7 @@ def add_options(self, parser):
2527
def set_test_params(self):
2628
self.setup_clean_chain = True
2729
self.num_nodes = 1
28-
self.extra_args = [['-keypool=100']]
30+
self.extra_args = [['-keypool=100', "-unsafesqlitesync=0"]]
2931
self.wallet_names = []
3032

3133
def skip_test_if_missing_module(self):
@@ -241,6 +243,35 @@ def run_test(self):
241243
conn.close()
242244
assert_raises_rpc_error(-4, "Unexpected legacy entry in descriptor wallet found.", self.nodes[0].loadwallet, "crashme")
243245

246+
self.log.info("Test adding new autogenerated descriptors")
247+
self.nodes[0].createwallet(wallet_name="autogen", descriptors=True, blank=True)
248+
wallet = self.nodes[0].get_wallet_rpc("autogen")
249+
250+
# Set a new seed without adding new descriptors
251+
wallet.sethdseed(False)
252+
253+
# seed cannot be rotated
254+
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)
255+
256+
# Now add new autogenerated descriptors
257+
addr_types = ["legacy", "p2sh-segwit", "bech32", "bech32m"]
258+
for t in addr_types[0:2]:
259+
wallet.createwalletdescriptor(t)
260+
assert_raises_rpc_error(-4, "Descriptor already exists", wallet.createwalletdescriptor, t)
261+
262+
# We can make new change descriptors now
263+
# Also testing the second parameter
264+
for t in addr_types[2:]:
265+
wallet.createwalletdescriptor(t, True)
266+
wallet.createwalletdescriptor(t, False)
267+
268+
# Check that all descriptors use the same xpub
269+
descs = wallet.listdescriptors()["descriptors"]
270+
xpub = re.search(r"tpub.+?\/", descs[0]["desc"]).group()
271+
for d in descs:
272+
desc_xpub = re.search(r"tpub.+?\/", descs[0]["desc"])
273+
assert desc_xpub
274+
assert_equal(xpub, desc_xpub.group())
244275

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

0 commit comments

Comments
 (0)