could add checks that the txout types are as labeled, e.g.
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index fb1829db7e5..90a34aa778c 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -1171,12 +1171,22 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(PubKeyDestination{pubkey});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
+ }
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2PKH
tx_create.vout[0].scriptPubKey = GetScriptForDestination(PKHash{pubkey});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
+ }
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2SH
@@ -1185,6 +1195,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << OP_0 << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
@@ -1193,6 +1208,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash{witness_script});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_V0_SCRIPTHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2SH-wrapped P2WSH
@@ -1201,6 +1221,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
@@ -1209,6 +1234,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessV0KeyHash{pubkey});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_V0_KEYHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2SH-wrapped P2WSH
@@ -1217,6 +1247,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
@@ -1225,6 +1260,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessV1Taproot{XOnlyPubKey{pubkey}});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_V1_TAPROOT);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2SH-wrapped P2TR (undefined, non-standard)
@@ -1233,6 +1273,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
@@ -1241,6 +1286,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(PayToAnchor{});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::ANCHOR);
+ }
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2SH-wrapped P2A (undefined, non-standard)
@@ -1249,6 +1299,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
@@ -1256,6 +1311,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessUnknown{1, {0x42, 0x42}});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_UNKNOWN);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// P2SH-wrapped undefined version 1 witness program
@@ -1264,6 +1324,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
@@ -1274,6 +1339,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_create.vout[0].scriptPubKey = GetScriptForDestination(WitnessUnknown{i, program});
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::WITNESS_UNKNOWN);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
// It's also detected within P2SH.
@@ -1282,6 +1352,11 @@ BOOST_AUTO_TEST_CASE(spends_witness_prog)
tx_spend.vin[0].prevout.hash = tx_create.GetHash();
tx_spend.vin[0].scriptSig = CScript{} << ToByteVector(redeem_script);
AddCoins(coins, CTransaction{tx_create}, 0, false);
+ {
+ std::vector<std::vector<unsigned char>> vSolutions;
+ TxoutType whichType = Solver(tx_create.vout[0].scriptPubKey, vSolutions);
+ BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
+ }
BOOST_CHECK(::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));
tx_spend.vin[0].scriptSig.clear();
BOOST_CHECK(!::SpendsNonAnchorWitnessProg(CTransaction{tx_spend}, coins));