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.4KB

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