qa: Only allow disconnecting all NodeConns
[bitcoinplatinum.git] / src / test / test_bitcoin.h
blob62ded2aaf5ac3ce09571edfbd163958f89edc79b
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 "scheduler.h"
14 #include "txdb.h"
15 #include "txmempool.h"
17 #include <boost/thread.hpp>
19 extern uint256 insecure_rand_seed;
20 extern FastRandomContext insecure_rand_ctx;
22 static inline void SeedInsecureRand(bool fDeterministic = false)
24 if (fDeterministic) {
25 insecure_rand_seed = uint256();
26 } else {
27 insecure_rand_seed = GetRandHash();
29 insecure_rand_ctx = FastRandomContext(insecure_rand_seed);
32 static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); }
33 static inline uint256 InsecureRand256() { return insecure_rand_ctx.rand256(); }
34 static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.randbits(bits); }
35 static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); }
36 static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); }
38 /** Basic testing setup.
39 * This just configures logging and chain parameters.
41 struct BasicTestingSetup {
42 ECCVerifyHandle globalVerifyHandle;
44 explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
45 ~BasicTestingSetup();
48 /** Testing setup that configures a complete environment.
49 * Included are data directory, coins database, script check threads setup.
51 class CConnman;
52 class CNode;
53 struct CConnmanTest {
54 static void AddNode(CNode& node);
55 static void ClearNodes();
58 class PeerLogicValidation;
59 struct TestingSetup: public BasicTestingSetup {
60 CCoinsViewDB *pcoinsdbview;
61 fs::path pathTemp;
62 boost::thread_group threadGroup;
63 CConnman* connman;
64 CScheduler scheduler;
65 std::unique_ptr<PeerLogicValidation> peerLogic;
67 explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
68 ~TestingSetup();
71 class CBlock;
72 struct CMutableTransaction;
73 class CScript;
76 // Testing fixture that pre-creates a
77 // 100-block REGTEST-mode block chain
79 struct TestChain100Setup : public TestingSetup {
80 TestChain100Setup();
82 // Create a new block with just given transactions, coinbase paying to
83 // scriptPubKey, and try to add it to the current chain.
84 CBlock CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns,
85 const CScript& scriptPubKey);
87 ~TestChain100Setup();
89 std::vector<CTransaction> coinbaseTxns; // For convenience, coinbase transactions
90 CKey coinbaseKey; // private/public key needed to spend coinbase transactions
93 class CTxMemPoolEntry;
95 struct TestMemPoolEntryHelper
97 // Default values
98 CAmount nFee;
99 int64_t nTime;
100 unsigned int nHeight;
101 bool spendsCoinbase;
102 unsigned int sigOpCost;
103 LockPoints lp;
105 TestMemPoolEntryHelper() :
106 nFee(0), nTime(0), nHeight(1),
107 spendsCoinbase(false), sigOpCost(4) { }
109 CTxMemPoolEntry FromTx(const CMutableTransaction &tx);
110 CTxMemPoolEntry FromTx(const CTransaction &tx);
112 // Change the default value
113 TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
114 TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; return *this; }
115 TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
116 TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
117 TestMemPoolEntryHelper &SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
120 CBlock getBlock13b8a();
122 #endif