Fix intermittent failure in ledger.work_validation due to random work being above threshold (#2708)

This commit is contained in:
Guilherme Lawless 2020-04-09 17:25:02 +01:00 committed by GitHub
commit 70dff44aa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2999,8 +2999,14 @@ TEST (ledger, work_validation)
// With random work the block doesn't pass, then modifies the block with sufficient work and ensures a correct result
auto process_block = [&store, &ledger, &pool](nano::block & block_a, nano::block_details const details_a) {
auto threshold = nano::work_threshold (block_a.work_version (), details_a);
// Rarely failed with random work, so modify until it doesn't have enough difficulty
while (block_a.difficulty () >= threshold)
{
block_a.block_work_set (block_a.block_work () + 1);
}
EXPECT_EQ (nano::process_result::insufficient_work, ledger.process (store->tx_begin_write (), block_a).code);
block_a.block_work_set (*pool.generate (block_a.root (), nano::work_threshold (block_a.work_version (), details_a)));
block_a.block_work_set (*pool.generate (block_a.root (), threshold));
EXPECT_EQ (nano::process_result::progress, ledger.process (store->tx_begin_write (), block_a).code);
};