[tests] Remove unused function InsecureRandBytes(size_t len)
[bitcoinplatinum.git] / src / test / test_bitcoin.h
blobc9e4a3427fc393c6cc7ffc83ee583047960515b8
1 // Copyright (c) 2015-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_TEST_TEST_BITCOIN_H
6 #define BITCOIN_TEST_TEST_BITCOIN_H
8 #include "chainparamsbase.h"
9 #include "fs.h"
10 #include "key.h"
11 #include "pubkey.h"
12 #include "random.h"
13 #include "txdb.h"
14 #include "txmempool.h"
16 #include <boost/thread.hpp>
18 extern uint256 insecure_rand_seed;
19 extern FastRandomContext insecure_rand_ctx;
21 static inline void SeedInsecureRand(bool fDeterministic = false)
23 if (fDeterministic) {
24 insecure_rand_seed = uint256();
25 } else {
26 insecure_rand_seed = GetRandHash();
28 insecure_rand_ctx = FastRandomContext(insecure_rand_seed);
31 static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); }
32 static inline uint256 InsecureRand256() { return insecure_rand_ctx.rand256(); }
33 static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.randbits(bits); }
34 static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); }
35 static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); }
37 /** Basic testing setup.
38 * This just configures logging and chain parameters.
40 struct BasicTestingSetup {
41 ECCVerifyHandle globalVerifyHandle;
43 BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
44 ~BasicTestingSetup();
47 /** Testing setup that configures a complete environment.
48 * Included are data directory, coins database, script check threads setup.
50 class CConnman;
51 struct TestingSetup: public BasicTestingSetup {
52 CCoinsViewDB *pcoinsdbview;
53 fs::path pathTemp;
54 boost::thread_group threadGroup;
55 CConnman* connman;
57 TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
58 ~TestingSetup();
61 class CBlock;
62 struct CMutableTransaction;
63 class CScript;
66 // Testing fixture that pre-creates a
67 // 100-block REGTEST-mode block chain
69 struct TestChain100Setup : public TestingSetup {
70 TestChain100Setup();
72 // Create a new block with just given transactions, coinbase paying to
73 // scriptPubKey, and try to add it to the current chain.
74 CBlock CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns,
75 const CScript& scriptPubKey);
77 ~TestChain100Setup();
79 std::vector<CTransaction> coinbaseTxns; // For convenience, coinbase transactions
80 CKey coinbaseKey; // private/public key needed to spend coinbase transactions
83 class CTxMemPoolEntry;
85 struct TestMemPoolEntryHelper
87 // Default values
88 CAmount nFee;
89 int64_t nTime;
90 unsigned int nHeight;
91 bool spendsCoinbase;
92 unsigned int sigOpCost;
93 LockPoints lp;
95 TestMemPoolEntryHelper() :
96 nFee(0), nTime(0), nHeight(1),
97 spendsCoinbase(false), sigOpCost(4) { }
99 CTxMemPoolEntry FromTx(const CMutableTransaction &tx);
100 CTxMemPoolEntry FromTx(const CTransaction &tx);
102 // Change the default value
103 TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
104 TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; return *this; }
105 TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
106 TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
107 TestMemPoolEntryHelper &SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
109 #endif