Skip to content

Commit 173cc9b

Browse files
committed
test: walettool create descriptors
1 parent 345e88e commit 173cc9b

File tree

1 file changed

+47
-75
lines changed

1 file changed

+47
-75
lines changed

test/functional/tool_wallet.py

Lines changed: 47 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def skip_test_if_missing_module(self):
2828

2929
def bitcoin_wallet_process(self, *args):
3030
binary = self.config["environment"]["BUILDDIR"] + '/src/bitcoin-wallet' + self.config["environment"]["EXEEXT"]
31-
args = ['-datadir={}'.format(self.nodes[0].datadir), '-chain=%s' % self.chain] + list(args)
32-
return subprocess.Popen([binary] + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
31+
default_args = ['-datadir={}'.format(self.nodes[0].datadir), '-chain=%s' % self.chain]
32+
if self.options.descriptors:
33+
default_args.append('-descriptors')
34+
35+
return subprocess.Popen([binary] + default_args + list(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
3336

3437
def assert_raises_tool_error(self, error, *args):
3538
p = self.bitcoin_wallet_process(*args)
@@ -63,6 +66,36 @@ def log_wallet_timestamp_comparison(self, old, new):
6366
result = 'unchanged' if new == old else 'increased!'
6467
self.log.debug('Wallet file timestamp {}'.format(result))
6568

69+
def get_expected_info_output(self, name="", transactions=0, keypool=2, address=0):
70+
wallet_name = self.default_wallet_name if name == "" else name
71+
output_types = 3 # p2pkh, p2sh, segwit
72+
if self.options.descriptors:
73+
return textwrap.dedent('''\
74+
Wallet info
75+
===========
76+
Name: %s
77+
Format: sqlite
78+
Descriptors: yes
79+
Encrypted: no
80+
HD (hd seed available): yes
81+
Keypool Size: %d
82+
Transactions: %d
83+
Address Book: %d
84+
''' % (wallet_name, keypool * output_types, transactions, address))
85+
else:
86+
return textwrap.dedent('''\
87+
Wallet info
88+
===========
89+
Name: %s
90+
Format: bdb
91+
Descriptors: no
92+
Encrypted: no
93+
HD (hd seed available): yes
94+
Keypool Size: %d
95+
Transactions: %d
96+
Address Book: %d
97+
''' % (wallet_name, keypool, transactions, address * output_types))
98+
6699
def test_invalid_tool_commands_and_args(self):
67100
self.log.info('Testing that various invalid commands raise with specific error messages')
68101
self.assert_raises_tool_error('Invalid command: foo', 'foo')
@@ -98,33 +131,7 @@ def test_tool_wallet_info(self):
98131
# shasum_before = self.wallet_shasum()
99132
timestamp_before = self.wallet_timestamp()
100133
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
101-
if self.options.descriptors:
102-
out = textwrap.dedent('''\
103-
Wallet info
104-
===========
105-
Name: default_wallet
106-
Format: sqlite
107-
Descriptors: yes
108-
Encrypted: no
109-
HD (hd seed available): yes
110-
Keypool Size: 6
111-
Transactions: 0
112-
Address Book: 1
113-
''')
114-
else:
115-
out = textwrap.dedent('''\
116-
Wallet info
117-
===========
118-
Name: \
119-
120-
Format: bdb
121-
Descriptors: no
122-
Encrypted: no
123-
HD (hd seed available): yes
124-
Keypool Size: 2
125-
Transactions: 0
126-
Address Book: 3
127-
''')
134+
out = self.get_expected_info_output(address=1)
128135
self.assert_tool_output(out, '-wallet=' + self.default_wallet_name, 'info')
129136
timestamp_after = self.wallet_timestamp()
130137
self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
@@ -155,33 +162,7 @@ def test_tool_wallet_info_after_transaction(self):
155162
shasum_before = self.wallet_shasum()
156163
timestamp_before = self.wallet_timestamp()
157164
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
158-
if self.options.descriptors:
159-
out = textwrap.dedent('''\
160-
Wallet info
161-
===========
162-
Name: default_wallet
163-
Format: sqlite
164-
Descriptors: yes
165-
Encrypted: no
166-
HD (hd seed available): yes
167-
Keypool Size: 6
168-
Transactions: 1
169-
Address Book: 1
170-
''')
171-
else:
172-
out = textwrap.dedent('''\
173-
Wallet info
174-
===========
175-
Name: \
176-
177-
Format: bdb
178-
Descriptors: no
179-
Encrypted: no
180-
HD (hd seed available): yes
181-
Keypool Size: 2
182-
Transactions: 1
183-
Address Book: 3
184-
''')
165+
out = self.get_expected_info_output(transactions=1, address=1)
185166
self.assert_tool_output(out, '-wallet=' + self.default_wallet_name, 'info')
186167
shasum_after = self.wallet_shasum()
187168
timestamp_after = self.wallet_timestamp()
@@ -199,19 +180,7 @@ def test_tool_wallet_create_on_existing_wallet(self):
199180
shasum_before = self.wallet_shasum()
200181
timestamp_before = self.wallet_timestamp()
201182
self.log.debug('Wallet file timestamp before calling create: {}'.format(timestamp_before))
202-
out = textwrap.dedent('''\
203-
Topping up keypool...
204-
Wallet info
205-
===========
206-
Name: foo
207-
Format: bdb
208-
Descriptors: no
209-
Encrypted: no
210-
HD (hd seed available): yes
211-
Keypool Size: 2000
212-
Transactions: 0
213-
Address Book: 0
214-
''')
183+
out = "Topping up keypool...\n" + self.get_expected_info_output(name="foo", keypool=2000)
215184
self.assert_tool_output(out, '-wallet=foo', 'create')
216185
shasum_after = self.wallet_shasum()
217186
timestamp_after = self.wallet_timestamp()
@@ -237,9 +206,13 @@ def test_getwalletinfo_on_different_wallet(self):
237206
self.log.debug('Wallet file timestamp after calling getwalletinfo: {}'.format(timestamp_after))
238207

239208
assert_equal(0, out['txcount'])
240-
assert_equal(1000, out['keypoolsize'])
241-
assert_equal(1000, out['keypoolsize_hd_internal'])
242-
assert_equal(True, 'hdseedid' in out)
209+
if not self.options.descriptors:
210+
assert_equal(1000, out['keypoolsize'])
211+
assert_equal(1000, out['keypoolsize_hd_internal'])
212+
assert_equal(True, 'hdseedid' in out)
213+
else:
214+
assert_equal(3000, out['keypoolsize'])
215+
assert_equal(3000, out['keypoolsize_hd_internal'])
243216

244217
self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
245218
assert_equal(timestamp_before, timestamp_after)
@@ -261,10 +234,9 @@ def run_test(self):
261234
# Warning: The following tests are order-dependent.
262235
self.test_tool_wallet_info()
263236
self.test_tool_wallet_info_after_transaction()
237+
self.test_tool_wallet_create_on_existing_wallet()
238+
self.test_getwalletinfo_on_different_wallet()
264239
if not self.options.descriptors:
265-
# TODO: Wallet tool needs more create options at which point these can be enabled.
266-
self.test_tool_wallet_create_on_existing_wallet()
267-
self.test_getwalletinfo_on_different_wallet()
268240
# Salvage is a legacy wallet only thing
269241
self.test_salvage()
270242

0 commit comments

Comments
 (0)