|
4 | 4 |
|
5 | 5 | #include <test/data/bip341_wallet_vectors.json.h>
|
6 | 6 |
|
| 7 | +#include <addresstype.h> |
7 | 8 | #include <key.h>
|
8 | 9 | #include <key_io.h>
|
9 | 10 | #include <script/script.h>
|
@@ -130,9 +131,8 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
|
130 | 131 | BOOST_CHECK(solutions[1] == ToByteVector(uint256::ONE));
|
131 | 132 |
|
132 | 133 | // TxoutType::ANCHOR
|
133 |
| - std::vector<unsigned char> anchor_bytes{0x4e, 0x73}; |
134 | 134 | s.clear();
|
135 |
| - s << OP_1 << anchor_bytes; |
| 135 | + s << OP_1 << ANCHOR_BYTES; |
136 | 136 | BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::ANCHOR);
|
137 | 137 | BOOST_CHECK(solutions.empty());
|
138 | 138 |
|
@@ -197,14 +197,22 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_failure)
|
197 | 197 | s << OP_RETURN << std::vector<unsigned char>({75}) << OP_ADD;
|
198 | 198 | BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::NONSTANDARD);
|
199 | 199 |
|
200 |
| - // TxoutType::WITNESS_UNKNOWN with incorrect program size |
| 200 | + // TxoutType::WITNESS_V0_{KEY,SCRIPT}HASH with incorrect program size (-> consensus-invalid, i.e. non-standard) |
201 | 201 | s.clear();
|
202 | 202 | s << OP_0 << std::vector<unsigned char>(19, 0x01);
|
203 | 203 | BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::NONSTANDARD);
|
204 | 204 |
|
| 205 | + // TxoutType::WITNESS_V1_TAPROOT with incorrect program size (-> undefined, but still policy-valid) |
| 206 | + s.clear(); |
| 207 | + s << OP_1 << std::vector<unsigned char>(31, 0x01); |
| 208 | + BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_UNKNOWN); |
| 209 | + s.clear(); |
| 210 | + s << OP_1 << std::vector<unsigned char>(33, 0x01); |
| 211 | + BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_UNKNOWN); |
| 212 | + |
205 | 213 | // TxoutType::ANCHOR but wrong witness version
|
206 | 214 | s.clear();
|
207 |
| - s << OP_2 << std::vector<unsigned char>{0x4e, 0x73}; |
| 215 | + s << OP_2 << ANCHOR_BYTES; |
208 | 216 | BOOST_CHECK(!s.IsPayToAnchor());
|
209 | 217 | BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_UNKNOWN);
|
210 | 218 |
|
@@ -268,12 +276,32 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
268 | 276 | BOOST_CHECK(ExtractDestination(s, address));
|
269 | 277 | BOOST_CHECK(std::get<WitnessV0ScriptHash>(address) == scripthash);
|
270 | 278 |
|
| 279 | + // TxoutType::WITNESS_V1_TAPROOT |
| 280 | + s.clear(); |
| 281 | + auto xpk = XOnlyPubKey(pubkey); |
| 282 | + s << OP_1 << ToByteVector(xpk); |
| 283 | + BOOST_CHECK(ExtractDestination(s, address)); |
| 284 | + BOOST_CHECK(std::get<WitnessV1Taproot>(address) == WitnessV1Taproot(xpk)); |
| 285 | + |
| 286 | + // TxoutType::ANCHOR |
| 287 | + s.clear(); |
| 288 | + s << OP_1 << ANCHOR_BYTES; |
| 289 | + BOOST_CHECK(ExtractDestination(s, address)); |
| 290 | + BOOST_CHECK(std::get<PayToAnchor>(address) == PayToAnchor()); |
| 291 | + |
271 | 292 | // TxoutType::WITNESS_UNKNOWN with unknown version
|
| 293 | + // -> segwit version 1 with an undefined program size (33 bytes in this test case) |
272 | 294 | s.clear();
|
273 | 295 | s << OP_1 << ToByteVector(pubkey);
|
274 | 296 | BOOST_CHECK(ExtractDestination(s, address));
|
275 |
| - WitnessUnknown unk{1, ToByteVector(pubkey)}; |
276 |
| - BOOST_CHECK(std::get<WitnessUnknown>(address) == unk); |
| 297 | + WitnessUnknown unk_v1{1, ToByteVector(pubkey)}; |
| 298 | + BOOST_CHECK(std::get<WitnessUnknown>(address) == unk_v1); |
| 299 | + s.clear(); |
| 300 | + // -> segwit versions 2+ are not specified yet |
| 301 | + s << OP_2 << ToByteVector(xpk); |
| 302 | + BOOST_CHECK(ExtractDestination(s, address)); |
| 303 | + WitnessUnknown unk_v2{2, ToByteVector(xpk)}; |
| 304 | + BOOST_CHECK(std::get<WitnessUnknown>(address) == unk_v2); |
277 | 305 | }
|
278 | 306 |
|
279 | 307 | BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
@@ -341,6 +369,19 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
341 | 369 | expected << OP_0 << ToByteVector(scriptHash);
|
342 | 370 | result = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
343 | 371 | BOOST_CHECK(result == expected);
|
| 372 | + |
| 373 | + // WitnessV1Taproot |
| 374 | + auto xpk = XOnlyPubKey(pubkeys[0]); |
| 375 | + expected.clear(); |
| 376 | + expected << OP_1 << ToByteVector(xpk); |
| 377 | + result = GetScriptForDestination(WitnessV1Taproot(xpk)); |
| 378 | + BOOST_CHECK(result == expected); |
| 379 | + |
| 380 | + // PayToAnchor |
| 381 | + expected.clear(); |
| 382 | + expected << OP_1 << ANCHOR_BYTES; |
| 383 | + result = GetScriptForDestination(PayToAnchor()); |
| 384 | + BOOST_CHECK(result == expected); |
344 | 385 | }
|
345 | 386 |
|
346 | 387 | BOOST_AUTO_TEST_CASE(script_standard_taproot_builder)
|
|
0 commit comments