Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockcheck_tests.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(blockfail) { | ||||
tx.vout[0].nValue = 42; | tx.vout[0].nValue = 42; | ||||
auto coinbaseTx = CTransaction(tx); | auto coinbaseTx = CTransaction(tx); | ||||
block.vtx.resize(1); | block.vtx.resize(1); | ||||
block.vtx[0] = MakeTransactionRef(tx); | block.vtx[0] = MakeTransactionRef(tx); | ||||
RunCheckOnBlock(config, block); | RunCheckOnBlock(config, block); | ||||
// No coinbase | // No coinbase | ||||
tx.vin[0].prevout.hash = GetRandHash(); | tx.vin[0].prevout.unspentid = unspentid_t(GetRandHash()); | ||||
tx.vin[0].prevout.n = 0; | tx.vin[0].prevout.n = 0; | ||||
block.vtx[0] = MakeTransactionRef(tx); | block.vtx[0] = MakeTransactionRef(tx); | ||||
RunCheckOnBlock(config, block, "bad-cb-missing"); | RunCheckOnBlock(config, block, "bad-cb-missing"); | ||||
// Invalid coinbase | // Invalid coinbase | ||||
tx = CMutableTransaction(coinbaseTx); | tx = CMutableTransaction(coinbaseTx); | ||||
tx.vin[0].scriptSig.resize(0); | tx.vin[0].scriptSig.resize(0); | ||||
block.vtx[0] = MakeTransactionRef(tx); | block.vtx[0] = MakeTransactionRef(tx); | ||||
RunCheckOnBlock(config, block, "bad-cb-length"); | RunCheckOnBlock(config, block, "bad-cb-length"); | ||||
// Oversize block. | // Oversize block. | ||||
tx = CMutableTransaction(coinbaseTx); | tx = CMutableTransaction(coinbaseTx); | ||||
block.vtx[0] = MakeTransactionRef(tx); | block.vtx[0] = MakeTransactionRef(tx); | ||||
tx.vin[0].prevout.n = 0; | tx.vin[0].prevout.n = 0; | ||||
auto txSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); | auto txSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); | ||||
auto maxTxCount = ((DEFAULT_MAX_BLOCK_SIZE - 1) / txSize) - 1; | auto maxTxCount = ((DEFAULT_MAX_BLOCK_SIZE - 1) / txSize) - 1; | ||||
for (size_t i = 1; i < maxTxCount; i++) { | for (size_t i = 1; i < maxTxCount; i++) { | ||||
tx.vin[0].prevout.hash = GetRandHash(); | tx.vin[0].prevout.unspentid = unspentid_t(GetRandHash()); | ||||
block.vtx.push_back(MakeTransactionRef(tx)); | block.vtx.push_back(MakeTransactionRef(tx)); | ||||
} | } | ||||
// Check that at this point, we still accept the block. | // Check that at this point, we still accept the block. | ||||
RunCheckOnBlock(config, block); | RunCheckOnBlock(config, block); | ||||
// But reject it with one more transaction as it goes over the maximum | // But reject it with one more transaction as it goes over the maximum | ||||
// allowed block size. | // allowed block size. | ||||
tx.vin[0].prevout.hash = GetRandHash(); | tx.vin[0].prevout.unspentid = unspentid_t(GetRandHash()); | ||||
block.vtx.push_back(MakeTransactionRef(tx)); | block.vtx.push_back(MakeTransactionRef(tx)); | ||||
RunCheckOnBlock(config, block, "bad-blk-length"); | RunCheckOnBlock(config, block, "bad-blk-length"); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |