Changeset View
Changeset View
Standalone View
Standalone View
src/test/sigopcount_tests.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
ScriptError VerifyWithFlag(const CTransaction &output, | 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((ret == true) == (error == SCRIPT_ERR_OK)); | BOOST_CHECK_EQUAL((ret == true), (error == SCRIPT_ERR_OK)); | ||||
return error; | return error; | ||||
} | } | ||||
/** | /** | ||||
* Builds a creationTx from scriptPubKey and a spendingTx from scriptSig and | * Builds a creationTx from scriptPubKey and a spendingTx from scriptSig and | ||||
* witness such that spendingTx spends output zero of creationTx. Also inserts | * witness 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 46 Lines • ▼ Show 20 Lines | // Multisig script (legacy counting) | ||||
CScript scriptSig = CScript() << OP_0 << OP_0; | CScript scriptSig = CScript() << OP_0 << OP_0; | ||||
BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig); | BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig); | ||||
// Legacy counting only includes signature operations in scriptSigs and | // Legacy counting only includes signature operations in scriptSigs and | ||||
// scriptPubKeys of a transaction and does not take the actual executed | // scriptPubKeys of a transaction and does not take the actual executed | ||||
// sig operations into account. spendingTx in itself does not contain a | // sig operations into account. spendingTx in itself does not contain a | ||||
// signature operation. | // signature operation. | ||||
assert(GetTransactionSigOpCount(CTransaction(spendingTx), coins, | BOOST_CHECK_EQUAL( | ||||
flags) == 0); | GetTransactionSigOpCount(CTransaction(spendingTx), coins, flags), | ||||
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. | ||||
assert(GetTransactionSigOpCount(CTransaction(creationTx), coins, | BOOST_CHECK_EQUAL( | ||||
flags) == MAX_PUBKEYS_PER_MULTISIG); | GetTransactionSigOpCount(CTransaction(creationTx), coins, flags), | ||||
MAX_PUBKEYS_PER_MULTISIG); | |||||
// Sanity check: script verification fails because of an invalid | // Sanity check: script verification fails because of an invalid | ||||
// signature. | // signature. | ||||
assert(VerifyWithFlag(CTransaction(creationTx), spendingTx, flags) == | BOOST_CHECK_EQUAL( | ||||
VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | |||||
SCRIPT_ERR_CHECKMULTISIGVERIFY); | SCRIPT_ERR_CHECKMULTISIGVERIFY); | ||||
} | } | ||||
// 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); | ||||
assert(GetTransactionSigOpCount(CTransaction(spendingTx), coins, | BOOST_CHECK_EQUAL( | ||||
flags) == 2); | GetTransactionSigOpCount(CTransaction(spendingTx), coins, flags), | ||||
assert(VerifyWithFlag(CTransaction(creationTx), spendingTx, flags) == | 2); | ||||
BOOST_CHECK_EQUAL( | |||||
VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | |||||
SCRIPT_ERR_CHECKMULTISIGVERIFY); | SCRIPT_ERR_CHECKMULTISIGVERIFY); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_consensus_sigops_limit) { | BOOST_AUTO_TEST_CASE(test_consensus_sigops_limit) { | ||||
BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(1), MAX_BLOCK_SIGOPS_PER_MB); | BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(1), MAX_BLOCK_SIGOPS_PER_MB); | ||||
BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(123456), MAX_BLOCK_SIGOPS_PER_MB); | BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(123456), MAX_BLOCK_SIGOPS_PER_MB); | ||||
BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(1000000), MAX_BLOCK_SIGOPS_PER_MB); | BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(1000000), MAX_BLOCK_SIGOPS_PER_MB); | ||||
BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(1000001), | BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(1000001), | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |