0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

scripted-diff: Replace EnsureChainman with Assert in unit tests

-BEGIN VERIFY SCRIPT-
sed --regexp-extended -i -e 's/EnsureChainman\((m?_?node)\)\./Assert(\1.chainman)->/g' $(git grep -l EnsureChainman)
-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke 2020-06-14 14:44:35 -04:00
parent fa6ef701ad
commit fa34587f1c
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
6 changed files with 15 additions and 15 deletions

View file

@ -94,7 +94,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
CBlockHeader header = block->GetBlockHeader(); CBlockHeader header = block->GetBlockHeader();
BlockValidationState state; BlockValidationState state;
if (!EnsureChainman(m_node).ProcessNewBlockHeaders({header}, state, Params(), &pindex)) { if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, Params(), &pindex)) {
return false; return false;
} }
} }
@ -171,7 +171,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
uint256 chainA_last_header = last_header; uint256 chainA_last_header = last_header;
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
const auto& block = chainA[i]; const auto& block = chainA[i];
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr)); BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
} }
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
const auto& block = chainA[i]; const auto& block = chainA[i];
@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
uint256 chainB_last_header = last_header; uint256 chainB_last_header = last_header;
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
const auto& block = chainB[i]; const auto& block = chainB[i];
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr)); BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
} }
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
const auto& block = chainB[i]; const auto& block = chainB[i];
@ -220,7 +220,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
// Reorg back to chain A. // Reorg back to chain A.
for (size_t i = 2; i < 4; i++) { for (size_t i = 2; i < 4; i++) {
const auto& block = chainA[i]; const auto& block = chainA[i];
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr)); BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
} }
// Check that chain A and B blocks can be retrieved. // Check that chain A and B blocks can be retrieved.

View file

@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
pblock->nNonce = blockinfo[i].nonce; pblock->nNonce = blockinfo[i].nonce;
} }
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock); std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr)); BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
pblock->hashPrevBlock = pblock->GetHash(); pblock->hashPrevBlock = pblock->GetHash();
} }

View file

@ -32,7 +32,7 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
assert(block->nNonce); assert(block->nNonce);
} }
bool processed{EnsureChainman(node).ProcessNewBlock(Params(), block, true, nullptr)}; bool processed{Assert(node.chainman)->ProcessNewBlock(Params(), block, true, nullptr)};
assert(processed); assert(processed);
return CTxIn{block->vtx[0]->GetHash(), 0}; return CTxIn{block->vtx[0]->GetHash(), 0};

View file

@ -228,7 +228,7 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransa
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce; while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block); std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr); Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
CBlock result = block; CBlock result = block;
return result; return result;

View file

@ -163,10 +163,10 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
std::transform(blocks.begin(), blocks.end(), std::back_inserter(headers), [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); }); std::transform(blocks.begin(), blocks.end(), std::back_inserter(headers), [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); });
// Process all the headers so we understand the toplogy of the chain // Process all the headers so we understand the toplogy of the chain
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlockHeaders(headers, state, Params())); BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders(headers, state, Params()));
// Connect the genesis block and drain any outstanding events // Connect the genesis block and drain any outstanding events
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored)); BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
SyncWithValidationInterfaceQueue(); SyncWithValidationInterfaceQueue();
// subscribe to events (this subscriber will validate event ordering) // subscribe to events (this subscriber will validate event ordering)
@ -188,13 +188,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
FastRandomContext insecure; FastRandomContext insecure;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
auto block = blocks[insecure.randrange(blocks.size() - 1)]; auto block = blocks[insecure.randrange(blocks.size() - 1)];
EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, &ignored); Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
} }
// to make sure that eventually we process the full chain - do it here // to make sure that eventually we process the full chain - do it here
for (auto block : blocks) { for (auto block : blocks) {
if (block->vtx.size() == 1) { if (block->vtx.size() == 1) {
bool processed = EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, &ignored); bool processed = Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
assert(processed); assert(processed);
} }
} }
@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
{ {
bool ignored; bool ignored;
auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool { auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool {
return EnsureChainman(m_node).ProcessNewBlock(Params(), block, /* fForceProcessing */ true, /* fNewBlock */ &ignored); return Assert(m_node.chainman)->ProcessNewBlock(Params(), block, /* fForceProcessing */ true, /* fNewBlock */ &ignored);
}; };
// Process all mined blocks // Process all mined blocks

View file

@ -118,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
// Prune the older block file. // Prune the older block file.
{ {
LOCK(cs_main); LOCK(cs_main);
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile); Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
} }
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile}); UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
@ -144,7 +144,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
// Prune the remaining block file. // Prune the remaining block file.
{ {
LOCK(cs_main); LOCK(cs_main);
EnsureChainman(m_node).PruneOneBlockFile(newTip->GetBlockPos().nFile); Assert(m_node.chainman)->PruneOneBlockFile(newTip->GetBlockPos().nFile);
} }
UnlinkPrunedFiles({newTip->GetBlockPos().nFile}); UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
@ -181,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
// Prune the older block file. // Prune the older block file.
{ {
LOCK(cs_main); LOCK(cs_main);
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile); Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
} }
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile}); UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});