Skip to content

Commit a245429

Browse files
committed
Merge bitcoin/bitcoin#26940: test: create random and coins utils, add amount helper, dedupe add_coin
4275195 De-duplicate add_coin methods to a test util helper (Jon Atack) 9d92c3d Create InsecureRandMoneyAmount() test util helper (Jon Atack) 81f5ade Move random test util code from setup_common to random (Jon Atack) Pull request description: - Move random test utilities from `setup_common` to a new `random` file, as many tests don't use this code. - Create a helper to generate semi-random CAmounts up to `MONEY_RANGE` rather than only uint32, and use the helper in the unit tests. - De-duplicate a shared `add_coin` method by extracting it to a `coins` test utility. ACKs for top commit: pinheadmz: ACK 4275195 achow101: ACK 4275195 john-moffett: ACK 4275195 Tree-SHA512: 3ed974251149c7417f935ef2f8865aa0dcc33b281b47522b0f96f1979dff94bb8527957f098fe4d210f40d715c00f29512f2ffe189097102229023b7284a3a27
2 parents 9321df4 + 4275195 commit a245429

39 files changed

+139
-43
lines changed

ci/test/06_script_b.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
6060
" src/rpc/signmessage.cpp"\
6161
" src/test/fuzz/txorphan.cpp"\
6262
" src/test/fuzz/util/"\
63+
" src/test/util/coins.cpp"\
6364
" src/uint256.cpp"\
6465
" src/util/bip32.cpp"\
6566
" src/util/bytevectorhash.cpp"\

src/Makefile.test_util.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ EXTRA_LIBRARIES += \
1010
TEST_UTIL_H = \
1111
test/util/blockfilter.h \
1212
test/util/chainstate.h \
13+
test/util/coins.h \
1314
test/util/json.h \
1415
test/util/logging.h \
1516
test/util/mining.h \
1617
test/util/net.h \
18+
test/util/random.h \
1719
test/util/script.h \
1820
test/util/setup_common.h \
1921
test/util/str.h \
@@ -30,6 +32,7 @@ libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
3032
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
3133
libtest_util_a_SOURCES = \
3234
test/util/blockfilter.cpp \
35+
test/util/coins.cpp \
3336
test/util/json.cpp \
3437
test/util/logging.cpp \
3538
test/util/mining.cpp \

src/test/base58_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <base58.h>
88
#include <test/util/json.h>
9+
#include <test/util/random.h>
910
#include <test/util/setup_common.h>
1011
#include <util/strencodings.h>
1112
#include <util/vector.h>

src/test/blockencodings_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <consensus/merkle.h>
88
#include <pow.h>
99
#include <streams.h>
10+
#include <test/util/random.h>
1011
#include <test/util/txmempool.h>
1112

1213
#include <test/util/setup_common.h>

src/test/bloom_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <random.h>
1313
#include <serialize.h>
1414
#include <streams.h>
15+
#include <test/util/random.h>
1516
#include <test/util/setup_common.h>
1617
#include <uint256.h>
1718
#include <util/strencodings.h>

src/test/checkqueue_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <checkqueue.h>
66
#include <sync.h>
7+
#include <test/util/random.h>
78
#include <test/util/setup_common.h>
89
#include <util/system.h>
910
#include <util/time.h>

src/test/coins_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <coins.h>
77
#include <script/standard.h>
88
#include <streams.h>
9+
#include <test/util/random.h>
910
#include <test/util/setup_common.h>
1011
#include <txdb.h>
1112
#include <uint256.h>
@@ -172,7 +173,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
172173

173174
if (InsecureRandRange(5) == 0 || coin.IsSpent()) {
174175
Coin newcoin;
175-
newcoin.out.nValue = InsecureRand32();
176+
newcoin.out.nValue = InsecureRandMoneyAmount();
176177
newcoin.nHeight = 1;
177178

178179
// Infrequently test adding unspendable coins.

src/test/crypto_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <crypto/muhash.h>
1818
#include <random.h>
1919
#include <streams.h>
20+
#include <test/util/random.h>
2021
#include <test/util/setup_common.h>
2122
#include <util/strencodings.h>
2223

src/test/cuckoocache_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright (c) 2012-2021 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
45
#include <cuckoocache.h>
56
#include <random.h>
67
#include <script/sigcache.h>
8+
#include <test/util/random.h>
79
#include <test/util/setup_common.h>
810

911
#include <boost/test/unit_test.hpp>

src/test/dbwrapper_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <dbwrapper.h>
6+
#include <test/util/random.h>
67
#include <test/util/setup_common.h>
78
#include <uint256.h>
89
#include <util/string.h>

0 commit comments

Comments
 (0)