|
|
|
// Copyright (c) 2011-2013 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 Bitcoin Test Suite
|
|
|
|
|
|
|
|
#include "test_bitcoin.h"
|
|
|
|
|
|
|
|
#include "chainparams.h"
|
Update key.cpp to use new libsecp256k1
libsecp256k1's API changed, so update key.cpp to use it.
Libsecp256k1 now has explicit context objects, which makes it completely thread-safe.
In turn, keep an explicit context object in key.cpp, which is explicitly initialized
destroyed. This is not really pretty now, but it's more efficient than the static
initialized object in key.cpp (which made for example bitcoin-tx slow, as for most of
its calls, libsecp256k1 wasn't actually needed).
This also brings in the new blinding support in libsecp256k1. By passing in a random
seed, temporary variables during the elliptic curve computations are altered, in such
a way that if an attacker does not know the blind, observing the internal operations
leaks less information about the keys used. This was implemented by Greg Maxwell.
10 years ago
|
|
|
#include "key.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "txdb.h"
|
|
|
|
#include "ui_interface.h"
|
|
|
|
#include "util.h"
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
#include "wallet/db.h"
|
|
|
|
#include "wallet/wallet.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
10 years ago
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
|
|
|
CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h
|
|
|
|
CWallet* pwalletMain;
|
|
|
|
|
|
|
|
extern bool fPrintToConsole;
|
|
|
|
extern void noui_connect();
|
|
|
|
|
|
|
|
BasicTestingSetup::BasicTestingSetup()
|
|
|
|
{
|
Update key.cpp to use new libsecp256k1
libsecp256k1's API changed, so update key.cpp to use it.
Libsecp256k1 now has explicit context objects, which makes it completely thread-safe.
In turn, keep an explicit context object in key.cpp, which is explicitly initialized
destroyed. This is not really pretty now, but it's more efficient than the static
initialized object in key.cpp (which made for example bitcoin-tx slow, as for most of
its calls, libsecp256k1 wasn't actually needed).
This also brings in the new blinding support in libsecp256k1. By passing in a random
seed, temporary variables during the elliptic curve computations are altered, in such
a way that if an attacker does not know the blind, observing the internal operations
leaks less information about the keys used. This was implemented by Greg Maxwell.
10 years ago
|
|
|
ECC_Start();
|
|
|
|
SetupEnvironment();
|
|
|
|
fPrintToDebugLog = false; // don't want to write to debug.log file
|
|
|
|
fCheckBlockIndex = true;
|
|
|
|
SelectParams(CBaseChainParams::MAIN);
|
|
|
|
}
|
|
|
|
BasicTestingSetup::~BasicTestingSetup()
|
|
|
|
{
|
Update key.cpp to use new libsecp256k1
libsecp256k1's API changed, so update key.cpp to use it.
Libsecp256k1 now has explicit context objects, which makes it completely thread-safe.
In turn, keep an explicit context object in key.cpp, which is explicitly initialized
destroyed. This is not really pretty now, but it's more efficient than the static
initialized object in key.cpp (which made for example bitcoin-tx slow, as for most of
its calls, libsecp256k1 wasn't actually needed).
This also brings in the new blinding support in libsecp256k1. By passing in a random
seed, temporary variables during the elliptic curve computations are altered, in such
a way that if an attacker does not know the blind, observing the internal operations
leaks less information about the keys used. This was implemented by Greg Maxwell.
10 years ago
|
|
|
ECC_Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
TestingSetup::TestingSetup()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
bitdb.MakeMock();
|
|
|
|
#endif
|
|
|
|
ClearDatadirCache();
|
|
|
|
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
|
|
|
|
boost::filesystem::create_directories(pathTemp);
|
|
|
|
mapArgs["-datadir"] = pathTemp.string();
|
|
|
|
pblocktree = new CBlockTreeDB(1 << 20, true);
|
|
|
|
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
|
|
|
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
|
|
|
InitBlockIndex();
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
bool fFirstRun;
|
|
|
|
pwalletMain = new CWallet("wallet.dat");
|
|
|
|
pwalletMain->LoadWallet(fFirstRun);
|
|
|
|
RegisterValidationInterface(pwalletMain);
|
|
|
|
#endif
|
|
|
|
nScriptCheckThreads = 3;
|
|
|
|
for (int i=0; i < nScriptCheckThreads-1; i++)
|
|
|
|
threadGroup.create_thread(&ThreadScriptCheck);
|
|
|
|
RegisterNodeSignals(GetNodeSignals());
|
|
|
|
}
|
|
|
|
|
|
|
|
TestingSetup::~TestingSetup()
|
|
|
|
{
|
|
|
|
UnregisterNodeSignals(GetNodeSignals());
|
|
|
|
threadGroup.interrupt_all();
|
|
|
|
threadGroup.join_all();
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
UnregisterValidationInterface(pwalletMain);
|
|
|
|
delete pwalletMain;
|
|
|
|
pwalletMain = NULL;
|
|
|
|
#endif
|
|
|
|
UnloadBlockIndex();
|
|
|
|
delete pcoinsTip;
|
|
|
|
delete pcoinsdbview;
|
|
|
|
delete pblocktree;
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
bitdb.Flush(true);
|
|
|
|
bitdb.Reset();
|
|
|
|
#endif
|
|
|
|
boost::filesystem::remove_all(pathTemp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown(void* parg)
|
|
|
|
{
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartShutdown()
|
|
|
|
{
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShutdownRequested()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|