-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#27425: test: move remaining rand code from util…
…/setup_common to util/random 1cd45d4 test: move random.h include header from setup_common.h to cpp (Jon Atack) 1b246fd test: move remaining random test util code from setup_common to random (jonatack) Pull request description: and drop the `util/random` dependency on `util/setup_common`. This improves code separation and allows `util/setup_common` to call `util/random` functions without creating a circular dependency, thereby addressing bitcoin/bitcoin#26940 (comment) by glozow (thanks!) ACKs for top commit: MarcoFalke: lgtm ACK 1cd45d4 🌂 Tree-SHA512: 6ce63d9103ba9b04eebbd8ad02fe9aa79e356296533404034a1ae88e9b7ca0bc9a5c51fd754b71cf4e7b55b18bcd4d5474b2d588edee3851e3b3ce0e4d309a93
- Loading branch information
Showing
9 changed files
with
72 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2023 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <test/util/random.h> | ||
|
||
#include <logging.h> | ||
#include <random.h> | ||
#include <uint256.h> | ||
|
||
#include <cstdlib> | ||
#include <string> | ||
|
||
FastRandomContext g_insecure_rand_ctx; | ||
|
||
/** Return the unsigned from the environment var if available, otherwise 0 */ | ||
static uint256 GetUintFromEnv(const std::string& env_name) | ||
{ | ||
const char* num = std::getenv(env_name.c_str()); | ||
if (!num) return {}; | ||
return uint256S(num); | ||
} | ||
|
||
void Seed(FastRandomContext& ctx) | ||
{ | ||
// Should be enough to get the seed once for the process | ||
static uint256 seed{}; | ||
static const std::string RANDOM_CTX_SEED{"RANDOM_CTX_SEED"}; | ||
if (seed.IsNull()) seed = GetUintFromEnv(RANDOM_CTX_SEED); | ||
if (seed.IsNull()) seed = GetRandHash(); | ||
LogPrintf("%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex()); | ||
ctx = FastRandomContext(seed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters