Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | void MinerTestingSetup::TestPackageSelection( | ||||
// 10k satoshi fee. | // 10k satoshi fee. | ||||
tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; | tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; | ||||
g_mempool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx)); | g_mempool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | AssemblerForTest(chainparams, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); | BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); | ||||
} | } | ||||
void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) { | void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg, | ||||
const CTxMemPool &mempool) { | |||||
GlobalConfig config; | GlobalConfig config; | ||||
config.SetMaxBlockSize(eb); | config.SetMaxBlockSize(eb); | ||||
CScript scriptPubKey = | CScript scriptPubKey = | ||||
CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909" | CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909" | ||||
"a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112" | "a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112" | ||||
"de5c384df7ba0b8d578a4c702b6bf11d5f") | "de5c384df7ba0b8d578a4c702b6bf11d5f") | ||||
<< OP_CHECKSIG; | << OP_CHECKSIG; | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate = | std::unique_ptr<CBlockTemplate> pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, mempool).CreateNewBlock(scriptPubKey); | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot | // IncrementExtraNonce creates a valid coinbase and merkleRoot | ||||
unsigned int extraNonce = 0; | unsigned int extraNonce = 0; | ||||
IncrementExtraNonce(pblock, ::ChainActive().Tip(), config.GetMaxBlockSize(), | IncrementExtraNonce(pblock, ::ChainActive().Tip(), config.GetMaxBlockSize(), | ||||
extraNonce); | extraNonce); | ||||
unsigned int nHeight = ::ChainActive().Tip()->nHeight + 1; | unsigned int nHeight = ::ChainActive().Tip()->nHeight + 1; | ||||
std::vector<uint8_t> vec(cbmsg.begin(), cbmsg.end()); | std::vector<uint8_t> vec(cbmsg.begin(), cbmsg.end()); | ||||
BOOST_CHECK(pblock->vtx[0]->vin[0].scriptSig == | BOOST_CHECK(pblock->vtx[0]->vin[0].scriptSig == | ||||
((CScript() << nHeight << CScriptNum(extraNonce) << vec) + | ((CScript() << nHeight << CScriptNum(extraNonce) << vec) + | ||||
COINBASE_FLAGS)); | COINBASE_FLAGS)); | ||||
} | } | ||||
// Coinbase scriptSig has to contains the correct EB value | // Coinbase scriptSig has to contains the correct EB value | ||||
// converted to MB, rounded down to the first decimal | // converted to MB, rounded down to the first decimal | ||||
BOOST_AUTO_TEST_CASE(CheckCoinbase_EB) { | BOOST_AUTO_TEST_CASE(CheckCoinbase_EB) { | ||||
TestCoinbaseMessageEB(1000001, "/EB1.0/"); | TestCoinbaseMessageEB(1000001, "/EB1.0/", ::g_mempool); | ||||
TestCoinbaseMessageEB(2000000, "/EB2.0/"); | TestCoinbaseMessageEB(2000000, "/EB2.0/", ::g_mempool); | ||||
TestCoinbaseMessageEB(8000000, "/EB8.0/"); | TestCoinbaseMessageEB(8000000, "/EB8.0/", ::g_mempool); | ||||
TestCoinbaseMessageEB(8320000, "/EB8.3/"); | TestCoinbaseMessageEB(8320000, "/EB8.3/", ::g_mempool); | ||||
} | } | ||||
// NOTE: These tests rely on CreateNewBlock doing its own self-validation! | // NOTE: These tests rely on CreateNewBlock doing its own self-validation! | ||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// Note that by default, these tests run with size accounting enabled. | // Note that by default, these tests run with size accounting enabled. | ||||
GlobalConfig config; | GlobalConfig config; | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
CScript scriptPubKey = | CScript scriptPubKey = | ||||
▲ Show 20 Lines • Show All 401 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
SetMockTime(0); | SetMockTime(0); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
TestPackageSelection(chainparams, scriptPubKey, txFirst); | TestPackageSelection(chainparams, scriptPubKey, txFirst); | ||||
fCheckpointsEnabled = true; | fCheckpointsEnabled = true; | ||||
} | } | ||||
void CheckBlockMaxSize(const Config &config, uint64_t size, uint64_t expected) { | void CheckBlockMaxSize(const Config &config, const CTxMemPool &mempool, | ||||
uint64_t size, uint64_t expected) { | |||||
gArgs.ForceSetArg("-blockmaxsize", std::to_string(size)); | gArgs.ForceSetArg("-blockmaxsize", std::to_string(size)); | ||||
BlockAssembler ba(config, g_mempool); | BlockAssembler ba(config, mempool); | ||||
BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), expected); | BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), expected); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(BlockAssembler_construction) { | BOOST_AUTO_TEST_CASE(BlockAssembler_construction) { | ||||
GlobalConfig config; | GlobalConfig config; | ||||
// We are working on a fake chain and need to protect ourselves. | // We are working on a fake chain and need to protect ourselves. | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
// Test around historical 1MB (plus one byte because that's mandatory) | // Test around historical 1MB (plus one byte because that's mandatory) | ||||
config.SetMaxBlockSize(ONE_MEGABYTE + 1); | config.SetMaxBlockSize(ONE_MEGABYTE + 1); | ||||
CheckBlockMaxSize(config, 0, 1000); | CheckBlockMaxSize(config, ::g_mempool, 0, 1000); | ||||
CheckBlockMaxSize(config, 1000, 1000); | CheckBlockMaxSize(config, ::g_mempool, 1000, 1000); | ||||
CheckBlockMaxSize(config, 1001, 1001); | CheckBlockMaxSize(config, ::g_mempool, 1001, 1001); | ||||
CheckBlockMaxSize(config, 12345, 12345); | CheckBlockMaxSize(config, ::g_mempool, 12345, 12345); | ||||
CheckBlockMaxSize(config, ONE_MEGABYTE - 1001, ONE_MEGABYTE - 1001); | CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE - 1001, | ||||
CheckBlockMaxSize(config, ONE_MEGABYTE - 1000, ONE_MEGABYTE - 1000); | ONE_MEGABYTE - 1001); | ||||
CheckBlockMaxSize(config, ONE_MEGABYTE - 999, ONE_MEGABYTE - 999); | CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE - 1000, | ||||
CheckBlockMaxSize(config, ONE_MEGABYTE, ONE_MEGABYTE - 999); | ONE_MEGABYTE - 1000); | ||||
CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE - 999, | |||||
ONE_MEGABYTE - 999); | |||||
CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE, ONE_MEGABYTE - 999); | |||||
// Test around default cap | // Test around default cap | ||||
config.SetMaxBlockSize(DEFAULT_MAX_BLOCK_SIZE); | config.SetMaxBlockSize(DEFAULT_MAX_BLOCK_SIZE); | ||||
// Now we can use the default max block size. | // Now we can use the default max block size. | ||||
CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE - 1001, | CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE - 1001, | ||||
DEFAULT_MAX_BLOCK_SIZE - 1001); | DEFAULT_MAX_BLOCK_SIZE - 1001); | ||||
CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE - 1000, | CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE - 1000, | ||||
DEFAULT_MAX_BLOCK_SIZE - 1000); | DEFAULT_MAX_BLOCK_SIZE - 1000); | ||||
CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE - 999, | CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE - 999, | ||||
DEFAULT_MAX_BLOCK_SIZE - 1000); | DEFAULT_MAX_BLOCK_SIZE - 1000); | ||||
CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE, | CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE, | ||||
DEFAULT_MAX_BLOCK_SIZE - 1000); | DEFAULT_MAX_BLOCK_SIZE - 1000); | ||||
// If the parameter is not specified, we use | // If the parameter is not specified, we use | ||||
// DEFAULT_MAX_GENERATED_BLOCK_SIZE | // DEFAULT_MAX_GENERATED_BLOCK_SIZE | ||||
{ | { | ||||
gArgs.ClearForcedArg("-blockmaxsize"); | gArgs.ClearForcedArg("-blockmaxsize"); | ||||
BlockAssembler ba(config, g_mempool); | BlockAssembler ba(config, g_mempool); | ||||
BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), | BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), | ||||
Show All 14 Lines |