Changeset View
Changeset View
Standalone View
Standalone View
src/test/sigopcount_tests.cpp
Show First 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(2000001), | ||||
3 * MAX_BLOCK_SIGOPS_PER_MB); | 3 * MAX_BLOCK_SIGOPS_PER_MB); | ||||
BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(2654321), | BOOST_CHECK_EQUAL(GetMaxBlockSigOpsCount(2654321), | ||||
3 * MAX_BLOCK_SIGOPS_PER_MB); | 3 * MAX_BLOCK_SIGOPS_PER_MB); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
GetMaxBlockSigOpsCount(std::numeric_limits<uint32_t>::max()), | GetMaxBlockSigOpsCount(std::numeric_limits<uint32_t>::max()), | ||||
4295 * MAX_BLOCK_SIGOPS_PER_MB); | 4295 * MAX_BLOCK_SIGOPS_PER_MB); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_max_sigops_per_tx) { | |||||
CMutableTransaction tx; | |||||
tx.nVersion = 1; | |||||
tx.vin.resize(1); | |||||
tx.vin[0].prevout = COutPoint(TxId(InsecureRand256()), 0); | |||||
tx.vin[0].scriptSig = CScript(); | |||||
tx.vout.resize(1); | |||||
tx.vout[0].nValue = SATOSHI; | |||||
tx.vout[0].scriptPubKey = CScript(); | |||||
{ | |||||
CValidationState state; | |||||
BOOST_CHECK(CheckRegularTransaction(CTransaction(tx), state)); | |||||
} | |||||
// Get just before the limit. | |||||
for (size_t i = 0; i < MAX_TX_SIGOPS_COUNT; i++) { | |||||
tx.vout[0].scriptPubKey << OP_CHECKSIG; | |||||
} | |||||
{ | |||||
CValidationState state; | |||||
BOOST_CHECK(CheckRegularTransaction(CTransaction(tx), state)); | |||||
} | |||||
// And go over. | |||||
tx.vout[0].scriptPubKey << OP_CHECKSIG; | |||||
{ | |||||
CValidationState state; | |||||
BOOST_CHECK(!CheckRegularTransaction(CTransaction(tx), state)); | |||||
BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txn-sigops"); | |||||
} | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |