test: refactor: Move g_insecure_rand_ctx.Reseed out of the helper that calls MakeRandDeterministicDANGEROUS

The global g_insecure_rand_ctx will be removed in the future, so
removing it from this helper is useful.

Also, tying the two concepts of the global internal RNGState and the
global test-only rng context is a bit confusing, because tests can
simply use the m_rng, if it exists. Also, tests may seed more than one
random context, or none at all, or a random context of a different type.

Fix all issues by moving the Reseed call to the two places where it is
used.
This commit is contained in:
MarcoFalke
2024-08-16 11:02:54 +02:00
parent 3dc527f460
commit fa19af555d
4 changed files with 12 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ FastRandomContext g_insecure_rand_ctx;
extern void MakeRandDeterministicDANGEROUS(const uint256& seed) noexcept;
void SeedRandomForTest(SeedRand seedtype)
void SeedRandomStateForTest(SeedRand seedtype)
{
static const std::string RANDOM_CTX_SEED{"RANDOM_CTX_SEED"};
@@ -34,5 +34,4 @@ void SeedRandomForTest(SeedRand seedtype)
const uint256& seed{seedtype == SeedRand::SEED ? ctx_seed : uint256::ZERO};
LogPrintf("%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex());
MakeRandDeterministicDANGEROUS(seed);
g_insecure_rand_ctx.Reseed(GetRandHash());
}