Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
test_bitcoin.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE Feathercoin Test Suite
2 #include <boost/test/unit_test.hpp>
3 #include <boost/filesystem.hpp>
4 
5 #include "db.h"
6 #include "txdb.h"
7 #include "main.h"
8 #include "wallet.h"
9 #include "util.h"
10 
13 
14 extern bool fPrintToConsole;
15 extern void noui_connect();
16 
17 struct TestingSetup {
19  boost::filesystem::path pathTemp;
20  boost::thread_group threadGroup;
21 
23  fPrintToDebugger = true; // don't want to write to debug.log file
24  noui_connect();
25  bitdb.MakeMock();
26  pathTemp = GetTempPath() / strprintf("test_feathercoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
27  boost::filesystem::create_directories(pathTemp);
28  mapArgs["-datadir"] = pathTemp.string();
29  pblocktree = new CBlockTreeDB(1 << 20, true);
30  pcoinsdbview = new CCoinsViewDB(1 << 23, true);
31  pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
33  bool fFirstRun;
34  pwalletMain = new CWallet("wallet.dat");
35  pwalletMain->LoadWallet(fFirstRun);
36  RegisterWallet(pwalletMain);
38  for (int i=0; i < nScriptCheckThreads-1; i++)
39  threadGroup.create_thread(&ThreadScriptCheck);
40  }
42  {
43  threadGroup.interrupt_all();
44  threadGroup.join_all();
45  delete pwalletMain;
46  pwalletMain = NULL;
47  delete pcoinsTip;
48  delete pcoinsdbview;
49  delete pblocktree;
50  bitdb.Flush(true);
51  boost::filesystem::remove_all(pathTemp);
52  }
53 };
54 
56 
57 void Shutdown(void* parg)
58 {
59  exit(0);
60 }
61 
63 {
64  exit(0);
65 }
66 
#define strprintf(format,...)
Definition: util.h:169
void StartShutdown()
boost::filesystem::path GetTempPath()
Definition: util.cpp:1438
void ThreadScriptCheck()
Run an instance of the script checking thread.
Definition: main.cpp:1672
void Flush(bool fShutdown)
Definition: db.cpp:429
Signals for UI communication.
Definition: ui_interface.h:26
int64 GetTime()
Definition: util.cpp:1298
CDBEnv bitdb
Definition: db.cpp:29
int nScriptCheckThreads
Definition: main.cpp:48
void MakeMock()
Definition: db.cpp:105
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: main.cpp:290
CWallet * pwalletMain
Access to the block database (blocks/index/)
Definition: txdb.h:32
CClientUIInterface uiInterface
uint64 GetRand(uint64 nMax)
Definition: util.cpp:175
bool fPrintToConsole
Definition: util.cpp:75
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:289
BOOST_GLOBAL_FIXTURE(TestingSetup)
boost::filesystem::path pathTemp
CCoinsView backed by the LevelDB coin database (chainstate/)
Definition: txdb.h:15
void Shutdown(void *parg)
bool fPrintToDebugger
Definition: util.cpp:76
void RegisterWallet(CWallet *pwalletIn)
Register a wallet to receive updates from core.
Definition: main.cpp:96
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:69
DBErrors LoadWallet(bool &fFirstRunRet)
Definition: wallet.cpp:1438
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: main.h:2194
bool InitBlockIndex()
Initialize a new block tree database + block data on disk.
Definition: main.cpp:2836
CCoinsViewDB * pcoinsdbview
void noui_connect()
Definition: noui.cpp:45
map< string, string > mapArgs
Definition: util.cpp:71
boost::thread_group threadGroup