Changeset View
Changeset View
Standalone View
Standalone View
src/test/test_bitcoin.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#define BOOST_TEST_MODULE Bitcoin Test Suite | |||||
#include "test_bitcoin.h" | #include "test_bitcoin.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/consensus.h" | #include "consensus/consensus.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "crypto/sha256.h" | #include "crypto/sha256.h" | ||||
#include "fs.h" | #include "fs.h" | ||||
#include "key.h" | #include "key.h" | ||||
#include "miner.h" | #include "miner.h" | ||||
#include "net_processing.h" | #include "net_processing.h" | ||||
#include "pubkey.h" | #include "pubkey.h" | ||||
#include "random.h" | #include "random.h" | ||||
#include "rpc/register.h" | #include "rpc/register.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "script/scriptcache.h" | #include "script/scriptcache.h" | ||||
#include "script/sigcache.h" | #include "script/sigcache.h" | ||||
#include "txdb.h" | #include "txdb.h" | ||||
#include "txmempool.h" | #include "txmempool.h" | ||||
#include "ui_interface.h" | #include "ui_interface.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "test/testutil.h" | #include "test/testutil.h" | ||||
#include <boost/test/unit_test.hpp> | |||||
#include <boost/thread.hpp> | |||||
#include <atomic> | #include <atomic> | ||||
#include <chrono> | #include <chrono> | ||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <functional> | #include <functional> | ||||
#include <list> | #include <list> | ||||
#include <memory> | #include <memory> | ||||
#include <thread> | #include <thread> | ||||
std::unique_ptr<CConnman> g_connman; | |||||
uint256 insecure_rand_seed = GetRandHash(); | uint256 insecure_rand_seed = GetRandHash(); | ||||
FastRandomContext insecure_rand_ctx(insecure_rand_seed); | FastRandomContext insecure_rand_ctx(insecure_rand_seed); | ||||
extern bool fPrintToConsole; | extern bool fPrintToConsole; | ||||
extern void noui_connect(); | extern void noui_connect(); | ||||
BasicTestingSetup::BasicTestingSetup(const std::string &chainName) { | BasicTestingSetup::BasicTestingSetup(const std::string &chainName) { | ||||
SHA256AutoDetect(); | SHA256AutoDetect(); | ||||
Show All 31 Lines | pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", | ||||
(unsigned long)GetTime(), | (unsigned long)GetTime(), | ||||
(int)(InsecureRandRange(100000))); | (int)(InsecureRandRange(100000))); | ||||
fs::create_directories(pathTemp); | fs::create_directories(pathTemp); | ||||
ForceSetArg("-datadir", pathTemp.string()); | ForceSetArg("-datadir", pathTemp.string()); | ||||
mempool.setSanityCheck(1.0); | mempool.setSanityCheck(1.0); | ||||
pblocktree = new CBlockTreeDB(1 << 20, true); | pblocktree = new CBlockTreeDB(1 << 20, true); | ||||
pcoinsdbview = new CCoinsViewDB(1 << 23, true); | pcoinsdbview = new CCoinsViewDB(1 << 23, true); | ||||
pcoinsTip = new CCoinsViewCache(pcoinsdbview); | pcoinsTip = new CCoinsViewCache(pcoinsdbview); | ||||
BOOST_REQUIRE(InitBlockIndex(config)); | if (!InitBlockIndex(config)) { | ||||
throw std::runtime_error("InitBlockIndex failed."); | |||||
} | |||||
{ | { | ||||
CValidationState state; | CValidationState state; | ||||
bool ok = ActivateBestChain(config, state); | if (!ActivateBestChain(config, state)) { | ||||
BOOST_REQUIRE(ok); | throw std::runtime_error("ActivateBestChain failed."); | ||||
} | |||||
} | } | ||||
nScriptCheckThreads = 3; | nScriptCheckThreads = 3; | ||||
for (int i = 0; i < nScriptCheckThreads - 1; i++) { | for (int i = 0; i < nScriptCheckThreads - 1; i++) { | ||||
threadGroup.create_thread(&ThreadScriptCheck); | threadGroup.create_thread(&ThreadScriptCheck); | ||||
} | } | ||||
// Deterministic randomness for tests. | // Deterministic randomness for tests. | ||||
g_connman = std::unique_ptr<CConnman>(new CConnman(config, 0x1337, 0x1337)); | g_connman = std::unique_ptr<CConnman>(new CConnman(config, 0x1337, 0x1337)); | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransaction &txn, | ||||
Amount inChainValue = | Amount inChainValue = | ||||
pool && pool->HasNoInputsOf(txn) ? txn.GetValueOut() : Amount(0); | pool && pool->HasNoInputsOf(txn) ? txn.GetValueOut() : Amount(0); | ||||
return CTxMemPoolEntry(MakeTransactionRef(txn), nFee, nTime, dPriority, | return CTxMemPoolEntry(MakeTransactionRef(txn), nFee, nTime, dPriority, | ||||
nHeight, inChainValue, spendsCoinbase, sigOpCost, | nHeight, inChainValue, spendsCoinbase, sigOpCost, | ||||
lp); | lp); | ||||
} | } | ||||
void Shutdown(void *parg) { | |||||
exit(0); | |||||
} | |||||
void StartShutdown() { | |||||
exit(0); | |||||
} | |||||
bool ShutdownRequested() { | |||||
return false; | |||||
} | |||||
namespace { | namespace { | ||||
// A place to put misc. setup code eg "the travis workaround" that needs to run | // A place to put misc. setup code eg "the travis workaround" that needs to run | ||||
// at program startup and exit | // at program startup and exit | ||||
struct Init { | struct Init { | ||||
Init(); | Init(); | ||||
~Init(); | ~Init(); | ||||
std::list<std::function<void(void)>> cleanup; | std::list<std::function<void(void)>> cleanup; | ||||
}; | }; | ||||
Init init; | Init init; | ||||
Init::Init() { | Init::Init() { | ||||
if (getenv("TRAVIS_NOHANG_WORKAROUND")) { | if (getenv("TRAVIS_NOHANG_WORKAROUND")) { | ||||
// This is a workaround for MinGW/Win32 builds on Travis sometimes | // This is a workaround for MinGW/Win32 builds on Travis sometimes | ||||
// hanging due to no output received by Travis after a 10-minute | // hanging due to no output received by Travis after a 10-minute | ||||
// timeout. | // timeout. | ||||
// The strategy here is to let the jobs finish however long they take | // The strategy here is to let the jobs finish however long they take | ||||
// on Travis, by feeding Travis output. We start a parallel thread | // on Travis, by feeding Travis output. We start a parallel thread | ||||
// that just prints out '.' once per second. | // that just prints out '.' once per second. | ||||
struct Private { | struct Private { | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |