@@ -25,7 +25,7 @@ def mock_signer_path(self):
25
25
return path
26
26
27
27
def set_test_params (self ):
28
- self .num_nodes = 3
28
+ self .num_nodes = 4
29
29
30
30
self .extra_args = [
31
31
[],
@@ -54,7 +54,7 @@ def run_test(self):
54
54
55
55
# Handle script missing:
56
56
assert_raises_rpc_error (- 1 , 'execve failed: No such file or directory' ,
57
- self .nodes [2 ].enumeratesigners
57
+ self .nodes [3 ].enumeratesigners
58
58
)
59
59
60
60
# Handle error thrown by script
@@ -100,7 +100,7 @@ def run_test(self):
100
100
# )
101
101
# self.clear_mock_result(self.nodes[1])
102
102
103
- assert_equal (hww .getwalletinfo ()["keypoolsize" ], 3 )
103
+ assert_equal (hww .getwalletinfo ()["keypoolsize" ], 30 )
104
104
105
105
address1 = hww .getnewaddress (address_type = "bech32" )
106
106
assert_equal (address1 , "bcrt1qm90ugl4d48jv8n6e5t9ln6t9zlpm5th68x4f8g" )
@@ -134,5 +134,84 @@ def run_test(self):
134
134
)
135
135
self .clear_mock_result (self .nodes [1 ])
136
136
137
+ self .log .info ('Prepare mock PSBT' )
138
+ self .nodes [0 ].sendtoaddress (address1 , 1 )
139
+ self .nodes [0 ].generate (1 )
140
+ self .sync_all ()
141
+
142
+ # Load private key into wallet to generate a signed PSBT for the mock
143
+ self .nodes [1 ].createwallet (wallet_name = "mock" , disable_private_keys = False , blank = True , descriptors = True )
144
+ mock_wallet = self .nodes [1 ].get_wallet_rpc ("mock" )
145
+ assert mock_wallet .getwalletinfo ()['private_keys_enabled' ]
146
+
147
+ result = mock_wallet .importdescriptors ([{
148
+ "desc" : "wpkh([00000001/84'/1'/0']tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0/*)#rweraev0" ,
149
+ "timestamp" : 0 ,
150
+ "range" : [0 ,1 ],
151
+ "internal" : False ,
152
+ "active" : True
153
+ },
154
+ {
155
+ "desc" : "wpkh([00000001/84'/1'/0']tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/*)#j6uzqvuh" ,
156
+ "timestamp" : 0 ,
157
+ "range" : [0 , 0 ],
158
+ "internal" : True ,
159
+ "active" : True
160
+ }])
161
+ assert_equal (result [0 ], {'success' : True })
162
+ assert_equal (result [1 ], {'success' : True })
163
+ assert_equal (mock_wallet .getwalletinfo ()["txcount" ], 1 )
164
+ dest = self .nodes [0 ].getnewaddress (address_type = 'bech32' )
165
+ mock_psbt = mock_wallet .walletcreatefundedpsbt ([], {dest :0.5 }, 0 , {}, True )['psbt' ]
166
+ mock_psbt_signed = mock_wallet .walletprocesspsbt (psbt = mock_psbt , sign = True , sighashtype = "ALL" , bip32derivs = True )
167
+ mock_psbt_final = mock_wallet .finalizepsbt (mock_psbt_signed ["psbt" ])
168
+ mock_tx = mock_psbt_final ["hex" ]
169
+ assert (mock_wallet .testmempoolaccept ([mock_tx ])[0 ]["allowed" ])
170
+
171
+ # # Create a new wallet and populate with specific public keys, in order
172
+ # # to work with the mock signed PSBT.
173
+ # self.nodes[1].createwallet(wallet_name="hww4", disable_private_keys=True, descriptors=True, external_signer=True)
174
+ # hww4 = self.nodes[1].get_wallet_rpc("hww4")
175
+ #
176
+ # descriptors = [{
177
+ # "desc": "wpkh([00000001/84'/1'/0']tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/0/*)#x30uthjs",
178
+ # "timestamp": "now",
179
+ # "range": [0, 1],
180
+ # "internal": False,
181
+ # "watchonly": True,
182
+ # "active": True
183
+ # },
184
+ # {
185
+ # "desc": "wpkh([00000001/84'/1'/0']tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/*)#h92akzzg",
186
+ # "timestamp": "now",
187
+ # "range": [0, 0],
188
+ # "internal": True,
189
+ # "watchonly": True,
190
+ # "active": True
191
+ # }]
192
+
193
+ # result = hww4.importdescriptors(descriptors)
194
+ # assert_equal(result[0], {'success': True})
195
+ # assert_equal(result[1], {'success': True})
196
+ assert_equal (hww .getwalletinfo ()["txcount" ], 1 )
197
+
198
+ assert (hww .testmempoolaccept ([mock_tx ])[0 ]["allowed" ])
199
+
200
+ with open (os .path .join (self .nodes [1 ].cwd , "mock_psbt" ), "w" , encoding = "utf8" ) as f :
201
+ f .write (mock_psbt_signed ["psbt" ])
202
+
203
+ self .log .info ('Test send using hww1' )
204
+
205
+ res = hww .send (outputs = {dest :0.5 },options = {"add_to_wallet" : False })
206
+ assert (res ["complete" ])
207
+ assert_equal (res ["hex" ], mock_tx )
208
+
209
+ # # Handle error thrown by script
210
+ # self.set_mock_result(self.nodes[4], "2")
211
+ # assert_raises_rpc_error(-1, 'Unable to parse JSON',
212
+ # hww4.signerprocesspsbt, psbt_orig, "00000001"
213
+ # )
214
+ # self.clear_mock_result(self.nodes[4])
215
+
137
216
if __name__ == '__main__' :
138
217
SignerTest ().main ()
0 commit comments