Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_tests.cpp
Show All 30 Lines | |||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <fstream> | #include <fstream> | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
// Uncomment if you want to output updated JSON tests. | // Uncomment if you want to output updated JSON tests. | ||||
#define UPDATE_JSON_TESTS | // #define UPDATE_JSON_TESTS | ||||
deadalnix: Congratulations, you played yourself :) | |||||
static const uint32_t gFlags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; | static const uint32_t gFlags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; | ||||
struct ScriptErrorDesc { | struct ScriptErrorDesc { | ||||
ScriptError err; | ScriptError err; | ||||
const char *name; | const char *name; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 1,990 Lines • ▼ Show 20 Lines | tests.push_back( | ||||
<< OP_CHECKMULTISIG, | << OP_CHECKMULTISIG, | ||||
"CHECKMULTISIG 2-of-8 Schnorr, wrong way to represent 0b10000001", | "CHECKMULTISIG 2-of-8 Schnorr, wrong way to represent 0b10000001", | ||||
newmultisigflags) | newmultisigflags) | ||||
.Num(0b10000001) | .Num(0b10000001) | ||||
.PushSigSchnorr(keys.key0) | .PushSigSchnorr(keys.key0) | ||||
.PushSigSchnorr(keys.key2) | .PushSigSchnorr(keys.key2) | ||||
.SetScriptError(ScriptError::INVALID_BITFIELD_SIZE)); | .SetScriptError(ScriptError::INVALID_BITFIELD_SIZE)); | ||||
tests.push_back( | tests.push_back( | ||||
TestBuilder(CScript() << OP_1 << -1 << -1 << -1 << -1 << -1 | |||||
<< ToByteVector(keys.pubkey0C) << -1 << 7 | |||||
<< OP_CHECKMULTISIG, | |||||
"CHECKMULTISIG 1-of-7 Schnorr, second-to-last key", | |||||
newmultisigflags) | |||||
.Push("20") | |||||
.PushSigSchnorr(keys.key0)); | |||||
tests.push_back( | |||||
TestBuilder(CScript() << OP_1 << -1 << -1 << -1 << -1 << -1 << -1 << -1 | |||||
<< -1 << -1 << -1 << ToByteVector(keys.pubkey0C) | |||||
<< -1 << -1 << 13 << OP_CHECKMULTISIG, | |||||
"CHECKMULTISIG 1-of-13 Schnorr, third-to-last key", | |||||
newmultisigflags) | |||||
.Push("0004") | |||||
.PushSigSchnorr(keys.key0)); | |||||
tests.push_back( | |||||
TestBuilder(CScript() | TestBuilder(CScript() | ||||
<< OP_OVER << OP_DUP << OP_DUP << OP_2DUP << OP_3DUP | << OP_OVER << OP_DUP << OP_DUP << OP_2DUP << OP_3DUP | ||||
<< OP_3DUP << OP_3DUP << OP_3DUP << 20 | << OP_3DUP << OP_3DUP << OP_3DUP << 20 | ||||
<< ToByteVector(keys.pubkey0C) | << ToByteVector(keys.pubkey0C) | ||||
<< ToByteVector(keys.pubkey1C) | << ToByteVector(keys.pubkey1C) | ||||
<< ToByteVector(keys.pubkey2C) << OP_OVER << OP_DUP | << ToByteVector(keys.pubkey2C) << OP_OVER << OP_DUP | ||||
<< OP_DUP << OP_2DUP << OP_3DUP << OP_3DUP << OP_3DUP | << OP_DUP << OP_2DUP << OP_3DUP << OP_3DUP << OP_3DUP | ||||
<< OP_3DUP << 20 << OP_CHECKMULTISIG, | << OP_3DUP << 20 << OP_CHECKMULTISIG, | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | #endif | ||||
for (TestBuilder &test : tests) { | for (TestBuilder &test : tests) { | ||||
test.Test(); | test.Test(); | ||||
std::string str = JSONPrettyPrint(test.GetJSON()); | std::string str = JSONPrettyPrint(test.GetJSON()); | ||||
#ifdef UPDATE_JSON_TESTS | #ifdef UPDATE_JSON_TESTS | ||||
strGen += str + ",\n"; | strGen += str + ",\n"; | ||||
#else | #else | ||||
if (tests_set.count(str) == 0) { | if (tests_set.count(str) == 0) { | ||||
BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + | BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + | ||||
test.GetComment()); | test.GetComment()); | ||||
markblundebergAuthorUnsubmitted Done Inline Actions^ this is the consistency test mentioned in the commit message markblundeberg: ^ this is the consistency test mentioned in the commit message | |||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
#ifdef UPDATE_JSON_TESTS | #ifdef UPDATE_JSON_TESTS | ||||
FILE *file = fopen("script_tests.json.gen", "w"); | FILE *file = fopen("script_tests.json.gen", "w"); | ||||
fputs(strGen.c_str(), file); | fputs(strGen.c_str(), file); | ||||
fclose(file); | fclose(file); | ||||
▲ Show 20 Lines • Show All 806 Lines • Show Last 20 Lines |
Congratulations, you played yourself :)