Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_tests.cpp
Show First 20 Lines • Show All 1,525 Lines • ▼ Show 20 Lines | tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0H) | ||||
<< OP_CHECKDATASIGVERIFY << OP_TRUE, | << OP_CHECKDATASIGVERIFY << OP_TRUE, | ||||
"CHECKDATASIGVERIFY with invalid hybrid pubkey", | "CHECKDATASIGVERIFY with invalid hybrid pubkey", | ||||
checkdatasigschnorrflags) | checkdatasigschnorrflags) | ||||
.PushDataSig(keys.key0, {}) | .PushDataSig(keys.key0, {}) | ||||
.DamagePush(10) | .DamagePush(10) | ||||
.Num(0) | .Num(0) | ||||
.ScriptError(SCRIPT_ERR_PUBKEYTYPE)); | .ScriptError(SCRIPT_ERR_PUBKEYTYPE)); | ||||
// Tests SCRIPT_ALLOW_SEGWIT_RECOVERY | |||||
tests.push_back( | |||||
TestBuilder(CScript() << OP_0 << ToByteVector(keys.pubkey0.GetID()), | |||||
"v0 P2SH-P2WPKH but no SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH, true) | |||||
.PushRedeem() | |||||
.ScriptError(SCRIPT_ERR_CLEANSTACK)); | |||||
tests.push_back( | |||||
TestBuilder(CScript() << OP_0 << ToByteVector(keys.pubkey0.GetID()), | |||||
"v0 P2SH-P2WPKH with SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH | | |||||
SCRIPT_ALLOW_SEGWIT_RECOVERY, | |||||
true) | |||||
.PushRedeem()); | |||||
std::vector<uint8_t> dummy256 = {90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | |||||
deadalnix: Using a uint256 would ensure by definition that this is the right size. | |||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, | |||||
22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; | |||||
tests.push_back( | |||||
TestBuilder(CScript() << OP_0 << dummy256, | |||||
"v0 P2SH-P2WSH but no SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH, true) | |||||
.PushRedeem() | |||||
.ScriptError(SCRIPT_ERR_CLEANSTACK)); | |||||
tests.push_back( | |||||
TestBuilder(CScript() << OP_0 << dummy256, | |||||
"v0 P2SH-P2WSH with SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH | | |||||
SCRIPT_ALLOW_SEGWIT_RECOVERY, | |||||
true) | |||||
.PushRedeem()); | |||||
// Test of IsWitnessProgram inside SCRIPT_ALLOW_SEGWIT_RECOVERY | |||||
tests.push_back(TestBuilder(CScript() << OP_0 << OP_1, | |||||
"Invalid witness program (too short) with " | |||||
"SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH | | |||||
SCRIPT_ALLOW_SEGWIT_RECOVERY, | |||||
true) | |||||
.PushRedeem() | |||||
.ScriptError(SCRIPT_ERR_CLEANSTACK)); | |||||
tests.push_back( | |||||
TestBuilder(CScript() | |||||
<< OP_0 | |||||
<< std::vector<uint8_t>( | |||||
{90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | |||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, | |||||
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, | |||||
33, 34, 35, 36, 37, 38, 39, 40}), | |||||
deadalnixUnsubmitted Done Inline ActionsTake the previous valid value and add/remove one byte. If not,this too error prone. deadalnix: Take the previous valid value and add/remove one byte. If not,this too error prone.
Too short… | |||||
"Invalid witness program (too long) with " | |||||
"SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH | | |||||
SCRIPT_ALLOW_SEGWIT_RECOVERY, | |||||
true) | |||||
.PushRedeem() | |||||
.ScriptError(SCRIPT_ERR_CLEANSTACK)); | |||||
tests.push_back( | |||||
TestBuilder(CScript() << std::vector<uint8_t>({17}) << dummy256, | |||||
deadalnixUnsubmitted Done Inline ActionsI'm pretty sure you can send 17 in there directly. Or at least that there is something significantly simpler than this. deadalnix: I'm pretty sure you can send 17 in there directly. Or at least that there is something… | |||||
"Invalid witness program (invalid version) with " | |||||
"SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH | | |||||
SCRIPT_ALLOW_SEGWIT_RECOVERY, | |||||
true) | |||||
.PushRedeem() | |||||
.ScriptError(SCRIPT_ERR_CLEANSTACK)); | |||||
tests.push_back(TestBuilder(CScript() << OP_0 << dummy256 << OP_1, | |||||
"Invalid witness program (more than 2 stack " | |||||
"items) with SCRIPT_ALLOW_SEGWIT_RECOVERY", | |||||
SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH | | |||||
SCRIPT_ALLOW_SEGWIT_RECOVERY, | |||||
true) | |||||
.PushRedeem() | |||||
.ScriptError(SCRIPT_ERR_CLEANSTACK)); | |||||
std::set<std::string> tests_set; | std::set<std::string> tests_set; | ||||
{ | { | ||||
UniValue json_tests = read_json(std::string( | UniValue json_tests = read_json(std::string( | ||||
json_tests::script_tests, | json_tests::script_tests, | ||||
json_tests::script_tests + sizeof(json_tests::script_tests))); | json_tests::script_tests + sizeof(json_tests::script_tests))); | ||||
for (unsigned int idx = 0; idx < json_tests.size(); idx++) { | for (unsigned int idx = 0; idx < json_tests.size(); idx++) { | ||||
▲ Show 20 Lines • Show All 755 Lines • Show Last 20 Lines |
Using a uint256 would ensure by definition that this is the right size.