1
0
Fork 0
forked from lthn/blockchain

random_in_range moved, unit_tests/db_tests fixed

This commit is contained in:
sowle 2022-07-22 05:32:41 +02:00
parent 386df3db2a
commit e4293af219
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 13 additions and 8 deletions

View file

@ -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<uint64_t>() % (to - from + 1) + from;
}
struct log_level_scope_changer
{

View file

@ -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<uint64_t>() % (to - from + 1) + from;
}
bool random_state_manupulation_test();
bool random_evenness_test();
bool get_random_text_test();

View file

@ -22,6 +22,7 @@ using namespace currency;
#include "../core_tests/test_core_time.h"
std::atomic<int64_t> 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"

View file

@ -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);
}