From e4293af2195e00bbb3a16a03c6d07516ff7ae688 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 22 Jul 2022 05:32:41 +0200 Subject: [PATCH] random_in_range moved, unit_tests/db_tests fixed --- tests/core_tests/chaingen_helpers.h | 7 ------- tests/core_tests/random_helper.h | 11 +++++++++++ tests/functional_tests/core_concurrency_test.cpp | 1 + tests/unit_tests/db_tests.cpp | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index a6284433..673f2381 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -187,13 +187,6 @@ inline bool mine_next_pos_block_in_playtime_with_wallet(tools::wallet2& w, const return w.build_minted_block(ctx.sp, ctx.rsp, miner_address); } -inline uint64_t random_in_range(uint64_t from, uint64_t to) -{ - if (from == to) - return from; - CHECK_AND_ASSERT_MES(from < to, 0, "Invalid arguments: from = " << from << ", to = " << to); - return crypto::rand() % (to - from + 1) + from; -} struct log_level_scope_changer { diff --git a/tests/core_tests/random_helper.h b/tests/core_tests/random_helper.h index 360b326d..61d49f80 100644 --- a/tests/core_tests/random_helper.h +++ b/tests/core_tests/random_helper.h @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once +#include "crypto/crypto.h" // DISCLAIMER: designed for tests puposes ONLY! // This class is not intended to be used neither in multi-threaded environment nor in production. @@ -64,6 +65,16 @@ inline std::string get_random_text(size_t len) } } +// boundaries are included +inline uint64_t random_in_range(uint64_t from, uint64_t to) +{ + if (from == to) + return from; + CHECK_AND_ASSERT_MES(from < to, 0, "Invalid arguments: from = " << from << ", to = " << to); + return crypto::rand() % (to - from + 1) + from; +} + + bool random_state_manupulation_test(); bool random_evenness_test(); bool get_random_text_test(); diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index a6dc5e8d..e689e0bf 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -22,6 +22,7 @@ using namespace currency; #include "../core_tests/test_core_time.h" std::atomic test_core_time::m_time_shift; +#include "../core_tests/random_helper.h" #include "../core_tests/test_core_proxy.h" #include "../core_tests/chaingen_helpers.h" #include "../core_tests/core_state_helper.h" diff --git a/tests/unit_tests/db_tests.cpp b/tests/unit_tests/db_tests.cpp index ade70b74..fcf5bac0 100644 --- a/tests/unit_tests/db_tests.cpp +++ b/tests/unit_tests/db_tests.cpp @@ -377,7 +377,7 @@ namespace db_test } // restore PRNG state to keep other tests unaffected - crypto::random_prng_get_state(prng_state, sizeof prng_state); + crypto::random_prng_set_state(prng_state, sizeof prng_state); ASSERT_TRUE(result); }