Make [seed_]insecure_rand available to the gtests

This commit is contained in:
sasha 2022-04-26 14:44:40 -07:00
parent fbd6564152
commit e861389adc
2 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "init.h"
#include "key.h"
#include "pubkey.h"
#include "random.h"
#include "util.h"
#include "utiltest.h"
@ -13,6 +14,9 @@
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
uint256 insecure_rand_seed = GetRandHash();
FastRandomContext insecure_rand_ctx(insecure_rand_seed);
struct ECCryptoClosure
{
ECCVerifyHandle handle;

View File

@ -1,6 +1,7 @@
#ifndef BITCOIN_GTEST_UTILS_H
#define BITCOIN_GTEST_UTILS_H
#include "random.h"
#include "util.h"
#include "key_io.h"
@ -10,4 +11,22 @@ void LoadProofParameters();
void LoadGlobalWallet();
void UnloadGlobalWallet();
extern uint256 insecure_rand_seed;
extern FastRandomContext insecure_rand_ctx;
static inline void seed_insecure_rand(bool fDeterministic = false)
{
if (fDeterministic) {
insecure_rand_seed = uint256();
} else {
insecure_rand_seed = GetRandHash();
}
insecure_rand_ctx = FastRandomContext(insecure_rand_seed);
}
static inline uint32_t insecure_rand(void)
{
return insecure_rand_ctx.rand32();
}
#endif