aboutsummaryrefslogtreecommitdiff
path: root/src/test/util/random.h
AgeCommit message (Collapse)Author
2024-07-01tests: overhaul deterministic test randomnessPieter Wuille
The existing code provides two randomness mechanisms for test purposes: - g_insecure_rand_ctx (with its wrappers InsecureRand*), which during tests is initialized using either zeros (SeedRand::ZEROS), or using environment-provided randomness (SeedRand::SEED). - g_mock_deterministic_tests, which controls some (but not all) of the normal randomness output if set, but then makes it extremely predictable (identical output repeatedly). Replace this with a single mechanism, which retains the SeedRand modes to control all randomness. There is a new internal deterministic PRNG inside the random module, which is used in GetRandBytes() when in test mode, and which is also used to initialize g_insecure_rand_ctx. This means that during tests, all random numbers are made deterministic. There is one exception, GetStrongRandBytes(), which even in test mode still uses the normal PRNG state. This probably opens the door to removing a lot of the ad-hoc "deterministic" mode functions littered through the codebase (by simply running relevant tests in SeedRand::ZEROS mode), but this isn't done yet.
2024-05-21doc: remove comment about using thread_localfanquake
Followup to https://github.com/bitcoin/bitcoin/pull/30095#discussion_r1605655974.
2023-06-14test: move remaining random test util code from setup_common to randomjonatack
and drop the util/random dependency on util/setup_common. This improves code separation and avoids creating a circular dependency if setup_common needs to call the util/random functions.
2023-02-09Create InsecureRandMoneyAmount() test util helperJon Atack
to generate semi-random CAmounts up to MAX_MONEY rather than only uint32, and use it in the unit tests.
2023-02-06Move random test util code from setup_common to randomJon Atack
as many of the unit tests don't use this code