3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
5
#include < key.h>
6
- #include < keystore.h>
7
6
#include < script/script.h>
8
7
#include < script/script_error.h>
9
8
#include < script/standard.h>
10
9
#include < test/setup_common.h>
11
10
#include < wallet/ismine.h>
11
+ #include < wallet/wallet.h>
12
12
13
13
#include < boost/test/unit_test.hpp>
14
14
@@ -27,13 +27,15 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
27
27
CKey uncompressedKey;
28
28
uncompressedKey.MakeNewKey (false );
29
29
CPubKey uncompressedPubkey = uncompressedKey.GetPubKey ();
30
+ std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain ();
30
31
31
32
CScript scriptPubKey;
32
33
isminetype result;
33
34
34
35
// P2PK compressed
35
36
{
36
- CBasicKeyStore keystore;
37
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
38
+ LOCK (keystore.cs_wallet );
37
39
scriptPubKey = GetScriptForRawPubKey (pubkeys[0 ]);
38
40
39
41
// Keystore does not have key
@@ -48,7 +50,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
48
50
49
51
// P2PK uncompressed
50
52
{
51
- CBasicKeyStore keystore;
53
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
54
+ LOCK (keystore.cs_wallet );
52
55
scriptPubKey = GetScriptForRawPubKey (uncompressedPubkey);
53
56
54
57
// Keystore does not have key
@@ -63,7 +66,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
63
66
64
67
// P2PKH compressed
65
68
{
66
- CBasicKeyStore keystore;
69
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
70
+ LOCK (keystore.cs_wallet );
67
71
scriptPubKey = GetScriptForDestination (PKHash (pubkeys[0 ]));
68
72
69
73
// Keystore does not have key
@@ -78,7 +82,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
78
82
79
83
// P2PKH uncompressed
80
84
{
81
- CBasicKeyStore keystore;
85
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
86
+ LOCK (keystore.cs_wallet );
82
87
scriptPubKey = GetScriptForDestination (PKHash (uncompressedPubkey));
83
88
84
89
// Keystore does not have key
@@ -93,7 +98,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
93
98
94
99
// P2SH
95
100
{
96
- CBasicKeyStore keystore;
101
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
102
+ LOCK (keystore.cs_wallet );
97
103
98
104
CScript redeemScript = GetScriptForDestination (PKHash (pubkeys[0 ]));
99
105
scriptPubKey = GetScriptForDestination (ScriptHash (redeemScript));
@@ -115,7 +121,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
115
121
116
122
// (P2PKH inside) P2SH inside P2SH (invalid)
117
123
{
118
- CBasicKeyStore keystore;
124
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
125
+ LOCK (keystore.cs_wallet );
119
126
120
127
CScript redeemscript_inner = GetScriptForDestination (PKHash (pubkeys[0 ]));
121
128
CScript redeemscript = GetScriptForDestination (ScriptHash (redeemscript_inner));
@@ -131,7 +138,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
131
138
132
139
// (P2PKH inside) P2SH inside P2WSH (invalid)
133
140
{
134
- CBasicKeyStore keystore;
141
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
142
+ LOCK (keystore.cs_wallet );
135
143
136
144
CScript redeemscript = GetScriptForDestination (PKHash (pubkeys[0 ]));
137
145
CScript witnessscript = GetScriptForDestination (ScriptHash (redeemscript));
@@ -147,7 +155,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
147
155
148
156
// P2WPKH inside P2WSH (invalid)
149
157
{
150
- CBasicKeyStore keystore;
158
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
159
+ LOCK (keystore.cs_wallet );
151
160
152
161
CScript witnessscript = GetScriptForDestination (WitnessV0KeyHash (PKHash (pubkeys[0 ])));
153
162
scriptPubKey = GetScriptForDestination (WitnessV0ScriptHash (witnessscript));
@@ -161,7 +170,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
161
170
162
171
// (P2PKH inside) P2WSH inside P2WSH (invalid)
163
172
{
164
- CBasicKeyStore keystore;
173
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
174
+ LOCK (keystore.cs_wallet );
165
175
166
176
CScript witnessscript_inner = GetScriptForDestination (PKHash (pubkeys[0 ]));
167
177
CScript witnessscript = GetScriptForDestination (WitnessV0ScriptHash (witnessscript_inner));
@@ -177,7 +187,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
177
187
178
188
// P2WPKH compressed
179
189
{
180
- CBasicKeyStore keystore;
190
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
191
+ LOCK (keystore.cs_wallet );
181
192
BOOST_CHECK (keystore.AddKey (keys[0 ]));
182
193
183
194
scriptPubKey = GetScriptForDestination (WitnessV0KeyHash (PKHash (pubkeys[0 ])));
@@ -190,7 +201,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
190
201
191
202
// P2WPKH uncompressed
192
203
{
193
- CBasicKeyStore keystore;
204
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
205
+ LOCK (keystore.cs_wallet );
194
206
BOOST_CHECK (keystore.AddKey (uncompressedKey));
195
207
196
208
scriptPubKey = GetScriptForDestination (WitnessV0KeyHash (PKHash (uncompressedPubkey)));
@@ -207,7 +219,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
207
219
208
220
// scriptPubKey multisig
209
221
{
210
- CBasicKeyStore keystore;
222
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
223
+ LOCK (keystore.cs_wallet );
211
224
212
225
scriptPubKey = GetScriptForMultisig (2 , {uncompressedPubkey, pubkeys[1 ]});
213
226
@@ -236,7 +249,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
236
249
237
250
// P2SH multisig
238
251
{
239
- CBasicKeyStore keystore;
252
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
253
+ LOCK (keystore.cs_wallet );
240
254
BOOST_CHECK (keystore.AddKey (uncompressedKey));
241
255
BOOST_CHECK (keystore.AddKey (keys[1 ]));
242
256
@@ -255,7 +269,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
255
269
256
270
// P2WSH multisig with compressed keys
257
271
{
258
- CBasicKeyStore keystore;
272
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
273
+ LOCK (keystore.cs_wallet );
259
274
BOOST_CHECK (keystore.AddKey (keys[0 ]));
260
275
BOOST_CHECK (keystore.AddKey (keys[1 ]));
261
276
@@ -279,7 +294,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
279
294
280
295
// P2WSH multisig with uncompressed key
281
296
{
282
- CBasicKeyStore keystore;
297
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
298
+ LOCK (keystore.cs_wallet );
283
299
BOOST_CHECK (keystore.AddKey (uncompressedKey));
284
300
BOOST_CHECK (keystore.AddKey (keys[1 ]));
285
301
@@ -303,7 +319,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
303
319
304
320
// P2WSH multisig wrapped in P2SH
305
321
{
306
- CBasicKeyStore keystore;
322
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
323
+ LOCK (keystore.cs_wallet );
307
324
308
325
CScript witnessScript = GetScriptForMultisig (2 , {pubkeys[0 ], pubkeys[1 ]});
309
326
CScript redeemScript = GetScriptForDestination (WitnessV0ScriptHash (witnessScript));
@@ -328,7 +345,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
328
345
329
346
// OP_RETURN
330
347
{
331
- CBasicKeyStore keystore;
348
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
349
+ LOCK (keystore.cs_wallet );
332
350
BOOST_CHECK (keystore.AddKey (keys[0 ]));
333
351
334
352
scriptPubKey.clear ();
@@ -340,7 +358,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
340
358
341
359
// witness unspendable
342
360
{
343
- CBasicKeyStore keystore;
361
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
362
+ LOCK (keystore.cs_wallet );
344
363
BOOST_CHECK (keystore.AddKey (keys[0 ]));
345
364
346
365
scriptPubKey.clear ();
@@ -352,7 +371,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
352
371
353
372
// witness unknown
354
373
{
355
- CBasicKeyStore keystore;
374
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
375
+ LOCK (keystore.cs_wallet );
356
376
BOOST_CHECK (keystore.AddKey (keys[0 ]));
357
377
358
378
scriptPubKey.clear ();
@@ -364,7 +384,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
364
384
365
385
// Nonstandard
366
386
{
367
- CBasicKeyStore keystore;
387
+ CWallet keystore (chain.get (), WalletLocation (), WalletDatabase::CreateDummy ());
388
+ LOCK (keystore.cs_wallet );
368
389
BOOST_CHECK (keystore.AddKey (keys[0 ]));
369
390
370
391
scriptPubKey.clear ();
0 commit comments