You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_bitcoin.cpp 2.5KB

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