Skip to content

Commit 2efebca

Browse files
kwvgPastaPastaPasta
authored andcommitted
refactor: use aliases of globals in unit tests
1 parent 89f41fa commit 2efebca

9 files changed

+24
-24
lines changed

src/test/block_reward_reallocation_tests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
182182
BOOST_ASSERT(dmnman.GetListAtChainTip().HasMN(tx.GetHash()));
183183
BOOST_CHECK(tip->nHeight < Params().GetConsensus().BRRHeight);
184184
// Creating blocks by different ways
185-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
185+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
186186
}
187187
for ([[maybe_unused]] auto _ : irange::range(1999)) {
188188
CreateAndProcessBlock({}, coinbaseKey);
@@ -212,7 +212,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
212212
BOOST_ASSERT(dmnman.GetListAtChainTip().HasMN(tx.GetHash()));
213213
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
214214
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
215-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
215+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
216216
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
217217
}
218218

@@ -226,7 +226,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
226226
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
227227
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
228228
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
229-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
229+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
230230
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 122209530);
231231
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
232232
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, 61104762); // 0.4999999755
@@ -244,7 +244,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
244244
const bool isV20Active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V20)};
245245
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
246246
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
247-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
247+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
248248
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
249249
}
250250
}
@@ -262,7 +262,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
262262
CAmount expected_block_reward = block_subsidy_potential - block_subsidy_potential / 5;
263263

264264
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
265-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
265+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
266266
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), expected_block_reward);
267267
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 67550353);
268268
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
@@ -288,7 +288,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
288288
const bool isMNRewardReallocated{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_MN_RR)};
289289
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
290290
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
291-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
291+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
292292

293293
if (isMNRewardReallocated) {
294294
const CAmount platform_payment = MasternodePayments::PlatformShare(masternode_payment);
@@ -310,7 +310,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
310310
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, isV20Active);
311311
const CAmount platform_payment = MasternodePayments::PlatformShare(masternode_payment);
312312
masternode_payment -= platform_payment;
313-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
313+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
314314

315315
CAmount block_subsidy_potential = block_subsidy + block_subsidy_sb;
316316
BOOST_CHECK_EQUAL(tip->nHeight, 3858);

src/test/blockfilter_index_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
6969
const CScript& scriptPubKey)
7070
{
7171
const CChainParams& chainparams = Params();
72-
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, chainparams).CreateNewBlock(scriptPubKey);
72+
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, chainparams).CreateNewBlock(scriptPubKey);
7373
CBlock& block = pblocktemplate->block;
7474
block.hashPrevBlock = prev->GetBlockHash();
7575
block.nTime = prev->nTime + 1;

src/test/denialofservice_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
8080
const CChainParams& chainparams = Params();
8181
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
8282
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr, *m_node.scheduler,
83-
*m_node.chainman, *m_node.mempool, *governance, m_node.cj_ctx,
83+
*m_node.chainman, *m_node.mempool, *m_node.govman, m_node.cj_ctx,
8484
m_node.llmq_ctx, false);
8585

8686
// Mock an outbound peer
@@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
151151
const CChainParams& chainparams = Params();
152152
auto connman = std::make_unique<CConnmanTest>(0x1337, 0x1337, *m_node.addrman);
153153
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr, *m_node.scheduler,
154-
*m_node.chainman, *m_node.mempool, *governance, m_node.cj_ctx,
154+
*m_node.chainman, *m_node.mempool, *m_node.govman, m_node.cj_ctx,
155155
m_node.llmq_ctx, false);
156156

157157
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
@@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
225225
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
226226
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
227227
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), *m_node.scheduler,
228-
*m_node.chainman, *m_node.mempool, *governance, m_node.cj_ctx,
228+
*m_node.chainman, *m_node.mempool, *m_node.govman, m_node.cj_ctx,
229229
m_node.llmq_ctx, false);
230230

231231
banman->ClearBanned();
@@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
271271
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
272272
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
273273
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), *m_node.scheduler,
274-
*m_node.chainman, *m_node.mempool, *governance, m_node.cj_ctx,
274+
*m_node.chainman, *m_node.mempool, *m_node.govman, m_node.cj_ctx,
275275
m_node.llmq_ctx, false);
276276

277277
banman->ClearBanned();
@@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
316316
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
317317
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
318318
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), *m_node.scheduler,
319-
*m_node.chainman, *m_node.mempool, *governance, m_node.cj_ctx,
319+
*m_node.chainman, *m_node.mempool, *m_node.govman, m_node.cj_ctx,
320320
m_node.llmq_ctx, false);
321321

322322
banman->ClearBanned();

src/test/dynamic_activation_thresholds_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct TestChainDATSetup : public TestChainSetup
8181
BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::STARTED);
8282
BOOST_CHECK_EQUAL(g_versionbitscache.Statistics(::ChainActive().Tip(), consensus_params, deployment_id).threshold, threshold(0));
8383
// Next block should be signaling by default
84-
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
84+
const auto pblocktemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
8585
const uint32_t bitmask = ((uint32_t)1) << consensus_params.vDeployments[deployment_id].bit;
8686
BOOST_CHECK_EQUAL(::ChainActive().Tip()->nVersion & bitmask, 0);
8787
BOOST_CHECK_EQUAL(pblocktemplate->block.nVersion & bitmask, bitmask);

