Branch data Line data Source code
1 : : // Copyright (c) 2017-2022 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <key.h>
6 : : #include <key_io.h>
7 : : #include <node/context.h>
8 : : #include <script/script.h>
9 : : #include <script/solver.h>
10 : : #include <script/signingprovider.h>
11 : : #include <test/util/setup_common.h>
12 : : #include <wallet/types.h>
13 : : #include <wallet/wallet.h>
14 : : #include <wallet/test/util.h>
15 : :
16 : : #include <boost/test/unit_test.hpp>
17 : :
18 : : using namespace util::hex_literals;
19 : :
20 : : namespace wallet {
21 : : BOOST_FIXTURE_TEST_SUITE(ismine_tests, BasicTestingSetup)
22 : :
23 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(ismine_standard)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
24 : : {
25 : 2 : CKey keys[2];
26 [ + + ]: 3 : CPubKey pubkeys[2];
27 [ + + ]: 3 : for (int i = 0; i < 2; i++) {
28 [ + - ]: 2 : keys[i].MakeNewKey(true);
29 [ + - ]: 2 : pubkeys[i] = keys[i].GetPubKey();
30 : : }
31 : :
32 : 1 : CKey uncompressedKey = GenerateRandomKey(/*compressed=*/false);
33 [ + - ]: 1 : CPubKey uncompressedPubkey = uncompressedKey.GetPubKey();
34 : 1 : std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
35 : :
36 : 1 : CScript scriptPubKey;
37 : 1 : isminetype result;
38 : :
39 : : // P2PK compressed - Legacy
40 : 1 : {
41 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
42 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
43 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
44 [ + - ]: 2 : scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
45 : :
46 : : // Keystore does not have key
47 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
48 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
49 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
50 : :
51 : : // Keystore has key
52 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
53 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
54 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
55 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - +
- ]
56 : 1 : }
57 : :
58 : : // P2PK compressed - Descriptor
59 : 1 : {
60 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
61 [ + - + - ]: 2 : std::string desc_str = "pk(" + EncodeSecret(keys[0]) + ")";
62 : :
63 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
64 : :
65 [ + - ]: 2 : scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
66 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
67 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
68 : 1 : }
69 : :
70 : : // P2PK uncompressed - Legacy
71 : 1 : {
72 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
73 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
74 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
75 [ + - ]: 2 : scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
76 : :
77 : : // Keystore does not have key
78 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
79 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
80 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
81 : :
82 : : // Keystore has key
83 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
+ - + - +
- + - ]
84 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
85 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
86 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - +
- ]
87 : 1 : }
88 : :
89 : : // P2PK uncompressed - Descriptor
90 : 1 : {
91 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
92 [ + - + - ]: 2 : std::string desc_str = "pk(" + EncodeSecret(uncompressedKey) + ")";
93 : :
94 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
95 : :
96 [ + - ]: 2 : scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
97 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
98 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
99 : 1 : }
100 : :
101 : : // P2PKH compressed - Legacy
102 : 1 : {
103 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
104 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
105 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
106 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
107 : :
108 : : // Keystore does not have key
109 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
110 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
111 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
112 : :
113 : : // Keystore has key
114 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
115 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
116 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
117 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - +
- ]
118 : 1 : }
119 : :
120 : : // P2PKH compressed - Descriptor
121 : 1 : {
122 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
123 [ + - + - ]: 2 : std::string desc_str = "pkh(" + EncodeSecret(keys[0]) + ")";
124 : :
125 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
126 : :
127 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
128 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
129 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
130 : 1 : }
131 : :
132 : : // P2PKH uncompressed - Legacy
133 : 1 : {
134 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
135 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
136 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
137 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
138 : :
139 : : // Keystore does not have key
140 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
141 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
142 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
143 : :
144 : : // Keystore has key
145 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
+ - + - +
- ]
146 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
147 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
148 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - +
- ]
149 : 1 : }
150 : :
151 : : // P2PKH uncompressed - Descriptor
152 : 1 : {
153 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
154 [ + - + - ]: 2 : std::string desc_str = "pkh(" + EncodeSecret(uncompressedKey) + ")";
155 : :
156 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
157 : :
158 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
159 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
160 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
161 : 1 : }
162 : :
163 : : // P2SH - Legacy
164 : 1 : {
165 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
166 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
167 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
168 : :
169 [ + - + - ]: 1 : CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
170 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
171 : :
172 : : // Keystore does not have redeemScript or key
173 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
174 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
175 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
176 : :
177 : : // Keystore has redeemScript but no key
178 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
+ - + - +
- ]
179 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
180 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
181 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
182 : :
183 : : // Keystore has redeemScript and key
184 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
185 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
186 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
187 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - ]
188 [ + - ]: 2 : }
189 : :
190 : : // P2SH - Descriptor
191 : 1 : {
192 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
193 [ + - + - ]: 2 : std::string desc_str = "sh(pkh(" + EncodeSecret(keys[0]) + "))";
194 : :
195 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
196 : :
197 [ + - + - ]: 1 : CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
198 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
199 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
200 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
201 : 1 : }
202 : :
203 : : // (P2PKH inside) P2SH inside P2SH (invalid) - Legacy
204 : 1 : {
205 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
206 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
207 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
208 : :
209 [ + - + - ]: 1 : CScript redeemscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
210 [ + - + - ]: 1 : CScript redeemscript = GetScriptForDestination(ScriptHash(redeemscript_inner));
211 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemscript));
212 : :
213 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
+ - + - +
- ]
214 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript_inner));
+ - + - +
- ]
215 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
216 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
217 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
218 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
219 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - ]
220 [ + - ]: 2 : }
221 : :
222 : : // (P2PKH inside) P2SH inside P2SH (invalid) - Descriptor
223 : 1 : {
224 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
225 [ + - + - ]: 2 : std::string desc_str = "sh(sh(" + EncodeSecret(keys[0]) + "))";
226 : :
227 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, false);
228 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(spk_manager, nullptr);
229 : 1 : }
230 : :
231 : : // (P2PKH inside) P2SH inside P2WSH (invalid) - Legacy
232 : 1 : {
233 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
234 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
235 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
236 : :
237 [ + - + - ]: 1 : CScript redeemscript = GetScriptForDestination(PKHash(pubkeys[0]));
238 [ + - + - ]: 1 : CScript witnessscript = GetScriptForDestination(ScriptHash(redeemscript));
239 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
240 : :
241 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
+ - + - +
- ]
242 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
+ - + - +
- ]
243 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
244 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
245 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
246 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
247 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - ]
248 [ + - ]: 2 : }
249 : :
250 : : // (P2PKH inside) P2SH inside P2WSH (invalid) - Descriptor
251 : 1 : {
252 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
253 [ + - + - ]: 2 : std::string desc_str = "wsh(sh(" + EncodeSecret(keys[0]) + "))";
254 : :
255 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, false);
256 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(spk_manager, nullptr);
257 : 1 : }
258 : :
259 : : // P2WPKH inside P2WSH (invalid) - Legacy
260 : 1 : {
261 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
262 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
263 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
264 : :
265 [ + - + - ]: 1 : CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
266 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
267 : :
268 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
+ - + - +
- ]
269 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
270 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
271 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
272 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
273 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - ]
274 [ + - ]: 2 : }
275 : :
276 : : // P2WPKH inside P2WSH (invalid) - Descriptor
277 : 1 : {
278 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
279 [ + - + - ]: 2 : std::string desc_str = "wsh(wpkh(" + EncodeSecret(keys[0]) + "))";
280 : :
281 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, false);
282 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(spk_manager, nullptr);
283 : 1 : }
284 : :
285 : : // (P2PKH inside) P2WSH inside P2WSH (invalid) - Legacy
286 : 1 : {
287 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
288 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
289 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
290 : :
291 [ + - + - ]: 1 : CScript witnessscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
292 [ + - + - ]: 1 : CScript witnessscript = GetScriptForDestination(WitnessV0ScriptHash(witnessscript_inner));
293 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
294 : :
295 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript_inner));
+ - + - +
- ]
296 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
+ - + - +
- ]
297 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
298 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
299 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
300 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
301 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - ]
302 [ + - ]: 2 : }
303 : :
304 : : // (P2PKH inside) P2WSH inside P2WSH (invalid) - Descriptor
305 : 1 : {
306 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
307 [ + - + - ]: 2 : std::string desc_str = "wsh(wsh(" + EncodeSecret(keys[0]) + "))";
308 : :
309 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, false);
310 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(spk_manager, nullptr);
311 : 1 : }
312 : :
313 : : // P2WPKH compressed - Legacy
314 : 1 : {
315 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
316 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
317 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
318 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
319 : :
320 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
321 : :
322 : : // Keystore implicitly has key and P2SH redeemScript
323 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
324 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
325 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
326 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - +
- ]
327 : 1 : }
328 : :
329 : : // P2WPKH compressed - Descriptor
330 : 1 : {
331 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
332 [ + - + - ]: 2 : std::string desc_str = "wpkh(" + EncodeSecret(keys[0]) + ")";
333 : :
334 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
335 : :
336 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
337 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
338 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
339 : 1 : }
340 : :
341 : : // P2WPKH uncompressed - Legacy
342 : 1 : {
343 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
344 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
345 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
346 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
+ - + - +
- ]
347 : :
348 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(uncompressedPubkey));
349 : :
350 : : // Keystore has key, but no P2SH redeemScript
351 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
352 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
353 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
354 : :
355 : : // Keystore has key and P2SH redeemScript
356 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
357 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
358 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
359 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
360 : 1 : }
361 : :
362 : : // P2WPKH uncompressed (invalid) - Descriptor
363 : 1 : {
364 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
365 [ + - + - ]: 2 : std::string desc_str = "wpkh(" + EncodeSecret(uncompressedKey) + ")";
366 : :
367 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, false);
368 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(spk_manager, nullptr);
369 : 1 : }
370 : :
371 : : // scriptPubKey multisig - Legacy
372 : 1 : {
373 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
374 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
375 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
376 : :
377 [ + - + - : 2 : scriptPubKey = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
+ - ]
378 : :
379 : : // Keystore does not have any keys
380 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
381 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
382 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
383 : :
384 : : // Keystore has 1/2 keys
385 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
+ - + - +
- ]
386 : :
387 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
388 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
389 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
390 : :
391 : : // Keystore has 2/2 keys
392 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
+ - + - +
- ]
393 : :
394 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
395 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
396 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
397 : :
398 : : // Keystore has 2/2 keys and the script
399 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
400 : :
401 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
402 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
403 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
404 : 1 : }
405 : :
406 : : // scriptPubKey multisig - Descriptor
407 : 1 : {
408 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
409 [ + - + - : 3 : std::string desc_str = "multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + ")";
+ - + - ]
410 : :
411 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
412 : :
413 [ + - + - : 2 : scriptPubKey = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
+ - ]
414 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
415 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
416 : 1 : }
417 : :
418 : : // P2SH multisig - Legacy
419 : 1 : {
420 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
421 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
422 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
423 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
+ - + - +
- ]
424 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
+ - + - +
- ]
425 : :
426 [ + - + - : 2 : CScript redeemScript = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
+ - ]
427 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
428 : :
429 : : // Keystore has no redeemScript
430 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
431 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
432 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
433 : :
434 : : // Keystore has redeemScript
435 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
+ - + - +
- ]
436 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
437 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
438 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - ]
439 [ + - ]: 2 : }
440 : :
441 : : // P2SH multisig - Descriptor
442 : 1 : {
443 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
444 : :
445 [ + - + - : 3 : std::string desc_str = "sh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))";
+ - + - ]
446 : :
447 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
448 : :
449 [ + - + - : 2 : CScript redeemScript = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
+ - ]
450 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
451 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
452 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
453 : 1 : }
454 : :
455 : : // P2WSH multisig with compressed keys - Legacy
456 : 1 : {
457 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
458 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
459 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
460 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
461 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
+ - + - +
- ]
462 : :
463 [ + - + - : 2 : CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
+ - ]
464 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
465 : :
466 : : // Keystore has keys, but no witnessScript or P2SH redeemScript
467 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
468 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
469 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
470 : :
471 : : // Keystore has keys and witnessScript, but no P2SH redeemScript
472 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
+ - + - +
- ]
473 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
474 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
475 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
476 : :
477 : : // Keystore has keys, witnessScript, P2SH redeemScript
478 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
479 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
480 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
481 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - ]
482 [ + - ]: 2 : }
483 : :
484 : : // P2WSH multisig with compressed keys - Descriptor
485 : 1 : {
486 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
487 : :
488 [ + - + - : 3 : std::string desc_str = "wsh(multi(2, " + EncodeSecret(keys[0]) + ", " + EncodeSecret(keys[1]) + "))";
+ - + - ]
489 : :
490 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
491 : :
492 [ + - + - : 2 : CScript redeemScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
+ - ]
493 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(redeemScript));
494 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
495 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
496 : 1 : }
497 : :
498 : : // P2WSH multisig with uncompressed key - Legacy
499 : 1 : {
500 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
501 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
502 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
503 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
+ - + - +
- ]
504 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
+ - + - +
- ]
505 : :
506 [ + - + - : 2 : CScript witnessScript = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
+ - ]
507 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
508 : :
509 : : // Keystore has keys, but no witnessScript or P2SH redeemScript
510 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
511 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
512 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
513 : :
514 : : // Keystore has keys and witnessScript, but no P2SH redeemScript
515 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
+ - + - +
- ]
516 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
517 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
518 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
519 : :
520 : : // Keystore has keys, witnessScript, P2SH redeemScript
521 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
+ - + - +
- ]
522 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
523 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
524 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - ]
525 [ + - ]: 2 : }
526 : :
527 : : // P2WSH multisig with uncompressed key (invalid) - Descriptor
528 : 1 : {
529 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
530 : :
531 [ + - + - : 3 : std::string desc_str = "wsh(multi(2, " + EncodeSecret(uncompressedKey) + ", " + EncodeSecret(keys[1]) + "))";
+ - + - ]
532 : :
533 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, false);
534 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(spk_manager, nullptr);
535 : 1 : }
536 : :
537 : : // P2WSH multisig wrapped in P2SH - Legacy
538 : 1 : {
539 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
540 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
541 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
542 : :
543 [ + - + - : 2 : CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
+ - ]
544 [ + - + - ]: 1 : CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
545 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
546 : :
547 : : // Keystore has no witnessScript, P2SH redeemScript, or keys
548 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
549 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
550 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
551 : :
552 : : // Keystore has witnessScript and P2SH redeemScript, but no keys
553 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
+ - + - +
- ]
554 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
+ - + - +
- ]
555 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
556 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
557 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
558 : :
559 : : // Keystore has keys, witnessScript, P2SH redeemScript
560 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - +
- ]
561 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
+ - + - +
- ]
562 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
563 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
564 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
+ - + - ]
565 [ + - ]: 2 : }
566 : :
567 : : // P2WSH multisig wrapped in P2SH - Descriptor
568 : 1 : {
569 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
570 : :
571 [ + - + - : 3 : std::string desc_str = "sh(wsh(multi(2, " + EncodeSecret(keys[0]) + ", " + EncodeSecret(keys[1]) + ")))";
+ - + - ]
572 : :
573 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
574 : :
575 [ + - + - : 2 : CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
+ - ]
576 [ + - + - ]: 1 : CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
577 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
578 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
579 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
580 : 1 : }
581 : :
582 : : // Combo - Descriptor
583 : 1 : {
584 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
585 : :
586 [ + - + - ]: 2 : std::string desc_str = "combo(" + EncodeSecret(keys[0]) + ")";
587 : :
588 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
589 : :
590 : : // Test P2PK
591 [ + - + - ]: 1 : result = spk_manager->IsMine(GetScriptForRawPubKey(pubkeys[0]));
592 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
593 : :
594 : : // Test P2PKH
595 [ + - + - : 1 : result = spk_manager->IsMine(GetScriptForDestination(PKHash(pubkeys[0])));
+ - ]
596 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
597 : :
598 : : // Test P2SH (combo descriptor does not describe P2SH)
599 [ + - + - ]: 1 : CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
600 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
601 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
602 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
603 : :
604 : : // Test P2WPKH
605 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
606 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
607 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
608 : :
609 : : // P2SH-P2WPKH output
610 [ + - + - ]: 2 : redeemScript = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
611 [ + - + - ]: 2 : scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
612 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
613 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
614 : :
615 : : // Test P2TR (combo descriptor does not describe P2TR)
616 : 1 : XOnlyPubKey xpk(pubkeys[0]);
617 [ + - + - ]: 1 : Assert(xpk.IsFullyValid());
618 [ + - ]: 1 : TaprootBuilder builder;
619 [ + - ]: 1 : builder.Finalize(xpk);
620 [ + - ]: 1 : WitnessV1Taproot output = builder.GetOutput();
621 [ + - ]: 2 : scriptPubKey = GetScriptForDestination(output);
622 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
623 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
624 : 1 : }
625 : :
626 : : // Taproot - Descriptor
627 : 1 : {
628 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
629 : :
630 [ + - + - ]: 2 : std::string desc_str = "tr(" + EncodeSecret(keys[0]) + ")";
631 : :
632 [ + - ]: 1 : auto spk_manager = CreateDescriptor(keystore, desc_str, true);
633 : :
634 : 1 : XOnlyPubKey xpk(pubkeys[0]);
635 [ + - + - ]: 1 : Assert(xpk.IsFullyValid());
636 [ + - ]: 1 : TaprootBuilder builder;
637 [ + - ]: 1 : builder.Finalize(xpk);
638 [ + - ]: 1 : WitnessV1Taproot output = builder.GetOutput();
639 [ + - ]: 2 : scriptPubKey = GetScriptForDestination(output);
640 [ + - ]: 1 : result = spk_manager->IsMine(scriptPubKey);
641 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
642 : 1 : }
643 : :
644 : : // OP_RETURN
645 : 1 : {
646 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
647 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
648 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
649 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - ]
650 : :
651 : 1 : scriptPubKey.clear();
652 [ + - + - ]: 1 : scriptPubKey << OP_RETURN << ToByteVector(pubkeys[0]);
653 : :
654 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
655 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
656 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
657 : 1 : }
658 : :
659 : : // witness unspendable
660 : 1 : {
661 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
662 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
663 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
664 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - ]
665 : :
666 : 1 : scriptPubKey.clear();
667 [ + - ]: 1 : scriptPubKey << OP_0 << "aabb"_hex;
668 : :
669 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
670 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
671 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
672 : 1 : }
673 : :
674 : : // witness unknown
675 : 1 : {
676 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
677 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
678 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
679 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - ]
680 : :
681 : 1 : scriptPubKey.clear();
682 [ + - ]: 1 : scriptPubKey << OP_16 << "aabb"_hex;
683 : :
684 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
685 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
686 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
687 : 1 : }
688 : :
689 : : // Nonstandard
690 : 1 : {
691 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
692 [ + - ]: 1 : keystore.SetupLegacyScriptPubKeyMan();
693 [ + - + - ]: 1 : LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
694 [ + - + - : 2 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
+ - + - ]
695 : :
696 : 1 : scriptPubKey.clear();
697 [ + - + - : 1 : scriptPubKey << OP_9 << OP_ADD << OP_11 << OP_EQUAL;
+ - + - ]
698 : :
699 [ + - + - ]: 1 : result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
700 [ + - + - ]: 1 : BOOST_CHECK_EQUAL(result, ISMINE_NO);
701 [ + - + - : 3 : BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
+ - + - +
- ]
702 : 1 : }
703 [ + + - - ]: 4 : }
704 : :
705 : : BOOST_AUTO_TEST_SUITE_END()
706 : : } // namespace wallet
|