diff options
author | Jon Atack <jon@atack.com> | 2023-01-22 09:57:19 -0800 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2023-02-06 12:26:04 -0800 |
commit | 81f5ade2a324167c03c5ce765a26bd42ed652723 (patch) | |
tree | f45d1c7ba2012c636866f6fb2d6a7a876b5dda39 | |
parent | 52ddbd52f980c0e733682401056d8131f1d513c0 (diff) |
Move random test util code from setup_common to random
as many of the unit tests don't use this code
35 files changed, 73 insertions, 6 deletions
diff --git a/src/Makefile.test_util.include b/src/Makefile.test_util.include index 8496b3698a..257ecb5542 100644 --- a/src/Makefile.test_util.include +++ b/src/Makefile.test_util.include @@ -14,6 +14,7 @@ TEST_UTIL_H = \ test/util/logging.h \ test/util/mining.h \ test/util/net.h \ + test/util/random.h \ test/util/script.h \ test/util/setup_common.h \ test/util/str.h \ diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index 601caf8102..7f3ca6bf93 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -6,6 +6,7 @@ #include <base58.h> #include <test/util/json.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <util/strencodings.h> #include <util/vector.h> diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index e23b7228e7..4348a20886 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -7,6 +7,7 @@ #include <consensus/merkle.h> #include <pow.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/txmempool.h> #include <test/util/setup_common.h> diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index 4888041204..5d4c5eea0e 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -12,6 +12,7 @@ #include <random.h> #include <serialize.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <uint256.h> #include <util/strencodings.h> diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 53fbc26e15..135f107159 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -4,6 +4,7 @@ #include <checkqueue.h> #include <sync.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <util/system.h> #include <util/time.h> diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 55ecd41af1..e91ea3536d 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -6,6 +6,7 @@ #include <coins.h> #include <script/standard.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <txdb.h> #include <uint256.h> diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp index d3eef7beb7..b565ddaadb 100644 --- a/src/test/crypto_tests.cpp +++ b/src/test/crypto_tests.cpp @@ -17,6 +17,7 @@ #include <crypto/muhash.h> #include <random.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <util/strencodings.h> diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp index c7c34cc8c9..eafbcf5681 100644 --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -1,9 +1,11 @@ // Copyright (c) 2012-2021 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 <cuckoocache.h> #include <random.h> #include <script/sigcache.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <boost/test/unit_test.hpp> diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 7ad123754b..a36d7b6e2a 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <dbwrapper.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <uint256.h> #include <util/string.h> diff --git a/src/test/hash_tests.cpp b/src/test/hash_tests.cpp index 5b5158884a..f1f435591b 100644 --- a/src/test/hash_tests.cpp +++ b/src/test/hash_tests.cpp @@ -5,6 +5,7 @@ #include <clientversion.h> #include <crypto/siphash.h> #include <hash.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <util/strencodings.h> diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index edf28cfbfc..ea5b94f3a5 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -6,6 +6,7 @@ #include <key_io.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <uint256.h> #include <util/strencodings.h> diff --git a/src/test/merkle_tests.cpp b/src/test/merkle_tests.cpp index 74e01fc2a5..66f7be3c4e 100644 --- a/src/test/merkle_tests.cpp +++ b/src/test/merkle_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <consensus/merkle.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <boost/test/unit_test.hpp> diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index e766a55673..9e484f919e 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -9,6 +9,7 @@ #include <node/miner.h> #include <policy/policy.h> #include <script/standard.h> +#include <test/util/random.h> #include <test/util/txmempool.h> #include <timedata.h> #include <txmempool.h> diff --git a/src/test/minisketch_tests.cpp b/src/test/minisketch_tests.cpp index 59c0aab053..10506da783 100644 --- a/src/test/minisketch_tests.cpp +++ b/src/test/minisketch_tests.cpp @@ -5,6 +5,7 @@ #include <minisketch.h> #include <node/minisketchwrapper.h> #include <random.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <boost/test/unit_test.hpp> diff --git a/src/test/orphanage_tests.cpp b/src/test/orphanage_tests.cpp index a55b0bbcd0..21d07381e5 100644 --- a/src/test/orphanage_tests.cpp +++ b/src/test/orphanage_tests.cpp @@ -7,6 +7,7 @@ #include <script/sign.h> #include <script/signingprovider.h> #include <script/standard.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <txorphanage.h> diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp index 21e0dd2fc5..a1e672d174 100644 --- a/src/test/pmt_tests.cpp +++ b/src/test/pmt_tests.cpp @@ -6,6 +6,7 @@ #include <merkleblock.h> #include <serialize.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <uint256.h> #include <version.h> diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp index 7cd12ede0a..addc925bab 100644 --- a/src/test/pow_tests.cpp +++ b/src/test/pow_tests.cpp @@ -5,6 +5,7 @@ #include <chain.h> #include <chainparams.h> #include <pow.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <boost/test/unit_test.hpp> diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index 5f4d307048..1559011fcd 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -9,6 +9,7 @@ #include <serialize.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <boost/test/unit_test.hpp> diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 22f6cfd164..ed25401127 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -16,6 +16,7 @@ #include <script/signingprovider.h> #include <streams.h> #include <test/util/json.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <test/util/transaction_utils.h> #include <util/strencodings.h> diff --git a/src/test/serfloat_tests.cpp b/src/test/serfloat_tests.cpp index f6af32cf6c..b36bdc02ca 100644 --- a/src/test/serfloat_tests.cpp +++ b/src/test/serfloat_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <hash.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <util/serfloat.h> #include <serialize.h> diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 368f9e6047..0a33d1b26f 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -11,6 +11,7 @@ #include <streams.h> #include <test/data/sighash.json.h> #include <test/util/json.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <util/strencodings.h> #include <util/system.h> diff --git a/src/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp index ae9021df58..050033e43a 100644 --- a/src/test/skiplist_tests.cpp +++ b/src/test/skiplist_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <chain.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <vector> diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index b7c1ce5066..a9b5251ad3 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -4,6 +4,7 @@ #include <fs.h> #include <streams.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <boost/test/unit_test.hpp> diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 0180fa47e8..ea48dac764 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -22,6 +22,7 @@ #include <script/standard.h> #include <streams.h> #include <test/util/json.h> +#include <test/util/random.h> #include <test/util/script.h> #include <test/util/transaction_utils.h> #include <util/strencodings.h> diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp index e438867d15..024526497c 100644 --- a/src/test/txpackage_tests.cpp +++ b/src/test/txpackage_tests.cpp @@ -9,6 +9,7 @@ #include <primitives/transaction.h> #include <script/script.h> #include <script/standard.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <validation.h> diff --git a/src/test/txrequest_tests.cpp b/src/test/txrequest_tests.cpp index a4ed1e8b3a..17a55d5ab5 100644 --- a/src/test/txrequest_tests.cpp +++ b/src/test/txrequest_tests.cpp @@ -6,6 +6,7 @@ #include <txrequest.h> #include <uint256.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <algorithm> diff --git a/src/test/util/random.h b/src/test/util/random.h new file mode 100644 index 0000000000..72c9ec85e2 --- /dev/null +++ b/src/test/util/random.h @@ -0,0 +1,39 @@ +// 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. + +#ifndef BITCOIN_TEST_UTIL_RANDOM_H +#define BITCOIN_TEST_UTIL_RANDOM_H + +#include <random.h> +#include <test/util/setup_common.h> +#include <uint256.h> + +#include <cstdint> + +static inline uint32_t InsecureRand32() +{ + return g_insecure_rand_ctx.rand32(); +} + +static inline uint256 InsecureRand256() +{ + return g_insecure_rand_ctx.rand256(); +} + +static inline uint64_t InsecureRandBits(int bits) +{ + return g_insecure_rand_ctx.randbits(bits); +} + +static inline uint64_t InsecureRandRange(uint64_t range) +{ + return g_insecure_rand_ctx.randrange(range); +} + +static inline bool InsecureRandBool() +{ + return g_insecure_rand_ctx.randbool(); +} + +#endif // BITCOIN_TEST_UTIL_RANDOM_H diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 5f653d83ae..8874db7e75 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -71,12 +71,6 @@ static inline void SeedInsecureRand(SeedRand seed = SeedRand::SEED) } } -static inline uint32_t InsecureRand32() { return g_insecure_rand_ctx.rand32(); } -static inline uint256 InsecureRand256() { return g_insecure_rand_ctx.rand256(); } -static inline uint64_t InsecureRandBits(int bits) { return g_insecure_rand_ctx.randbits(bits); } -static inline uint64_t InsecureRandRange(uint64_t range) { return g_insecure_rand_ctx.randrange(range); } -static inline bool InsecureRandBool() { return g_insecure_rand_ctx.randbool(); } - static constexpr CAmount CENT{1000000}; /** Basic testing setup. diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 6b6bb18523..f0dcee7a9b 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -9,6 +9,7 @@ #include <hash.h> // For Hash() #include <key.h> // For CKey #include <sync.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <uint256.h> #include <util/getuniquepath.h> diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index 823c9877ac..4c8687ce69 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -11,6 +11,7 @@ #include <pow.h> #include <random.h> #include <script/standard.h> +#include <test/util/random.h> #include <test/util/script.h> #include <test/util/setup_common.h> #include <util/time.h> diff --git a/src/test/validation_chainstate_tests.cpp b/src/test/validation_chainstate_tests.cpp index c40481a95c..877ee30aa3 100644 --- a/src/test/validation_chainstate_tests.cpp +++ b/src/test/validation_chainstate_tests.cpp @@ -8,6 +8,7 @@ #include <rpc/blockchain.h> #include <sync.h> #include <test/util/chainstate.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <uint256.h> #include <validation.h> diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 56867a584b..4609b9a323 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -9,6 +9,7 @@ #include <rpc/blockchain.h> #include <sync.h> #include <test/util/chainstate.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <timedata.h> #include <uint256.h> diff --git a/src/test/validation_flush_tests.cpp b/src/test/validation_flush_tests.cpp index f2ff570ca6..b917fd78b8 100644 --- a/src/test/validation_flush_tests.cpp +++ b/src/test/validation_flush_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. // #include <sync.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <validation.h> diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index 91383ee4a5..80c00036e7 100644 --- a/src/test/versionbits_tests.cpp +++ b/src/test/versionbits_tests.cpp @@ -5,6 +5,7 @@ #include <chain.h> #include <chainparams.h> #include <consensus/params.h> +#include <test/util/random.h> #include <test/util/setup_common.h> #include <versionbits.h> diff --git a/src/wallet/test/wallet_crypto_tests.cpp b/src/wallet/test/wallet_crypto_tests.cpp index 6b8542f378..d5e75bb892 100644 --- a/src/wallet/test/wallet_crypto_tests.cpp +++ b/src/wallet/test/wallet_crypto_tests.cpp @@ -2,6 +2,7 @@ // 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 <test/util/setup_common.h> #include <util/strencodings.h> #include <wallet/crypter.h> |