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.
This commit is contained in:
Ethan Heilman 2025-03-20 18:55:31 -04:00
parent 998386d446
commit 3e167085ba

View file

@ -925,7 +925,12 @@ BOOST_AUTO_TEST_CASE(script_json_test)
if (test.size() > 0 && test[pos].isArray()) {
unsigned int i=0;
for (i = 0; i < test[pos].size()-1; i++) {
witness.stack.push_back(ParseHex(test[pos][i].get_str()));
auto element = test[pos][i].get_str();
const auto witness_value{TryParseHex<unsigned char>(element)};
if (!witness_value.has_value()) {
BOOST_ERROR("Bad witness in test: " << strTest << " witness is not hex: " << element);
}
witness.stack.push_back(witness_value.value());
}
nValue = AmountFromValue(test[pos][i]);
pos++;