Skip to content

Commit 3e16708

Browse files
committed
test: Ensures test fails if witness is not hex
This commit ensures that we do not fail silently when the test script encounters a witness string in the JSON test data that can not be parsed as hex.
1 parent 998386d commit 3e16708

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/test/script_tests.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,12 @@ BOOST_AUTO_TEST_CASE(script_json_test)
925925
if (test.size() > 0 && test[pos].isArray()) {
926926
unsigned int i=0;
927927
for (i = 0; i < test[pos].size()-1; i++) {
928-
witness.stack.push_back(ParseHex(test[pos][i].get_str()));
928+
auto element = test[pos][i].get_str();
929+
const auto witness_value{TryParseHex<unsigned char>(element)};
930+
if (!witness_value.has_value()) {
931+
BOOST_ERROR("Bad witness in test: " << strTest << " witness is not hex: " << element);
932+
}
933+
witness.stack.push_back(witness_value.value());
929934
}
930935
nValue = AmountFromValue(test[pos][i]);
931936
pos++;

0 commit comments

Comments
 (0)