mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-05-17 23:56:39 +00:00
Create InsecureRandMoneyAmount() test util helper
to generate semi-random CAmounts up to MAX_MONEY rather than only uint32, and use it in the unit tests.
This commit is contained in:
parent
81f5ade2a3
commit
9d92c3d7f4
@ -173,7 +173,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
|
|||||||
|
|
||||||
if (InsecureRandRange(5) == 0 || coin.IsSpent()) {
|
if (InsecureRandRange(5) == 0 || coin.IsSpent()) {
|
||||||
Coin newcoin;
|
Coin newcoin;
|
||||||
newcoin.out.nValue = InsecureRand32();
|
newcoin.out.nValue = InsecureRandMoneyAmount();
|
||||||
newcoin.nHeight = 1;
|
newcoin.nHeight = 1;
|
||||||
|
|
||||||
// Infrequently test adding unspendable coins.
|
// Infrequently test adding unspendable coins.
|
||||||
|
@ -110,7 +110,7 @@ void static RandomTransaction(CMutableTransaction& tx, bool fSingle)
|
|||||||
for (int out = 0; out < outs; out++) {
|
for (int out = 0; out < outs; out++) {
|
||||||
tx.vout.push_back(CTxOut());
|
tx.vout.push_back(CTxOut());
|
||||||
CTxOut &txout = tx.vout.back();
|
CTxOut &txout = tx.vout.back();
|
||||||
txout.nValue = InsecureRandRange(100000000);
|
txout.nValue = InsecureRandMoneyAmount();
|
||||||
RandomScript(txout.scriptPubKey);
|
RandomScript(txout.scriptPubKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,4 +28,3 @@ bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index,
|
|||||||
filter = BlockFilter(filter_type, block, block_undo);
|
filter = BlockFilter(filter_type, block, block_undo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#ifndef BITCOIN_TEST_UTIL_RANDOM_H
|
#ifndef BITCOIN_TEST_UTIL_RANDOM_H
|
||||||
#define BITCOIN_TEST_UTIL_RANDOM_H
|
#define BITCOIN_TEST_UTIL_RANDOM_H
|
||||||
|
|
||||||
|
#include <consensus/amount.h>
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
@ -36,4 +37,9 @@ static inline bool InsecureRandBool()
|
|||||||
return g_insecure_rand_ctx.randbool();
|
return g_insecure_rand_ctx.randbool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline CAmount InsecureRandMoneyAmount()
|
||||||
|
{
|
||||||
|
return static_cast<CAmount>(InsecureRandRange(MAX_MONEY + 1));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // BITCOIN_TEST_UTIL_RANDOM_H
|
#endif // BITCOIN_TEST_UTIL_RANDOM_H
|
||||||
|
@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
|
|||||||
uint256 txid = InsecureRand256();
|
uint256 txid = InsecureRand256();
|
||||||
COutPoint outp{txid, 0};
|
COutPoint outp{txid, 0};
|
||||||
newcoin.nHeight = 1;
|
newcoin.nHeight = 1;
|
||||||
newcoin.out.nValue = InsecureRand32();
|
newcoin.out.nValue = InsecureRandMoneyAmount();
|
||||||
newcoin.out.scriptPubKey.assign(uint32_t{56}, 1);
|
newcoin.out.scriptPubKey.assign(uint32_t{56}, 1);
|
||||||
coins_view.AddCoin(outp, std::move(newcoin), false);
|
coins_view.AddCoin(outp, std::move(newcoin), false);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
|
|||||||
uint256 txid = InsecureRand256();
|
uint256 txid = InsecureRand256();
|
||||||
COutPoint outp{txid, 0};
|
COutPoint outp{txid, 0};
|
||||||
newcoin.nHeight = 1;
|
newcoin.nHeight = 1;
|
||||||
newcoin.out.nValue = InsecureRand32();
|
newcoin.out.nValue = InsecureRandMoneyAmount();
|
||||||
newcoin.out.scriptPubKey.assign(uint32_t{56}, 1);
|
newcoin.out.scriptPubKey.assign(uint32_t{56}, 1);
|
||||||
coins_view.AddCoin(outp, std::move(newcoin), false);
|
coins_view.AddCoin(outp, std::move(newcoin), false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user