Changeset View
Changeset View
Standalone View
Standalone View
src/test/sigopcount_tests.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(GetTxSigOpCost) { | ||||
// Create utxo set | // Create utxo set | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
// Create key | // Create key | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
// Default flags | // Default flags | ||||
int flags = SCRIPT_VERIFY_P2SH; | const uint32_t flags = SCRIPT_VERIFY_P2SH; | ||||
// Multisig script (legacy counting) | // Multisig script (legacy counting) | ||||
{ | { | ||||
CScript scriptPubKey = CScript() << 1 << ToByteVector(pubkey) | CScript scriptPubKey = CScript() << 1 << ToByteVector(pubkey) | ||||
<< ToByteVector(pubkey) << 2 | << ToByteVector(pubkey) << 2 | ||||
<< OP_CHECKMULTISIGVERIFY; | << OP_CHECKMULTISIGVERIFY; | ||||
// Do not use a valid signature to avoid using wallet operations. | // Do not use a valid signature to avoid using wallet operations. | ||||
CScript scriptSig = CScript() << OP_0 << OP_0; | CScript scriptSig = CScript() << OP_0 << OP_0; | ||||
Show All 12 Lines | // Multisig script (legacy counting) | ||||
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_EQUAL( | ||||
VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | ||||
SCRIPT_ERR_CHECKMULTISIGVERIFY); | SCRIPT_ERR_CHECKMULTISIGVERIFY); | ||||
// Make sure non P2SH sigops are counted even if the flag for P2SH is | |||||
// not passed in. | |||||
BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(spendingTx), | |||||
coins, SCRIPT_VERIFY_NONE), | |||||
0); | |||||
BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(creationTx), | |||||
coins, SCRIPT_VERIFY_NONE), | |||||
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_EQUAL( | ||||
VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | VerifyWithFlag(CTransaction(creationTx), spendingTx, flags), | ||||
SCRIPT_ERR_CHECKMULTISIGVERIFY); | SCRIPT_ERR_CHECKMULTISIGVERIFY); | ||||
// Make sure P2SH sigops are not counted if the flag for P2SH is not | |||||
// passed in. | |||||
BOOST_CHECK_EQUAL(GetTransactionSigOpCount(CTransaction(spendingTx), | |||||
coins, SCRIPT_VERIFY_NONE), | |||||
0); | |||||
} | } | ||||
} | } | ||||
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 |