diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 50f1d061d9..a4a0c8998c 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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); };