]> Git Repo - VerusCoin.git/blob - src/test/test_bitcoin.cpp
Bitcore port
[VerusCoin.git] / src / test / test_bitcoin.cpp
1 // Copyright (c) 2011-2013 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.
4
5 #define BOOST_TEST_MODULE Bitcoin Test Suite
6
7 #include "test_bitcoin.h"
8
9 #include "crypto/common.h"
10
11 #include "key.h"
12 #include "main.h"
13 #include "random.h"
14 #include "chainparamsbase.h"
15 #include "txdb.h"
16 #include "ui_interface.h"
17 #include "util.h"
18 #ifdef ENABLE_WALLET
19 #include "wallet/db.h"
20 #include "wallet/wallet.h"
21 #endif
22
23 #include <boost/filesystem.hpp>
24 #include <boost/test/unit_test.hpp>
25 #include <boost/thread.hpp>
26
27 CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h
28 CWallet* pwalletMain;
29 ZCJoinSplit *pzcashParams;
30
31 extern bool fPrintToConsole;
32 extern void noui_connect();
33
34 BasicTestingSetup::BasicTestingSetup()
35 {
36         assert(init_and_check_sodium() != -1);
37         ECC_Start();
38         pzcashParams = ZCJoinSplit::Unopened();
39         SetupEnvironment();
40         fPrintToDebugLog = false; // don't want to write to debug.log file
41         fCheckBlockIndex = true;
42         SelectParams(CBaseChainParams::MAIN);
43 }
44 BasicTestingSetup::~BasicTestingSetup()
45 {
46         ECC_Stop();
47         delete pzcashParams;
48 }
49
50 TestingSetup::TestingSetup()
51 {
52 #ifdef ENABLE_WALLET
53         bitdb.MakeMock();
54 #endif
55         ClearDatadirCache();
56         pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
57         boost::filesystem::create_directories(pathTemp);
58         mapArgs["-datadir"] = pathTemp.string();
59         pblocktree = new CBlockTreeDB(1 << 20, true);
60         pcoinsdbview = new CCoinsViewDB(1 << 23, true);
61         pcoinsTip = new CCoinsViewCache(pcoinsdbview);
62         InitBlockIndex();
63 #ifdef ENABLE_WALLET
64         bool fFirstRun;
65         pwalletMain = new CWallet("wallet.dat");
66         pwalletMain->LoadWallet(fFirstRun);
67         RegisterValidationInterface(pwalletMain);
68 #endif
69         nScriptCheckThreads = 3;
70         for (int i=0; i < nScriptCheckThreads-1; i++)
71             threadGroup.create_thread(&ThreadScriptCheck);
72         RegisterNodeSignals(GetNodeSignals());
73 }
74
75 TestingSetup::~TestingSetup()
76 {
77         UnregisterNodeSignals(GetNodeSignals());
78         threadGroup.interrupt_all();
79         threadGroup.join_all();
80 #ifdef ENABLE_WALLET
81         UnregisterValidationInterface(pwalletMain);
82         delete pwalletMain;
83         pwalletMain = NULL;
84 #endif
85         UnloadBlockIndex();
86         delete pcoinsTip;
87         delete pcoinsdbview;
88         delete pblocktree;
89 #ifdef ENABLE_WALLET
90         bitdb.Flush(true);
91         bitdb.Reset();
92 #endif
93         boost::filesystem::remove_all(pathTemp);
94 }
95
96 void Shutdown(void* parg)
97 {
98   exit(0);
99 }
100
101 void StartShutdown()
102 {
103   exit(0);
104 }
105
106 bool ShutdownRequested()
107 {
108   return false;
109 }
This page took 0.029415 seconds and 4 git commands to generate.