Skip to content

Commit

Permalink
[Tests] Add EvoNotificationInterface in the TestingSetup fixture
Browse files Browse the repository at this point in the history
Thus avoid direct calls to `UpdatedBlockTip` in the tests.
  • Loading branch information
random-zebra committed May 31, 2021
1 parent f6aa6ad commit 4fd564c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/test/evo_deterministicmns_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "script/sign.h"
#include "spork.h"
#include "validation.h"
#include "validationinterface.h"

#include <boost/test/unit_test.hpp>

Expand Down Expand Up @@ -198,7 +199,6 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChain400Setup)
CreateAndProcessBlock({}, coinbaseKey);
chainTip = chainActive.Tip();
BOOST_CHECK_EQUAL(chainTip->nHeight, ++nHeight);
deterministicMNManager->UpdatedBlockTip(chainTip);

// force mnsync complete and enable spork 8
masternodeSync.RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
Expand Down Expand Up @@ -240,8 +240,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChain400Setup)
CreateAndProcessBlock({tx}, coinbaseKey);
chainTip = chainActive.Tip();
BOOST_CHECK_EQUAL(chainTip->nHeight, nHeight + 1);

deterministicMNManager->UpdatedBlockTip(chainTip);
SyncWithValidationInterfaceQueue();
BOOST_CHECK(deterministicMNManager->GetListAtChainTip().HasMN(txid));

// Add change to the utxos map
Expand All @@ -260,10 +259,10 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChain400Setup)
// Mine 20 blocks, checking MN reward payments
std::map<uint256, int> mapPayments;
for (size_t i = 0; i < 20; i++) {
SyncWithValidationInterfaceQueue();
auto dmnExpectedPayee = deterministicMNManager->GetListAtChainTip().GetMNPayee();
CBlock block = CreateAndProcessBlock({}, coinbaseKey);
chainTip = chainActive.Tip();
deterministicMNManager->UpdatedBlockTip(chainTip);
BOOST_ASSERT(!block.vtx.empty());
BOOST_CHECK(IsMNPayeeInBlock(block, dmnExpectedPayee->pdmnState->scriptPayout));
mapPayments[dmnExpectedPayee->proTxHash]++;
Expand Down Expand Up @@ -364,8 +363,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChain400Setup)
CreateAndProcessBlock(txns, coinbaseKey);
chainTip = chainActive.Tip();
BOOST_CHECK_EQUAL(chainTip->nHeight, nHeight + 1);

deterministicMNManager->UpdatedBlockTip(chainTip);
SyncWithValidationInterfaceQueue();
auto mnList = deterministicMNManager->GetListAtChainTip();
for (size_t j = 0; j < 3; j++) {
BOOST_CHECK(mnList.HasMN(txns[j].GetHash()));
Expand All @@ -377,10 +375,10 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChain400Setup)
// Mine 30 blocks, checking MN reward payments
mapPayments.clear();
for (size_t i = 0; i < 30; i++) {
SyncWithValidationInterfaceQueue();
auto dmnExpectedPayee = deterministicMNManager->GetListAtChainTip().GetMNPayee();
CBlock block = CreateAndProcessBlock({}, coinbaseKey);
chainTip = chainActive.Tip();
deterministicMNManager->UpdatedBlockTip(chainTip);
BOOST_ASSERT(!block.vtx.empty());
BOOST_CHECK(IsMNPayeeInBlock(block, dmnExpectedPayee->pdmnState->scriptPayout));
mapPayments[dmnExpectedPayee->proTxHash]++;
Expand Down
12 changes: 8 additions & 4 deletions src/test/test_pivx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "guiinterface.h"
#include "evo/deterministicmns.h"
#include "evo/evodb.h"
#include "evo/evonotificationinterface.h"
#include "miner.h"
#include "net_processing.h"
#include "rpc/server.h"
Expand Down Expand Up @@ -81,6 +82,12 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
// our unit tests aren't testing multiple parts of the code at once.
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);

// Register EvoNotificationInterface
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
connman = g_connman.get();
pEvoNotificationInterface = new EvoNotificationInterface(*connman);
RegisterValidationInterface(pEvoNotificationInterface);

// Ideally we'd move all the RPC tests to the functional testing framework
// instead of unit tests, but for now we need these here.
RegisterAllCoreRPCCommands(tableRPC);
Expand All @@ -100,8 +107,6 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
nScriptCheckThreads = 3;
for (int i=0; i < nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
connman = g_connman.get();
RegisterNodeSignals(GetNodeSignals());
}

Expand All @@ -114,6 +119,7 @@ TestingSetup::~TestingSetup()
UnregisterAllValidationInterfaces();
GetMainSignals().UnregisterBackgroundSignalScheduler();
UnloadBlockIndex();
delete pEvoNotificationInterface;
delete pcoinsTip;
delete pcoinsdbview;
delete pblocktree;
Expand All @@ -139,8 +145,6 @@ TestChainSetup::TestChainSetup(int blockCount) : TestingSetup(CBaseChainParams::
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);
coinbaseTxns.push_back(*b.vtx[0]);
}

deterministicMNManager->UpdatedBlockTip(chainActive.Tip());
}

// Create a new block with coinbase paying to scriptPubKey, and try to add it to the current chain.
Expand Down
2 changes: 2 additions & 0 deletions src/test/test_pivx.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ struct BasicTestingSetup {
* and wallet (if enabled) setup.
*/
class CConnman;
class EvoNotificationInterface;
struct TestingSetup: public BasicTestingSetup
{
CCoinsViewDB *pcoinsdbview;
boost::thread_group threadGroup;
CConnman* connman;
EvoNotificationInterface* pEvoNotificationInterface;
CScheduler scheduler;

TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
Expand Down

0 comments on commit 4fd564c

Please sign in to comment.