Changeset View
Changeset View
Standalone View
Standalone View
src/test/sigopcount_tests.cpp
Show All 20 Lines | |||||
// Helpers: | // Helpers: | ||||
static std::vector<uint8_t> Serialize(const CScript &s) { | static std::vector<uint8_t> Serialize(const CScript &s) { | ||||
std::vector<uint8_t> sSerialized(s.begin(), s.end()); | std::vector<uint8_t> sSerialized(s.begin(), s.end()); | ||||
return sSerialized; | return sSerialized; | ||||
} | } | ||||
BOOST_FIXTURE_TEST_SUITE(sigopcount_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(sigopcount_tests, BasicTestingSetup) | ||||
void CheckScriptSigOps(const CScript &script, uint32_t accurate_sigops, | |||||
uint32_t inaccurate_sigops) { | |||||
BOOST_CHECK_EQUAL(script.GetSigOpCount(false), inaccurate_sigops); | |||||
BOOST_CHECK_EQUAL(script.GetSigOpCount(true), accurate_sigops); | |||||
const CScript p2sh = GetScriptForDestination(CScriptID(script)); | |||||
const CScript scriptSig = CScript() << OP_0 << Serialize(script); | |||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), accurate_sigops); | |||||
// Check that GetSigOpCount report the exact count when not passed a P2SH. | |||||
BOOST_CHECK_EQUAL(script.GetSigOpCount(p2sh), accurate_sigops); | |||||
} | |||||
BOOST_AUTO_TEST_CASE(GetSigOpCount) { | BOOST_AUTO_TEST_CASE(GetSigOpCount) { | ||||
// Test CScript::GetSigOpCount() | // Test CScript::GetSigOpCount() | ||||
CScript s1; | CheckScriptSigOps(CScript(), 0, 0); | ||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U); | |||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U); | |||||
uint160 dummy; | uint160 dummy; | ||||
s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 | const CScript s1 = CScript() | ||||
<< OP_CHECKMULTISIG; | << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) | ||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U); | << OP_2 << OP_CHECKMULTISIG; | ||||
s1 << OP_IF << OP_CHECKSIG << OP_ENDIF; | CheckScriptSigOps(s1, 2, 20); | ||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U); | |||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21U); | const CScript s2 = CScript(s1) << OP_IF << OP_CHECKSIG << OP_ENDIF; | ||||
CheckScriptSigOps(s2, 3, 21); | |||||
CScript p2sh = GetScriptForDestination(CScriptID(s1)); | |||||
CScript scriptSig; | |||||
scriptSig << OP_0 << Serialize(s1); | |||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3U); | |||||
std::vector<CPubKey> keys; | std::vector<CPubKey> keys; | ||||
for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
CKey k; | CKey k; | ||||
k.MakeNewKey(true); | k.MakeNewKey(true); | ||||
keys.push_back(k.GetPubKey()); | keys.push_back(k.GetPubKey()); | ||||
} | } | ||||
CScript s2 = GetScriptForMultisig(1, keys); | |||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3U); | const CScript s3 = GetScriptForMultisig(1, keys); | ||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20U); | CheckScriptSigOps(s3, 3, 20); | ||||
p2sh = GetScriptForDestination(CScriptID(s2)); | const CScript p2sh = GetScriptForDestination(CScriptID(s3)); | ||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U); | CheckScriptSigOps(p2sh, 0, 0); | ||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U); | |||||
CScript scriptSig2; | CScript scriptSig2; | ||||
scriptSig2 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) | scriptSig2 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) | ||||
<< Serialize(s2); | << Serialize(s3); | ||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U); | BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U); | ||||
} | } | ||||
/** | /** | ||||
* Verifies script execution of the zeroth scriptPubKey of tx output and zeroth | * Verifies script execution of the zeroth scriptPubKey of tx output and zeroth | ||||
* scriptSig and witness of tx input. | * scriptSig and witness of tx input. | ||||
*/ | */ | ||||
ScriptError VerifyWithFlag(const CTransaction &output, | ScriptError VerifyWithFlag(const CTransaction &output, | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |