|
|
@ -49,19 +49,20 @@ struct { |
|
|
|
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CReserveKey reservekey(pwalletMain); |
|
|
|
CReserveKey reservekey(pwalletMain); |
|
|
|
CBlock *pblock; |
|
|
|
CBlockTemplate *pblocktemplate; |
|
|
|
CTransaction tx; |
|
|
|
CTransaction tx; |
|
|
|
CScript script; |
|
|
|
CScript script; |
|
|
|
uint256 hash; |
|
|
|
uint256 hash; |
|
|
|
|
|
|
|
|
|
|
|
// Simple block creation, nothing special yet:
|
|
|
|
// Simple block creation, nothing special yet:
|
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
|
|
|
|
|
|
|
|
// We can't make transactions until we have inputs
|
|
|
|
// We can't make transactions until we have inputs
|
|
|
|
// Therefore, load 100 blocks :)
|
|
|
|
// Therefore, load 100 blocks :)
|
|
|
|
std::vector<CTransaction*>txFirst; |
|
|
|
std::vector<CTransaction*>txFirst; |
|
|
|
for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i) |
|
|
|
for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
|
|
|
pblock->nVersion = 1; |
|
|
|
pblock->nVersion = 1; |
|
|
|
pblock->nTime = pindexBest->GetMedianTimePast()+1; |
|
|
|
pblock->nTime = pindexBest->GetMedianTimePast()+1; |
|
|
|
pblock->vtx[0].vin[0].scriptSig = CScript(); |
|
|
|
pblock->vtx[0].vin[0].scriptSig = CScript(); |
|
|
@ -75,10 +76,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
assert(ProcessBlock(NULL, pblock)); |
|
|
|
assert(ProcessBlock(NULL, pblock)); |
|
|
|
pblock->hashPrevBlock = pblock->GetHash(); |
|
|
|
pblock->hashPrevBlock = pblock->GetHash(); |
|
|
|
} |
|
|
|
} |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
|
|
|
|
|
|
|
|
// Just to make sure we can still make simple blocks
|
|
|
|
// Just to make sure we can still make simple blocks
|
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
|
|
|
|
|
|
|
|
// block sigops > limit: 1000 CHECKMULTISIG + 1
|
|
|
|
// block sigops > limit: 1000 CHECKMULTISIG + 1
|
|
|
|
tx.vin.resize(1); |
|
|
|
tx.vin.resize(1); |
|
|
@ -95,8 +96,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
tx.vin[0].prevout.hash = hash; |
|
|
|
tx.vin[0].prevout.hash = hash; |
|
|
|
} |
|
|
|
} |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// block size > limit
|
|
|
|
// block size > limit
|
|
|
@ -115,15 +116,15 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
tx.vin[0].prevout.hash = hash; |
|
|
|
tx.vin[0].prevout.hash = hash; |
|
|
|
} |
|
|
|
} |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// orphan in mempool
|
|
|
|
// orphan in mempool
|
|
|
|
hash = tx.GetHash(); |
|
|
|
hash = tx.GetHash(); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// child with higher priority than parent
|
|
|
|
// child with higher priority than parent
|
|
|
@ -140,8 +141,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
tx.vout[0].nValue = 5900000000LL; |
|
|
|
tx.vout[0].nValue = 5900000000LL; |
|
|
|
hash = tx.GetHash(); |
|
|
|
hash = tx.GetHash(); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// coinbase in mempool
|
|
|
|
// coinbase in mempool
|
|
|
@ -151,8 +152,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
tx.vout[0].nValue = 0; |
|
|
|
tx.vout[0].nValue = 0; |
|
|
|
hash = tx.GetHash(); |
|
|
|
hash = tx.GetHash(); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// invalid (pre-p2sh) txn in mempool
|
|
|
|
// invalid (pre-p2sh) txn in mempool
|
|
|
@ -169,8 +170,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
tx.vout[0].nValue -= 1000000; |
|
|
|
tx.vout[0].nValue -= 1000000; |
|
|
|
hash = tx.GetHash(); |
|
|
|
hash = tx.GetHash(); |
|
|
|
mempool.addUnchecked(hash,tx); |
|
|
|
mempool.addUnchecked(hash,tx); |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// double spend txn pair in mempool
|
|
|
|
// double spend txn pair in mempool
|
|
|
@ -183,18 +184,18 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) |
|
|
|
tx.vout[0].scriptPubKey = CScript() << OP_2; |
|
|
|
tx.vout[0].scriptPubKey = CScript() << OP_2; |
|
|
|
hash = tx.GetHash(); |
|
|
|
hash = tx.GetHash(); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
mempool.addUnchecked(hash, tx); |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
mempool.clear(); |
|
|
|
mempool.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// subsidy changing
|
|
|
|
// subsidy changing
|
|
|
|
int nHeight = pindexBest->nHeight; |
|
|
|
int nHeight = pindexBest->nHeight; |
|
|
|
pindexBest->nHeight = 209999; |
|
|
|
pindexBest->nHeight = 209999; |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
pindexBest->nHeight = 210000; |
|
|
|
pindexBest->nHeight = 210000; |
|
|
|
BOOST_CHECK(pblock = CreateNewBlock(reservekey)); |
|
|
|
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); |
|
|
|
delete pblock; |
|
|
|
delete pblocktemplate; |
|
|
|
pindexBest->nHeight = nHeight; |
|
|
|
pindexBest->nHeight = nHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|