@@ -28,8 +28,11 @@ def skip_test_if_missing_module(self):
28
28
29
29
def bitcoin_wallet_process (self , * args ):
30
30
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 )
33
36
34
37
def assert_raises_tool_error (self , error , * args ):
35
38
p = self .bitcoin_wallet_process (* args )
@@ -63,6 +66,36 @@ def log_wallet_timestamp_comparison(self, old, new):
63
66
result = 'unchanged' if new == old else 'increased!'
64
67
self .log .debug ('Wallet file timestamp {}' .format (result ))
65
68
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
+
66
99
def test_invalid_tool_commands_and_args (self ):
67
100
self .log .info ('Testing that various invalid commands raise with specific error messages' )
68
101
self .assert_raises_tool_error ('Invalid command: foo' , 'foo' )
@@ -98,33 +131,7 @@ def test_tool_wallet_info(self):
98
131
# shasum_before = self.wallet_shasum()
99
132
timestamp_before = self .wallet_timestamp ()
100
133
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 )
128
135
self .assert_tool_output (out , '-wallet=' + self .default_wallet_name , 'info' )
129
136
timestamp_after = self .wallet_timestamp ()
130
137
self .log .debug ('Wallet file timestamp after calling info: {}' .format (timestamp_after ))
@@ -155,33 +162,7 @@ def test_tool_wallet_info_after_transaction(self):
155
162
shasum_before = self .wallet_shasum ()
156
163
timestamp_before = self .wallet_timestamp ()
157
164
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 )
185
166
self .assert_tool_output (out , '-wallet=' + self .default_wallet_name , 'info' )
186
167
shasum_after = self .wallet_shasum ()
187
168
timestamp_after = self .wallet_timestamp ()
@@ -199,19 +180,7 @@ def test_tool_wallet_create_on_existing_wallet(self):
199
180
shasum_before = self .wallet_shasum ()
200
181
timestamp_before = self .wallet_timestamp ()
201
182
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 )
215
184
self .assert_tool_output (out , '-wallet=foo' , 'create' )
216
185
shasum_after = self .wallet_shasum ()
217
186
timestamp_after = self .wallet_timestamp ()
@@ -237,9 +206,13 @@ def test_getwalletinfo_on_different_wallet(self):
237
206
self .log .debug ('Wallet file timestamp after calling getwalletinfo: {}' .format (timestamp_after ))
238
207
239
208
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' ])
243
216
244
217
self .log_wallet_timestamp_comparison (timestamp_before , timestamp_after )
245
218
assert_equal (timestamp_before , timestamp_after )
@@ -261,10 +234,9 @@ def run_test(self):
261
234
# Warning: The following tests are order-dependent.
262
235
self .test_tool_wallet_info ()
263
236
self .test_tool_wallet_info_after_transaction ()
237
+ self .test_tool_wallet_create_on_existing_wallet ()
238
+ self .test_getwalletinfo_on_different_wallet ()
264
239
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 ()
268
240
# Salvage is a legacy wallet only thing
269
241
self .test_salvage ()
270
242
0 commit comments