could add checks that the txout types are as labeled, e.g.
0diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
1index fb1829db7e5..90a34aa778c 100644
2--- a/src/test/transaction_tests.cpp
3+++ b/src/test/transaction_tests.cpp
4@@ -1171,12 +1171,22 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
5 tx_create.vout[0].scriptPubKey = GetScriptForDestination(PubKeyDestination{pubkey});
6 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
7 AddCoins(coins, CTransaction{tx_create}, 0, false);
8+ {
9+ std::vector<std::vector<unsigned char>> vSolutions;
10+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
11+ BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
12+ }
13 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
14
15 // P2PKH
16 tx_create.vout[0].scriptPubKey = GetScriptForDestination(PKHash{pubkey});
17 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
18 AddCoins(coins, CTransaction{tx_create}, 0, false);
19+ {
20+ std::vector<std::vector<unsigned char>> vSolutions;
21+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
22+ BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
23+ }
24 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
25
26 // P2SH
27@@ -1185,6 +1195,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
28 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
29 tx_spend.vin[0].scriptSig = CScript{} << OP_0 << ToByteVector(redeem_script);
30 AddCoins(coins, CTransaction{tx_create}, 0, false);
31+ {
32+ std::vector<std::vector<unsigned char>> vSolutions;
33+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
34+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
35+ }
36 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
37 tx_spend.vin[0].scriptSig.clear();
38
39@@ -1193,6 +1208,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
40 tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash{witness_script});
41 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
42 AddCoins(coins, CTransaction{tx_create}, 0, false);
43+ {
44+ std::vector<std::vector<unsigned char>> vSolutions;
45+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
46+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_V0_SCRIPTHASH);
47+ }
48 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
49
50 // P2SH-wrapped P2WSH
51@@ -1201,6 +1221,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
52 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
53 tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
54 AddCoins(coins, CTransaction{tx_create}, 0, false);
55+ {
56+ std::vector<std::vector<unsigned char>> vSolutions;
57+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
58+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
59+ }
60 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
61 tx_spend.vin[0].scriptSig.clear();
62 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
63@@ -1209,6 +1234,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
64 tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessV0KeyHash{pubkey});
65 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
66 AddCoins(coins, CTransaction{tx_create}, 0, false);
67+ {
68+ std::vector<std::vector<unsigned char>> vSolutions;
69+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
70+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_V0_KEYHASH);
71+ }
72 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
73
74 // P2SH-wrapped P2WSH
75@@ -1217,6 +1247,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
76 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
77 tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
78 AddCoins(coins, CTransaction{tx_create}, 0, false);
79+ {
80+ std::vector<std::vector<unsigned char>> vSolutions;
81+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
82+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
83+ }
84 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
85 tx_spend.vin[0].scriptSig.clear();
86 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
87@@ -1225,6 +1260,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
88 tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessV1Taproot{XOnlyPubKey{pubkey}});
89 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
90 AddCoins(coins, CTransaction{tx_create}, 0, false);
91+ {
92+ std::vector<std::vector<unsigned char>> vSolutions;
93+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
94+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_V1_TAPROOT);
95+ }
96 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
97
98 // P2SH-wrapped P2TR (undefined, non-standard)
99@@ -1233,6 +1273,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
100 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
101 tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
102 AddCoins(coins, CTransaction{tx_create}, 0, false);
103+ {
104+ std::vector<std::vector<unsigned char>> vSolutions;
105+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
106+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
107+ }
108 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
109 tx_spend.vin[0].scriptSig.clear();
110 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
111@@ -1241,6 +1286,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
112 tx_create.vout[0].scriptPubKey = GetScriptForDestination(PayToAnchor{});
113 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
114 AddCoins(coins, CTransaction{tx_create}, 0, false);
115+ {
116+ std::vector<std::vector<unsigned char>> vSolutions;
117+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
118+ BOOST_CHECK_EQUAL(whichType, TxoutType::ANCHOR);
119+ }
120 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
121
122 // P2SH-wrapped P2A (undefined, non-standard)
123@@ -1249,6 +1299,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
124 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
125 tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
126 AddCoins(coins, CTransaction{tx_create}, 0, false);
127+ {
128+ std::vector<std::vector<unsigned char>> vSolutions;
129+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
130+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
131+ }
132 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
133 tx_spend.vin[0].scriptSig.clear();
134
135@@ -1256,6 +1311,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
136 tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessUnknown{1, {0x42, 0x42}});
137 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
138 AddCoins(coins, CTransaction{tx_create}, 0, false);
139+ {
140+ std::vector<std::vector<unsigned char>> vSolutions;
141+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
142+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_UNKNOWN);
143+ }
144 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
145
146 // P2SH-wrapped undefined version 1 witness program
147@@ -1264,6 +1324,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
148 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
149 tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
150 AddCoins(coins, CTransaction{tx_create}, 0, false);
151+ {
152+ std::vector<std::vector<unsigned char>> vSolutions;
153+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
154+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
155+ }
156 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
157 tx_spend.vin[0].scriptSig.clear();
158 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
159@@ -1274,6 +1339,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
160 tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessUnknown{i, program});
161 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
162 AddCoins(coins, CTransaction{tx_create}, 0, false);
163+ {
164+ std::vector<std::vector<unsigned char>> vSolutions;
165+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
166+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_UNKNOWN);
167+ }
168 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
169
170 // It's also detected within P2SH.
171@@ -1282,6 +1352,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
172 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
173 tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
174 AddCoins(coins, CTransaction{tx_create}, 0, false);
175+ {
176+ std::vector<std::vector<unsigned char>> vSolutions;
177+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
178+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
179+ }
180 BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
181 tx_spend.vin[0].scriptSig.clear();
182 BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));