Add tests for CMerkleBlock usage with txids specified
[bitcoinplatinum.git] / src / test / test_bitcoin.h
blob2390aca34208266ea9f9c3a64d3a56abbf94ef0e
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 PeerLogicValidation;
53 struct TestingSetup: public BasicTestingSetup {
54 CCoinsViewDB *pcoinsdbview;
55 fs::path pathTemp;
56 boost::thread_group threadGroup;
57 CConnman* connman;
58 CScheduler scheduler;
59 std::unique_ptr<PeerLogicValidation> peerLogic;
61 explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
62 ~TestingSetup();
65 class CBlock;
66 struct CMutableTransaction;
67 class CScript;
70 // Testing fixture that pre-creates a
71 // 100-block REGTEST-mode block chain
73 struct TestChain100Setup : public TestingSetup {
74 TestChain100Setup();
76 // Create a new block with just given transactions, coinbase paying to
77 // scriptPubKey, and try to add it to the current chain.
78 CBlock CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns,
79 const CScript& scriptPubKey);
81 ~TestChain100Setup();
83 std::vector<CTransaction> coinbaseTxns; // For convenience, coinbase transactions
84 CKey coinbaseKey; // private/public key needed to spend coinbase transactions
87 class CTxMemPoolEntry;
89 struct TestMemPoolEntryHelper
91 // Default values
92 CAmount nFee;
93 int64_t nTime;
94 unsigned int nHeight;
95 bool spendsCoinbase;
96 unsigned int sigOpCost;
97 LockPoints lp;
99 TestMemPoolEntryHelper() :
100 nFee(0), nTime(0), nHeight(1),
101 spendsCoinbase(false), sigOpCost(4) { }
103 CTxMemPoolEntry FromTx(const CMutableTransaction &tx);
104 CTxMemPoolEntry FromTx(const CTransaction &tx);
106 // Change the default value
107 TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
108 TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; return *this; }
109 TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
110 TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
111 TestMemPoolEntryHelper &SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
114 CBlock getBlock13b8a();
116 #endif