Skip to content

Commit 5088360

Browse files
uncomputableroconnor-blockstream
authored andcommitted
Asset tests: Check script error
Compare the expected script error, parsed from JSON, with the actual error that VerifyScript returns. If the JSON does not include an expected error, then skip this check.
1 parent 4ca2411 commit 5088360

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/test/script_tests.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <cstdint>
2828
#include <fstream>
29+
#include <optional>
2930
#include <string>
3031
#include <vector>
3132

@@ -1740,8 +1741,10 @@ static void AssetTest(const UniValue& test)
17401741
// "final": true tests are valid for all flags. Others are only valid with flags that are
17411742
// a subset of test_flags.
17421743
if (fin || ((flags & test_flags) == flags)) {
1743-
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.witness.vtxinwit[idx].scriptWitness, flags, txcheck, nullptr);
1744+
ScriptError serror;
1745+
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.witness.vtxinwit[idx].scriptWitness, flags, txcheck, &serror);
17441746
BOOST_CHECK(ret);
1747+
BOOST_CHECK_EQUAL(serror, SCRIPT_ERR_OK);
17451748
}
17461749
}
17471750
}
@@ -1753,11 +1756,22 @@ static void AssetTest(const UniValue& test)
17531756
PrecomputedTransactionData txdata(hash_genesis_block);
17541757
txdata.Init(tx, std::vector<CTxOut>(prevouts));
17551758
CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata);
1759+
1760+
std::optional<ScriptError> expected_error;
1761+
if (test["failure"].exists("error")) {
1762+
expected_error = ParseScriptError(test["failure"]["error"].get_str());
1763+
}
1764+
17561765
for (const auto flags : ALL_CONSENSUS_FLAGS) {
17571766
// If a test is supposed to fail with test_flags, it should also fail with any superset thereof.
17581767
if ((flags & test_flags) == test_flags) {
1759-
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.witness.vtxinwit[idx].scriptWitness, flags, txcheck, nullptr);
1768+
ScriptError serror;
1769+
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.witness.vtxinwit[idx].scriptWitness, flags, txcheck, &serror);
17601770
BOOST_CHECK(!ret);
1771+
1772+
if (expected_error) {
1773+
BOOST_CHECK_EQUAL(serror, *expected_error);
1774+
}
17611775
}
17621776
}
17631777
}

0 commit comments

Comments
 (0)