From 022cf47dd7ef8f46e32a184e84f94d1e9f3a495c Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 31 Oct 2018 15:51:57 -0700 Subject: [PATCH] Simplify testing RNG code --- src/test/prevector_tests.cpp | 4 ++-- src/test/test_bitcoin.cpp | 3 +-- src/test/test_bitcoin.h | 10 ++-------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index c488d3edcf..7341389208 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -189,8 +189,8 @@ class prevector_tester { prevector_tester() { SeedInsecureRand(); - rand_seed = insecure_rand_seed; - rand_cache = insecure_rand_ctx; + rand_seed = InsecureRand256(); + rand_cache = FastRandomContext(rand_seed); } }; diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index f7874e6882..9b4076d956 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -36,8 +36,7 @@ void CConnmanTest::ClearNodes() g_connman->vNodes.clear(); } -uint256 insecure_rand_seed = GetRandHash(); -FastRandomContext insecure_rand_ctx(insecure_rand_seed); +FastRandomContext insecure_rand_ctx; extern bool fPrintToConsole; extern void noui_connect(); diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h index 182571b004..124f862de8 100644 --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -26,17 +26,11 @@ std::ostream& operator<<(typename std::enable_if::value, std::os return stream << static_cast::type>(e); } -extern uint256 insecure_rand_seed; extern FastRandomContext insecure_rand_ctx; -static inline void SeedInsecureRand(bool fDeterministic = false) +static inline void SeedInsecureRand(bool deterministic = false) { - if (fDeterministic) { - insecure_rand_seed = uint256(); - } else { - insecure_rand_seed = GetRandHash(); - } - insecure_rand_ctx = FastRandomContext(insecure_rand_seed); + insecure_rand_ctx = FastRandomContext(deterministic); } static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); }