Skip to content

Commit

Permalink
fuzz: Clarify that only SeedRandomStateForTest(SeedRand::ZEROS) is al…
Browse files Browse the repository at this point in the history
…lowed
  • Loading branch information
MarcoFalke committed Dec 17, 2024
1 parent fa18acb commit fae63bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/test/util/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void SeedRandomStateForTest(SeedRand seedtype)
}();

g_seeded_g_prng_zero = seedtype == SeedRand::ZEROS;
if constexpr (G_FUZZING) {
Assert(g_seeded_g_prng_zero); // Only SeedRandomStateForTest(SeedRand::ZEROS) is allowed in fuzz tests
}
const uint256& seed{seedtype == SeedRand::FIXED_SEED ? ctx_seed : uint256::ZERO};
LogInfo("Setting random seed for current tests to %s=%s\n", RANDOM_CTX_SEED, seed.GetHex());
MakeRandDeterministicDANGEROUS(seed);
Expand Down
5 changes: 3 additions & 2 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ static void ExitFailure(std::string_view str_err)
BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
: m_args{}
{
if constexpr (!G_FUZZING) {
SeedRandomForTest(SeedRand::FIXED_SEED);
}
m_node.shutdown_signal = &m_interrupt;
m_node.shutdown_request = [this]{ return m_interrupt(); };
m_node.args = &gArgs;
Expand Down Expand Up @@ -139,8 +142,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
}
}

SeedRandomForTest(SeedRand::FIXED_SEED);

const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""};
if (!m_node.args->IsArgSet("-testdatadir")) {
// To avoid colliding with a leftover prior datadir, and to allow
Expand Down

0 comments on commit fae63bf

Please sign in to comment.