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"
12 #include "txmempool.h"
14 #include <boost/filesystem.hpp>
15 #include <boost/thread.hpp>
17 /** Basic testing setup.
18 * This just configures logging and chain parameters.
20 struct BasicTestingSetup
{
21 ECCVerifyHandle globalVerifyHandle
;
23 BasicTestingSetup(const std::string
& chainName
= CBaseChainParams::MAIN
);
27 /** Testing setup that configures a complete environment.
28 * Included are data directory, coins database, script check threads setup.
31 struct TestingSetup
: public BasicTestingSetup
{
32 CCoinsViewDB
*pcoinsdbview
;
33 boost::filesystem::path pathTemp
;
34 boost::thread_group threadGroup
;
37 TestingSetup(const std::string
& chainName
= CBaseChainParams::MAIN
);
42 struct CMutableTransaction
;
46 // Testing fixture that pre-creates a
47 // 100-block REGTEST-mode block chain
49 struct TestChain100Setup
: public TestingSetup
{
52 // Create a new block with just given transactions, coinbase paying to
53 // scriptPubKey, and try to add it to the current chain.
54 CBlock
CreateAndProcessBlock(const std::vector
<CMutableTransaction
>& txns
,
55 const CScript
& scriptPubKey
);
59 std::vector
<CTransaction
> coinbaseTxns
; // For convenience, coinbase transactions
60 CKey coinbaseKey
; // private/public key needed to spend coinbase transactions
63 class CTxMemPoolEntry
;
65 struct TestMemPoolEntryHelper
72 unsigned int sigOpCost
;
75 TestMemPoolEntryHelper() :
76 nFee(0), nTime(0), nHeight(1),
77 spendsCoinbase(false), sigOpCost(4) { }
79 CTxMemPoolEntry
FromTx(const CMutableTransaction
&tx
);
80 CTxMemPoolEntry
FromTx(const CTransaction
&tx
);
82 // Change the default value
83 TestMemPoolEntryHelper
&Fee(CAmount _fee
) { nFee
= _fee
; return *this; }
84 TestMemPoolEntryHelper
&Time(int64_t _time
) { nTime
= _time
; return *this; }
85 TestMemPoolEntryHelper
&Height(unsigned int _height
) { nHeight
= _height
; return *this; }
86 TestMemPoolEntryHelper
&SpendsCoinbase(bool _flag
) { spendsCoinbase
= _flag
; return *this; }
87 TestMemPoolEntryHelper
&SigOpsCost(unsigned int _sigopsCost
) { sigOpCost
= _sigopsCost
; return *this; }