Skip to content

Commit

Permalink
test: refactor: deduplicate anchor witness program bytes (0x4e,0x73)
Browse files Browse the repository at this point in the history
  • Loading branch information
theStack committed Nov 21, 2024
1 parent 51dc01d commit 14acdf7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/test/script_standard_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <script/script.h>
#include <script/signingprovider.h>
#include <script/solver.h>
#include <test/util/script.h>
#include <test/util/setup_common.h>
#include <util/strencodings.h>

Expand Down Expand Up @@ -130,7 +131,6 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
BOOST_CHECK(solutions[1] == ToByteVector(uint256::ONE));

// TxoutType::ANCHOR
std::vector<unsigned char> anchor_bytes{0x4e, 0x73};
s.clear();
s << OP_1 << anchor_bytes;
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::ANCHOR);
Expand Down Expand Up @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_failure)

// TxoutType::ANCHOR but wrong witness version
s.clear();
s << OP_2 << std::vector<unsigned char>{0x4e, 0x73};
s << OP_2 << anchor_bytes;
BOOST_CHECK(!s.IsPayToAnchor());
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_UNKNOWN);

Expand Down Expand Up @@ -279,7 +279,6 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
BOOST_CHECK(std::get<WitnessV1Taproot>(address) == WitnessV1Taproot(xpk));

// TxoutType::ANCHOR
std::vector<unsigned char> anchor_bytes{0x4e, 0x73};
s.clear();
s << OP_1 << anchor_bytes;
BOOST_CHECK(ExtractDestination(s, address));
Expand Down Expand Up @@ -367,7 +366,6 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
BOOST_CHECK(result == expected);

// PayToAnchor
std::vector<unsigned char> anchor_bytes{0x4e, 0x73};
expected.clear();
expected << OP_1 << anchor_bytes;
result = GetScriptForDestination(PayToAnchor());
Expand Down
2 changes: 1 addition & 1 deletion src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
}

// Check anchor outputs
t.vout[0].scriptPubKey = CScript() << OP_1 << std::vector<unsigned char>{0x4e, 0x73};
t.vout[0].scriptPubKey = CScript() << OP_1 << anchor_bytes;
BOOST_CHECK(t.vout[0].scriptPubKey.IsPayToAnchor());
t.vout[0].nValue = 240;
CheckIsStandard(t);
Expand Down
3 changes: 3 additions & 0 deletions src/test/util/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ static const CScript P2WSH_EMPTY{
static const std::vector<std::vector<uint8_t>> P2WSH_EMPTY_TRUE_STACK{{static_cast<uint8_t>(OP_TRUE)}, {}};
static const std::vector<std::vector<uint8_t>> P2WSH_EMPTY_TWO_STACK{{static_cast<uint8_t>(OP_2)}, {}};

/** Witness program for Pay-to-Anchor output script type */
static const std::vector<unsigned char> anchor_bytes{0x4e, 0x73};

/** Flags that are not forbidden by an assert in script validation */
bool IsValidFlagCombination(unsigned flags);

Expand Down

0 comments on commit 14acdf7

Please sign in to comment.