Skip to content

Commit fae63bf

Browse files
author
MarcoFalke
committed
fuzz: Clarify that only SeedRandomStateForTest(SeedRand::ZEROS) is allowed
1 parent fa18acb commit fae63bf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/test/util/random.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ void SeedRandomStateForTest(SeedRand seedtype)
3939
}();
4040

4141
g_seeded_g_prng_zero = seedtype == SeedRand::ZEROS;
42+
if constexpr (G_FUZZING) {
43+
Assert(g_seeded_g_prng_zero); // Only SeedRandomStateForTest(SeedRand::ZEROS) is allowed in fuzz tests
44+
}
4245
const uint256& seed{seedtype == SeedRand::FIXED_SEED ? ctx_seed : uint256::ZERO};
4346
LogInfo("Setting random seed for current tests to %s=%s\n", RANDOM_CTX_SEED, seed.GetHex());
4447
MakeRandDeterministicDANGEROUS(seed);

src/test/util/setup_common.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ static void ExitFailure(std::string_view str_err)
108108
BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
109109
: m_args{}
110110
{
111+
if constexpr (!G_FUZZING) {
112+
SeedRandomForTest(SeedRand::FIXED_SEED);
113+
}
111114
m_node.shutdown_signal = &m_interrupt;
112115
m_node.shutdown_request = [this]{ return m_interrupt(); };
113116
m_node.args = &gArgs;
@@ -139,8 +142,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
139142
}
140143
}
141144

142-
SeedRandomForTest(SeedRand::FIXED_SEED);
143-
144145
const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""};
145146
if (!m_node.args->IsArgSet("-testdatadir")) {
146147
// To avoid colliding with a leftover prior datadir, and to allow

0 commit comments

Comments
 (0)