mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge d184fc3ba4 into merged_master (Bitcoin PR bitcoin/bitcoin#30571)
This commit is contained in:
commit
c7d1ee1c41
48 changed files with 515 additions and 460 deletions
|
|
@ -148,8 +148,7 @@ static ScriptError_t ParseScriptError(const std::string& name)
|
|||
return SCRIPT_ERR_UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup)
|
||||
|
||||
struct ScriptTest : BasicTestingSetup {
|
||||
void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScriptWitness& scriptWitness, uint32_t flags, const std::string& message, int scriptError, CAmount nValue = 0)
|
||||
{
|
||||
bool expect = (scriptError == SCRIPT_ERR_OK);
|
||||
|
|
@ -166,7 +165,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
|
|||
|
||||
// Verify that removing flags from a passing test or adding flags to a failing test does not change the result.
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
uint32_t extra_flags(InsecureRandBits(16));
|
||||
uint32_t extra_flags(m_rng.randbits(16));
|
||||
uint32_t combined_flags{expect ? (flags & ~extra_flags) : (flags | extra_flags)};
|
||||
// Weed out some invalid flag combinations.
|
||||
if (combined_flags & SCRIPT_VERIFY_CLEANSTACK && ~combined_flags & (SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS)) continue;
|
||||
|
|
@ -174,6 +173,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
|
|||
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, combined_flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue, MissingDataBehavior::ASSERT_FAIL), &err) == expect, message + strprintf(" (with flags %x)", combined_flags));
|
||||
}
|
||||
}
|
||||
}; // struct ScriptTest
|
||||
|
||||
void static NegateSignatureS(std::vector<unsigned char>& vchSig) {
|
||||
// Parse the signature.
|
||||
|
|
@ -407,11 +407,11 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
TestBuilder& Test()
|
||||
TestBuilder& Test(ScriptTest& test)
|
||||
{
|
||||
TestBuilder copy = *this; // Make a copy so we can rollback the push.
|
||||
DoPush();
|
||||
DoTest(creditTx->vout[0].scriptPubKey, spendTx.vin[0].scriptSig, scriptWitness, flags, comment, scriptError, nValue);
|
||||
test.DoTest(creditTx->vout[0].scriptPubKey, spendTx.vin[0].scriptSig, scriptWitness, flags, comment, scriptError, nValue);
|
||||
*this = copy;
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -463,6 +463,8 @@ std::string JSONPrettyPrint(const UniValue& univalue)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(script_tests, ScriptTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(script_build)
|
||||
{
|
||||
const KeyData keys;
|
||||
|
|
@ -922,7 +924,7 @@ BOOST_AUTO_TEST_CASE(script_build)
|
|||
std::string strGen;
|
||||
#endif
|
||||
for (TestBuilder& test : tests) {
|
||||
test.Test();
|
||||
test.Test(*this);
|
||||
std::string str = JSONPrettyPrint(test.GetJSON());
|
||||
#ifdef UPDATE_JSON_TESTS
|
||||
strGen += str + ",\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue