]>
Commit | Line | Data |
---|---|---|
3fc68461 | 1 | // Copyright (c) 2011-2013 The Bitcoin Core developers |
78253fcb | 2 | // Distributed under the MIT software license, see the accompanying |
3fc68461 WL |
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | ||
2c3691d5 | 5 | #define BOOST_TEST_MODULE Bitcoin Test Suite |
51ed9ec9 | 6 | |
51598b26 PW |
7 | #include "test_bitcoin.h" |
8 | ||
a56054be | 9 | #include "key.h" |
1466b8b7 | 10 | #include "main.h" |
6354935c | 11 | #include "random.h" |
51ed9ec9 BD |
12 | #include "txdb.h" |
13 | #include "ui_interface.h" | |
487db8a2 | 14 | #include "util.h" |
48ba56cd | 15 | #ifdef ENABLE_WALLET |
50c72f23 JS |
16 | #include "wallet/db.h" |
17 | #include "wallet/wallet.h" | |
48ba56cd | 18 | #endif |
51ed9ec9 BD |
19 | |
20 | #include <boost/filesystem.hpp> | |
21 | #include <boost/test/unit_test.hpp> | |
ad49c256 | 22 | #include <boost/thread.hpp> |
51ed9ec9 | 23 | |
73ac7abd | 24 | CClientUIInterface uiInterface; |
922e8e29 GA |
25 | CWallet* pwalletMain; |
26 | ||
cc40ba21 | 27 | extern bool fPrintToConsole; |
239c11d0 WL |
28 | extern void noui_connect(); |
29 | ||
92fd887f | 30 | BasicTestingSetup::BasicTestingSetup() |
51598b26 | 31 | { |
a56054be | 32 | ECC_Start(); |
fc3979ac | 33 | SetupEnvironment(); |
9e9056cd | 34 | fPrintToDebugLog = false; // don't want to write to debug.log file |
3fcfbc8a | 35 | fCheckBlockIndex = true; |
59bd89f1 | 36 | SelectParams(CBaseChainParams::MAIN); |
92fd887f WL |
37 | } |
38 | BasicTestingSetup::~BasicTestingSetup() | |
39 | { | |
a56054be | 40 | ECC_Stop(); |
92fd887f WL |
41 | } |
42 | ||
43 | TestingSetup::TestingSetup() | |
44 | { | |
48ba56cd | 45 | #ifdef ENABLE_WALLET |
148e107d | 46 | bitdb.MakeMock(); |
48ba56cd | 47 | #endif |
51598b26 | 48 | ClearDatadirCache(); |
487db8a2 PW |
49 | pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); |
50 | boost::filesystem::create_directories(pathTemp); | |
51 | mapArgs["-datadir"] = pathTemp.string(); | |
c7075c4b PW |
52 | pblocktree = new CBlockTreeDB(1 << 20, true); |
53 | pcoinsdbview = new CCoinsViewDB(1 << 23, true); | |
7c70438d | 54 | pcoinsTip = new CCoinsViewCache(pcoinsdbview); |
38603761 | 55 | InitBlockIndex(); |
48ba56cd | 56 | #ifdef ENABLE_WALLET |
148e107d LD |
57 | bool fFirstRun; |
58 | pwalletMain = new CWallet("wallet.dat"); | |
59 | pwalletMain->LoadWallet(fFirstRun); | |
a96d1139 | 60 | RegisterValidationInterface(pwalletMain); |
48ba56cd | 61 | #endif |
f9cae832 PW |
62 | nScriptCheckThreads = 3; |
63 | for (int i=0; i < nScriptCheckThreads-1; i++) | |
21eb5ada | 64 | threadGroup.create_thread(&ThreadScriptCheck); |
b2864d2f | 65 | RegisterNodeSignals(GetNodeSignals()); |
51598b26 PW |
66 | } |
67 | ||
68 | TestingSetup::~TestingSetup() | |
69 | { | |
70 | UnregisterNodeSignals(GetNodeSignals()); | |
21eb5ada GA |
71 | threadGroup.interrupt_all(); |
72 | threadGroup.join_all(); | |
48ba56cd | 73 | #ifdef ENABLE_WALLET |
51598b26 | 74 | UnregisterValidationInterface(pwalletMain); |
922e8e29 GA |
75 | delete pwalletMain; |
76 | pwalletMain = NULL; | |
48ba56cd | 77 | #endif |
51598b26 | 78 | UnloadBlockIndex(); |
d979e6e3 PW |
79 | delete pcoinsTip; |
80 | delete pcoinsdbview; | |
81 | delete pblocktree; | |
48ba56cd | 82 | #ifdef ENABLE_WALLET |
148e107d | 83 | bitdb.Flush(true); |
51598b26 | 84 | bitdb.Reset(); |
48ba56cd | 85 | #endif |
487db8a2 | 86 | boost::filesystem::remove_all(pathTemp); |
51598b26 | 87 | } |
cc40ba21 | 88 | |
e707d29d VN |
89 | void Shutdown(void* parg) |
90 | { | |
6ccff2cb | 91 | exit(0); |
e707d29d | 92 | } |
641cfb14 WL |
93 | |
94 | void StartShutdown() | |
95 | { | |
96 | exit(0); | |
97 | } | |
98 | ||
e3f5d433 WL |
99 | bool ShutdownRequested() |
100 | { | |
101 | return false; | |
102 | } |