aff4b6d2c5
c2f61be Add a ForceSetArg method for testing (Matt Corallo) 4e04814 Lock mapArgs/mapMultiArgs access in util (Matt Corallo) 4cd373a Un-expose mapArgs from utils.h (Matt Corallo) 71fde55 Get rid of mapArgs direct access in ZMQ construction (Matt Corallo) 0cf86a6 Introduce (and use) an IsArgSet accessor method (Matt Corallo) 2b5f085 Fix non-const mapMultiArgs[] access after init. (Matt Corallo) c8042a4 Remove arguments to ParseConfigFile (Matt Corallo)
167 lines
5.2 KiB
C++
167 lines
5.2 KiB
C++
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#define BOOST_TEST_MODULE Dash Test Suite
|
|
|
|
#include "test_dash.h"
|
|
|
|
#include "chainparams.h"
|
|
#include "consensus/consensus.h"
|
|
#include "consensus/validation.h"
|
|
#include "key.h"
|
|
#include "validation.h"
|
|
#include "miner.h"
|
|
#include "net_processing.h"
|
|
#include "pubkey.h"
|
|
#include "random.h"
|
|
#include "txdb.h"
|
|
#include "txmempool.h"
|
|
#include "ui_interface.h"
|
|
#include "rpc/server.h"
|
|
#include "rpc/register.h"
|
|
#include "script/sigcache.h"
|
|
|
|
#include "test/testutil.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/test/unit_test.hpp>
|
|
#include <boost/thread.hpp>
|
|
|
|
std::unique_ptr<CConnman> g_connman;
|
|
FastRandomContext insecure_rand_ctx(true);
|
|
|
|
extern bool fPrintToConsole;
|
|
extern void noui_connect();
|
|
|
|
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
|
|
{
|
|
ECC_Start();
|
|
SetupEnvironment();
|
|
SetupNetworking();
|
|
InitSignatureCache();
|
|
fPrintToDebugLog = false; // don't want to write to debug.log file
|
|
fCheckBlockIndex = true;
|
|
SelectParams(chainName);
|
|
noui_connect();
|
|
}
|
|
|
|
BasicTestingSetup::~BasicTestingSetup()
|
|
{
|
|
ECC_Stop();
|
|
g_connman.reset();
|
|
}
|
|
|
|
TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
|
|
{
|
|
const CChainParams& chainparams = Params();
|
|
// Ideally we'd move all the RPC tests to the functional testing framework
|
|
// instead of unit tests, but for now we need these here.
|
|
RegisterAllCoreRPCCommands(tableRPC);
|
|
ClearDatadirCache();
|
|
pathTemp = GetTempPath() / strprintf("test_dash_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
|
|
boost::filesystem::create_directories(pathTemp);
|
|
ForceSetArg("-datadir", pathTemp.string());
|
|
mempool.setSanityCheck(1.0);
|
|
pblocktree = new CBlockTreeDB(1 << 20, true);
|
|
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
|
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
|
InitBlockIndex(chainparams);
|
|
{
|
|
CValidationState state;
|
|
bool ok = ActivateBestChain(state, chainparams);
|
|
BOOST_CHECK(ok);
|
|
}
|
|
nScriptCheckThreads = 3;
|
|
for (int i=0; i < nScriptCheckThreads-1; i++)
|
|
threadGroup.create_thread(&ThreadScriptCheck);
|
|
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
|
|
connman = g_connman.get();
|
|
RegisterNodeSignals(GetNodeSignals());
|
|
}
|
|
|
|
TestingSetup::~TestingSetup()
|
|
{
|
|
UnregisterNodeSignals(GetNodeSignals());
|
|
threadGroup.interrupt_all();
|
|
threadGroup.join_all();
|
|
UnloadBlockIndex();
|
|
delete pcoinsTip;
|
|
delete pcoinsdbview;
|
|
delete pblocktree;
|
|
boost::filesystem::remove_all(pathTemp);
|
|
}
|
|
|
|
TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
|
|
{
|
|
// Generate a 100-block chain:
|
|
coinbaseKey.MakeNewKey(true);
|
|
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
|
for (int i = 0; i < COINBASE_MATURITY; i++)
|
|
{
|
|
std::vector<CMutableTransaction> noTxns;
|
|
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);
|
|
coinbaseTxns.push_back(*b.vtx[0]);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Create a new block with just given transactions, coinbase paying to
|
|
// scriptPubKey, and try to add it to the current chain.
|
|
//
|
|
CBlock
|
|
TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
|
|
{
|
|
const CChainParams& chainparams = Params();
|
|
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
|
|
CBlock& block = pblocktemplate->block;
|
|
|
|
// Replace mempool-selected txns with just coinbase plus passed-in txns:
|
|
block.vtx.resize(1);
|
|
BOOST_FOREACH(const CMutableTransaction& tx, txns)
|
|
block.vtx.push_back(MakeTransactionRef(tx));
|
|
// IncrementExtraNonce creates a valid coinbase and merkleRoot
|
|
unsigned int extraNonce = 0;
|
|
IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
|
|
|
|
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
|
|
|
|
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
|
|
ProcessNewBlock(chainparams, shared_pblock, true, NULL);
|
|
|
|
CBlock result = block;
|
|
return result;
|
|
}
|
|
|
|
TestChain100Setup::~TestChain100Setup()
|
|
{
|
|
}
|
|
|
|
|
|
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx, CTxMemPool *pool) {
|
|
CTransaction txn(tx);
|
|
bool hasNoDependencies = pool ? pool->HasNoInputsOf(tx) : hadNoDependencies;
|
|
// Hack to assume either its completely dependent on other mempool txs or not at all
|
|
CAmount inChainValue = hasNoDependencies ? txn.GetValueOut() : 0;
|
|
|
|
return CTxMemPoolEntry(txn, nFee, nTime, dPriority, nHeight,
|
|
hasNoDependencies, inChainValue, spendsCoinbase, sigOpCount, lp);
|
|
}
|
|
|
|
void Shutdown(void* parg)
|
|
{
|
|
exit(0);
|
|
}
|
|
|
|
void StartShutdown()
|
|
{
|
|
exit(0);
|
|
}
|
|
|
|
bool ShutdownRequested()
|
|
{
|
|
return false;
|
|
}
|