Skip to content

Commit

Permalink
Don't assert(foo()) where foo has side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift committed Jul 7, 2018
1 parent 0212187 commit 6ad0328
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ static CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
auto block = PrepareBlock(coinbase_scriptPubKey);

while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) {
assert(++block->nNonce);
++block->nNonce;
assert(block->nNonce);
}

bool processed{ProcessNewBlock(Params(), block, true, nullptr)};
Expand Down
9 changes: 6 additions & 3 deletions src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static void DeserializeBlockTest(benchmark::State& state)
while (state.KeepRunning()) {
CBlock block;
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block413567)));
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
assert(rewound);
}
}

Expand All @@ -45,10 +46,12 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
while (state.KeepRunning()) {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block413567)));
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
assert(rewound);

CValidationState validationState;
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
assert(checked);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ bool StartHTTPRPC()
// ifdef can be removed once we switch to better endpoint support and API versioning
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
#endif
assert(EventBase());
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
struct event_base* eventBase = EventBase();
assert(eventBase);
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(eventBase);
RPCSetTimerInterface(httpRPCTimerInterface.get());
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/script/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
// VerifyScript check is just defensive, and should never fail.
assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER));
bool verified = VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
assert(verified);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/test/txvalidation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
coinbaseTx.vout[0].nValue = 1 * CENT;
coinbaseTx.vout[0].scriptPubKey = scriptPubKey;

assert(CTransaction(coinbaseTx).IsCoinBase());
BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase());

CValidationState state;

Expand Down

0 comments on commit 6ad0328

Please sign in to comment.