Files
thehub/testing/common/TestFloweeSession.cpp
T

82 lines
2.7 KiB
C++
Raw Permalink Normal View History

2018-08-14 19:01:37 +02:00
/*
* This file is part of the Flowee project
* Copyright (C) 2011-2015 The Bitcoin Core developers
2021-01-20 15:57:19 +01:00
* Copyright (C) 2017-2021 Tom Zander <tom@flowee.org>
2018-08-14 19:01:37 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestFloweeSession.h"
2018-09-20 21:03:27 +02:00
#include "script/sigcache.h"
2018-08-14 19:01:37 +02:00
#include "MockApplication.h"
2018-08-15 20:38:28 +02:00
#include <utxo/UnspentOutputDatabase.h>
2018-11-13 23:07:30 +01:00
#include <BlocksDB.h>
#include <interfaces/validationinterface.h>
#include <UiInterface.h>
2019-08-24 13:20:37 +02:00
#include <util.h>
2026-05-14 13:13:40 +02:00
#include <utiltime.h>
2018-08-14 19:01:37 +02:00
#include <main.h>
#include <boost/filesystem.hpp>
CClientUIInterface uiInterface; // Declared but not defined in UiInterface.h
2018-08-15 20:38:28 +02:00
UnspentOutputDatabase *g_utxo = nullptr;
2019-04-21 14:39:55 +02:00
void TestFloweeSession::init()
2018-08-14 19:01:37 +02:00
{
2025-02-08 19:05:26 +01:00
MockApplication::doStartThreads();
2019-04-21 14:39:55 +02:00
bv.reset(new MockBlockValidation());
2018-08-14 19:01:37 +02:00
ClearDatadirCache();
2019-11-13 11:46:09 +01:00
pathTemp = boost::filesystem::temp_directory_path() / strprintf("test_flowee_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
2018-08-14 19:01:37 +02:00
boost::filesystem::create_directories(pathTemp / "regtest/blocks/index");
boost::filesystem::create_directories(pathTemp / "blocks/index");
mapArgs["-datadir"] = pathTemp.string();
Blocks::DB::createTestInstance(1<<20);
UnspentOutputDatabase::setSmallLimits();
2025-02-08 19:05:26 +01:00
g_utxo = new UnspentOutputDatabase(Application::instance()->ioContext(), GetDataDir(true) / "unspent");
2018-08-14 19:01:37 +02:00
2025-02-08 19:05:26 +01:00
// in case the executable already shut them down, lets restart them.
2019-04-21 14:39:55 +02:00
bv->initSingletons();
bv->appendGenesis();
MockApplication::setValidationEngine(bv.get());
2018-08-14 19:01:37 +02:00
RegisterNodeSignals(GetNodeSignals());
}
2019-04-21 14:39:55 +02:00
TestFloweeSession::TestFloweeSession(const std::string& chainName) : TestFloweeEnvPlusNet(chainName)
{
InitSignatureCache();
}
void TestFloweeSession::cleanup()
2018-08-14 19:01:37 +02:00
{
MockApplication::setValidationEngine(nullptr);
2021-01-20 15:57:19 +01:00
bv->waitValidationFinished();
2019-04-21 14:39:55 +02:00
bv->shutdown();
2018-08-14 19:01:37 +02:00
Blocks::Index::unload();
2025-02-08 19:05:26 +01:00
Application::instance()->stopThreads();
Application::instance()->joinAll();
2018-08-14 19:01:37 +02:00
UnregisterNodeSignals(GetNodeSignals());
ValidationNotifier().removeAll();
UnloadBlockIndex();
2018-08-15 20:38:28 +02:00
delete g_utxo;
2020-12-24 14:15:48 +01:00
g_utxo = nullptr;
2018-08-14 19:01:37 +02:00
boost::filesystem::remove_all(pathTemp);
}
2019-04-21 14:39:55 +02:00
TestFloweeSession::~TestFloweeSession()
{
}