From e861389adc79567eb7417ee1fd59b368e7bcc461 Mon Sep 17 00:00:00 2001 From: sasha Date: Tue, 26 Apr 2022 14:44:40 -0700 Subject: [PATCH] Make [seed_]insecure_rand available to the gtests --- src/gtest/main.cpp | 4 ++++ src/gtest/utils.h | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/gtest/main.cpp b/src/gtest/main.cpp index fa564286c..f77e8c1c6 100644 --- a/src/gtest/main.cpp +++ b/src/gtest/main.cpp @@ -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 G_TRANSLATION_FUN = nullptr; +uint256 insecure_rand_seed = GetRandHash(); +FastRandomContext insecure_rand_ctx(insecure_rand_seed); + struct ECCryptoClosure { ECCVerifyHandle handle; diff --git a/src/gtest/utils.h b/src/gtest/utils.h index 09f444c34..147ec99ab 100644 --- a/src/gtest/utils.h +++ b/src/gtest/utils.h @@ -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