src/test/evo_deterministicmns_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ void FuncDIP3Protx(TestChainSetup& setup)
406406

407407
CKey sporkKey;
408408
sporkKey.MakeNewKey(false);
409-
sporkManager->SetSporkAddress(EncodeDestination(PKHash(sporkKey.GetPubKey())));
410-
sporkManager->SetPrivKey(EncodeSecret(sporkKey));
409+
setup.m_node.sporkman->SetSporkAddress(EncodeDestination(PKHash(sporkKey.GetPubKey())));
410+
setup.m_node.sporkman->SetPrivKey(EncodeSecret(sporkKey));
411411

412412
auto utxos = BuildSimpleUtxoMap(setup.m_coinbase_txns);
413413

src/test/miner_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BlockAssembler MinerTestingSetup::AssemblerForTest(const CChainParams& params)
5252

5353
options.nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
5454
options.blockMinFeeRate = blockMinFeeRate;
55-
return BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, params, options);
55+
return BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, params, options);
5656
}
5757

5858
constexpr static struct {

src/test/util/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coi
4949
{
5050
assert(node.mempool);
5151
auto block = std::make_shared<CBlock>(
52-
BlockAssembler{*sporkManager, *governance, *node.llmq_ctx, *node.evodb, ::ChainstateActive(), *node.mempool, Params()}
52+
BlockAssembler{*node.sporkman, *node.govman, *node.llmq_ctx, *node.evodb, ::ChainstateActive(), *node.mempool, Params()}
5353
.CreateNewBlock(coinbase_scriptPubKey)
5454
->block);
5555

src/test/util/setup_common.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ void DashTestSetup(NodeContext& node)
108108
{
109109
CChainState& chainstate = Assert(node.chainman)->ActiveChainstate();
110110

111-
node.cj_ctx = std::make_unique<CJContext>(chainstate, *node.connman, *node.mempool, *::masternodeSync, /* relay_txes */ true);
111+
node.cj_ctx = std::make_unique<CJContext>(chainstate, *node.connman, *node.mempool, *node.mn_sync, /* relay_txes */ true);
112112
::deterministicMNManager = std::make_unique<CDeterministicMNManager>(chainstate, *node.connman, *node.evodb);
113113
node.dmnman = ::deterministicMNManager.get();
114114
#ifdef ENABLE_WALLET
115115
node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman);
116116
#endif // ENABLE_WALLET
117-
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.evodb, *sporkManager, *node.mempool, node.peerman, true, false);
117+
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.evodb, *node.sporkman, *node.mempool, node.peerman, true, false);
118118
}
119119

120120
void DashTestSetupClose(NodeContext& node)
@@ -223,7 +223,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
223223
m_node.sporkman = ::sporkManager.get();
224224
::governance = std::make_unique<CGovernanceManager>();
225225
m_node.govman = ::governance.get();
226-
::masternodeSync = std::make_unique<CMasternodeSync>(*m_node.connman, *::governance);
226+
::masternodeSync = std::make_unique<CMasternodeSync>(*m_node.connman, *m_node.govman);
227227
m_node.mn_sync = ::masternodeSync.get();
228228
::dstxManager = std::make_unique<CDSTXManager>();
229229
m_node.dstxman = ::dstxManager.get();
@@ -287,7 +287,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
287287

288288
m_node.banman = std::make_unique<BanMan>(GetDataDir() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
289289
m_node.peerman = PeerManager::make(chainparams, *m_node.connman, *m_node.addrman, m_node.banman.get(),
290-
*m_node.scheduler, *m_node.chainman, *m_node.mempool, *governance,
290+
*m_node.scheduler, *m_node.chainman, *m_node.mempool, *m_node.govman,
291291
m_node.cj_ctx, m_node.llmq_ctx, false);
292292
{
293293
CConnman::Options options;
@@ -389,7 +389,7 @@ CBlock TestChainSetup::CreateBlock(const std::vector<CMutableTransaction>& txns,
389389
const CChainParams& chainparams = Params();
390390
CTxMemPool empty_pool;
391391
CBlock block = BlockAssembler(
392-
*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb,
392+
*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb,
393393
::ChainstateActive(), empty_pool, chainparams
394394
).CreateNewBlock(scriptPubKey)->block;
395395

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
7575
CScript pubKey;
7676
pubKey << i++ << OP_TRUE;
7777

78-
auto ptemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(pubKey);
78+
auto ptemplate = BlockAssembler(*m_node.sporkman, *m_node.govman, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(pubKey);
7979
auto pblock = std::make_shared<CBlock>(ptemplate->block);
8080
pblock->hashPrevBlock = prev_hash;
8181
pblock->nTime = ++time;

0 commit comments

Comments
 (0)