Changeset View
Changeset View
Standalone View
Standalone View
src/test/sigopcount_tests.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
static ScriptError VerifyWithFlag(const CTransaction &output, | static ScriptError VerifyWithFlag(const CTransaction &output, | ||||
const CMutableTransaction &input, int flags) { | const CMutableTransaction &input, int flags) { | ||||
ScriptError error; | ScriptError error; | ||||
CTransaction inputi(input); | CTransaction inputi(input); | ||||
bool ret = VerifyScript( | bool ret = VerifyScript( | ||||
inputi.vin[0].scriptSig, output.vout[0].scriptPubKey, flags, | inputi.vin[0].scriptSig, output.vout[0].scriptPubKey, flags, | ||||
TransactionSignatureChecker(&inputi, 0, output.vout[0].nValue), &error); | TransactionSignatureChecker(&inputi, 0, output.vout[0].nValue), &error); | ||||
BOOST_CHECK_EQUAL((ret == true), (error == SCRIPT_ERR_OK)); | BOOST_CHECK_EQUAL((ret == true), (error == ScriptError::OK)); | ||||
return error; | return error; | ||||
} | } | ||||
/** | /** | ||||
* Builds a creationTx from scriptPubKey and a spendingTx from scriptSig | * Builds a creationTx from scriptPubKey and a spendingTx from scriptSig | ||||
* such that spendingTx spends output zero of creationTx. Also inserts | * such that spendingTx spends output zero of creationTx. Also inserts | ||||
* creationTx's output into the coins view. | * creationTx's output into the coins view. | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | // Multisig script (legacy counting) | ||||
0); | 0); | ||||
// creationTx contains two signature operations in its scriptPubKey, but | // creationTx contains two signature operations in its scriptPubKey, but | ||||
// legacy counting is not accurate. | // legacy counting is not accurate. | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
GetTransactionSigOpCount(CTransaction(creationTx), coins, flags), | GetTransactionSigOpCount(CTransaction(creationTx), coins, flags), | ||||
MAX_PUBKEYS_PER_MULTISIG); | MAX_PUBKEYS_PER_MULTISIG); | ||||
// Sanity check: script verification fails because of an invalid | // Sanity check: script verification fails because of an invalid | ||||
// signature. | // signature. | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK(VerifyWithFlag(CTransaction(creationTx), spendingTx, | ||||
VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | flags) == ScriptError::CHECKMULTISIGVERIFY); | ||||
SCRIPT_ERR_CHECKMULTISIGVERIFY); | |||||
// Make sure non P2SH sigops are counted even if the flag for P2SH is | // Make sure non P2SH sigops are counted even if the flag for P2SH is | ||||
// not passed in. | // not passed in. | ||||
BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(spendingTx), | BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(spendingTx), | ||||
coins, SCRIPT_VERIFY_NONE), | coins, SCRIPT_VERIFY_NONE), | ||||
0); | 0); | ||||
BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(creationTx), | BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(creationTx), | ||||
coins, SCRIPT_VERIFY_NONE), | coins, SCRIPT_VERIFY_NONE), | ||||
MAX_PUBKEYS_PER_MULTISIG); | MAX_PUBKEYS_PER_MULTISIG); | ||||
} | } | ||||
// Multisig nested in P2SH | // Multisig nested in P2SH | ||||
{ | { | ||||
CScript redeemScript = CScript() << 1 << ToByteVector(pubkey) | CScript redeemScript = CScript() << 1 << ToByteVector(pubkey) | ||||
<< ToByteVector(pubkey) << 2 | << ToByteVector(pubkey) << 2 | ||||
<< OP_CHECKMULTISIGVERIFY; | << OP_CHECKMULTISIGVERIFY; | ||||
CScript scriptPubKey = GetScriptForDestination(CScriptID(redeemScript)); | CScript scriptPubKey = GetScriptForDestination(CScriptID(redeemScript)); | ||||
CScript scriptSig = CScript() | CScript scriptSig = CScript() | ||||
<< OP_0 << OP_0 << ToByteVector(redeemScript); | << OP_0 << OP_0 << ToByteVector(redeemScript); | ||||
BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig); | BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
GetTransactionSigOpCount(CTransaction(spendingTx), coins, flags), | GetTransactionSigOpCount(CTransaction(spendingTx), coins, flags), | ||||
2); | 2); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK(VerifyWithFlag(CTransaction(creationTx), spendingTx, | ||||
VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | flags) == ScriptError::CHECKMULTISIGVERIFY); | ||||
SCRIPT_ERR_CHECKMULTISIGVERIFY); | |||||
// Make sure P2SH sigops are not counted if the flag for P2SH is not | // Make sure P2SH sigops are not counted if the flag for P2SH is not | ||||
// passed in. | // passed in. | ||||
BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(spendingTx), | BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(spendingTx), | ||||
coins, SCRIPT_VERIFY_NONE), | coins, SCRIPT_VERIFY_NONE), | ||||
0); | 0); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |