Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup) | BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup) | ||||
static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB); | static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB); | ||||
BlockAssembler MinerTestingSetup::AssemblerForTest(const CChainParams ¶ms) { | BlockAssembler MinerTestingSetup::AssemblerForTest(const CChainParams ¶ms) { | ||||
BlockAssembler::Options options; | BlockAssembler::Options options; | ||||
options.blockMinFeeRate = blockMinFeeRate; | options.blockMinFeeRate = blockMinFeeRate; | ||||
return BlockAssembler(params, *m_node.mempool, options); | return BlockAssembler(::ChainstateActive(), params, *m_node.mempool, | ||||
options); | |||||
} | } | ||||
constexpr static struct { | constexpr static struct { | ||||
uint8_t extranonce; | uint8_t extranonce; | ||||
uint32_t nonce; | uint32_t nonce; | ||||
} blockinfo[] = { | } blockinfo[] = { | ||||
{4, 0xa4a3e223}, {2, 0x15c32f9e}, {1, 0x0375b547}, {1, 0x7004a8a5}, | {4, 0xa4a3e223}, {2, 0x15c32f9e}, {1, 0x0375b547}, {1, 0x7004a8a5}, | ||||
{2, 0xce440296}, {2, 0x52cfe198}, {1, 0x77a72cd0}, {2, 0xbb5d6f84}, | {2, 0xce440296}, {2, 0x52cfe198}, {1, 0x77a72cd0}, {2, 0xbb5d6f84}, | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg, | ||||
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, mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, ::ChainstateActive(), 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; | ||||
▲ Show 20 Lines • Show All 429 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
fCheckpointsEnabled = true; | fCheckpointsEnabled = true; | ||||
} | } | ||||
void CheckBlockMaxSize(const Config &config, const CTxMemPool &mempool, | void CheckBlockMaxSize(const Config &config, const CTxMemPool &mempool, | ||||
uint64_t size, uint64_t expected) { | uint64_t size, uint64_t expected) { | ||||
gArgs.ForceSetArg("-blockmaxsize", ToString(size)); | gArgs.ForceSetArg("-blockmaxsize", ToString(size)); | ||||
BlockAssembler ba(config, mempool); | BlockAssembler ba(config, ::ChainstateActive(), 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); | ||||
Show All 26 Lines | CheckBlockMaxSize(config, *m_node.mempool, DEFAULT_MAX_BLOCK_SIZE - 999, | ||||
DEFAULT_MAX_BLOCK_SIZE - 1000); | DEFAULT_MAX_BLOCK_SIZE - 1000); | ||||
CheckBlockMaxSize(config, *m_node.mempool, DEFAULT_MAX_BLOCK_SIZE, | CheckBlockMaxSize(config, *m_node.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, *m_node.mempool); | BlockAssembler ba(config, ::ChainstateActive(), *m_node.mempool); | ||||
BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), | BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), | ||||
DEFAULT_MAX_GENERATED_BLOCK_SIZE); | DEFAULT_MAX_GENERATED_BLOCK_SIZE); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(TestCBlockTemplateEntry) { | BOOST_AUTO_TEST_CASE(TestCBlockTemplateEntry) { | ||||
const CTransaction tx; | const CTransaction tx; | ||||
CTransactionRef txRef = MakeTransactionRef(tx); | CTransactionRef txRef = MakeTransactionRef(tx); | ||||
CBlockTemplateEntry txEntry(txRef, 1 * SATOSHI, 10); | CBlockTemplateEntry txEntry(txRef, 1 * SATOSHI, 10); | ||||
BOOST_CHECK_MESSAGE(txEntry.tx == txRef, "Transactions did not match"); | BOOST_CHECK_MESSAGE(txEntry.tx == txRef, "Transactions did not match"); | ||||
BOOST_CHECK_EQUAL(txEntry.fees, 1 * SATOSHI); | BOOST_CHECK_EQUAL(txEntry.fees, 1 * SATOSHI); | ||||
BOOST_CHECK_EQUAL(txEntry.sigOpCount, 10); | BOOST_CHECK_EQUAL(txEntry.sigOpCount, 10); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |