From 70dff44aa0da77e363747ce0abdd358ff007e92f Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Thu, 9 Apr 2020 17:25:02 +0100 Subject: [PATCH] Fix intermittent failure in ledger.work_validation due to random work being above threshold (#2708) --- nano/core_test/ledger.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 50f1d061..a4a0c899 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); };