diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2024-08-14 09:39:31 -0400 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-08-26 11:22:20 +0200 |
commit | 948238a683b6c99f4e91114aa75680c6c2d73714 (patch) | |
tree | dbb699329bc54480ac468e67ab8b4e761bcdab72 /src/test | |
parent | fa0fe08eca48064b2a42789571fea017e455d820 (diff) |
test: Remove FastRandomContext global
Drop g_insecure_rand_ctx
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/fuzz.cpp | 1 | ||||
-rw-r--r-- | src/test/util/random.cpp | 2 | ||||
-rw-r--r-- | src/test/util/random.h | 33 | ||||
-rw-r--r-- | src/test/util/setup_common.h | 2 |
4 files changed, 1 insertions, 37 deletions
diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index 61f1d313bf..fdad0a287a 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -107,7 +107,6 @@ void initialize() // - GetStrongRandBytes(), which is used for the creation of private key material. // - Creating a BasicTestingSetup or derived class will switch to a random seed. SeedRandomStateForTest(SeedRand::ZEROS); - g_insecure_rand_ctx.Reseed(GetRandHash()); // Terminate immediately if a fuzzing harness ever tries to create a socket. // Individual tests can override this by pointing CreateSock to a mocked alternative. diff --git a/src/test/util/random.cpp b/src/test/util/random.cpp index da2f51ffbc..75b2a25857 100644 --- a/src/test/util/random.cpp +++ b/src/test/util/random.cpp @@ -11,8 +11,6 @@ #include <cstdlib> #include <string> -FastRandomContext g_insecure_rand_ctx; - extern void MakeRandDeterministicDANGEROUS(const uint256& seed) noexcept; void SeedRandomStateForTest(SeedRand seedtype) diff --git a/src/test/util/random.h b/src/test/util/random.h index 10215ccbe5..c458534d48 100644 --- a/src/test/util/random.h +++ b/src/test/util/random.h @@ -11,14 +11,6 @@ #include <cstdint> -/** - * This global and the helpers that use it are not thread-safe. - * - * If thread-safety is needed, a per-thread instance could be - * used in the multi-threaded test. - */ -extern FastRandomContext g_insecure_rand_ctx; - enum class SeedRand { ZEROS, //!< Seed with a compile time constant of zeros SEED, //!< Use (and report) random seed from environment, or a (truly) random one. @@ -27,31 +19,6 @@ enum class SeedRand { /** Seed the global RNG state for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */ void SeedRandomStateForTest(SeedRand seed); -static inline uint32_t InsecureRand32() -{ - return g_insecure_rand_ctx.rand32(); -} - -static inline uint256 InsecureRand256() -{ - return g_insecure_rand_ctx.rand256(); -} - -static inline uint64_t InsecureRandBits(int bits) -{ - return g_insecure_rand_ctx.randbits(bits); -} - -static inline uint64_t InsecureRandRange(uint64_t range) -{ - return g_insecure_rand_ctx.randrange(range); -} - -static inline bool InsecureRandBool() -{ - return g_insecure_rand_ctx.randbool(); -} - template <RandomNumberGenerator Rng> inline CAmount RandMoney(Rng&& rng) { diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 677355c9f5..d995549ca6 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -66,7 +66,7 @@ struct BasicTestingSetup { util::SignalInterrupt m_interrupt; node::NodeContext m_node; // keep as first member to be destructed last - FastRandomContext& m_rng{g_insecure_rand_ctx}; // Alias (reference) for the global, to allow easy removal of the global in the future. + FastRandomContext m_rng; /** Seed the global RNG state and m_rng for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */ void SeedRandomForTest(SeedRand seed = SeedRand::SEED) { |