Skip to content

Commit

Permalink
[Test] Introduce PoS testing suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Aug 3, 2021
1 parent e98c1e8 commit a195c2e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ BITCOIN_TEST_SUITE = \
if ENABLE_WALLET
BITCOIN_TEST_SUITE += \
wallet/test/wallet_test_fixture.cpp \
wallet/test/wallet_test_fixture.h
wallet/test/wallet_test_fixture.h \
wallet/test/pos_test_fixture.cpp \
wallet/test/pos_test_fixture.h
endif

# test_pivx binary #
Expand Down
2 changes: 2 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ set(BITCOIN_TEST_SUITE
${CMAKE_CURRENT_SOURCE_DIR}/librust/sapling_test_fixture.cpp
${CMAKE_SOURCE_DIR}/src/wallet/test/wallet_test_fixture.h
${CMAKE_SOURCE_DIR}/src/wallet/test/wallet_test_fixture.cpp
${CMAKE_SOURCE_DIR}/src/wallet/test/pos_test_fixture.h
${CMAKE_SOURCE_DIR}/src/wallet/test/pos_test_fixture.cpp
${CMAKE_CURRENT_SOURCE_DIR}/librust/utiltest.h
${CMAKE_CURRENT_SOURCE_DIR}/librust/utiltest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/librust/json_test_vectors.h
Expand Down
40 changes: 40 additions & 0 deletions src/wallet/test/pos_test_fixture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2021 The PIVX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include "wallet/test/pos_test_fixture.h"
#include "wallet/wallet.h"

#include <boost/test/unit_test.hpp>

TestPoSChainSetup::TestPoSChainSetup() : TestChainSetup(0)
{
initZKSNARKS(); // init zk-snarks lib

bool fFirstRun;
pwalletMain = std::make_unique<CWallet>("testWallet", CWalletDBWrapper::CreateMock());
pwalletMain->LoadWallet(fFirstRun);
RegisterValidationInterface(pwalletMain.get());

{
LOCK(pwalletMain->cs_wallet);
pwalletMain->SetMinVersion(FEATURE_SAPLING);
gArgs.ForceSetArg("-keypool", "5");
pwalletMain->SetupSPKM(true);

// import coinbase key used to generate the 100-blocks chain
BOOST_CHECK(pwalletMain->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()));
}

int posActivation = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_POS].nActivationHeight - 1;
for (int i = 0; i < posActivation; i++) {
CBlock b = CreateAndProcessBlock({}, coinbaseKey);
coinbaseTxns.emplace_back(*b.vtx[0]);
}
}

TestPoSChainSetup::~TestPoSChainSetup()
{
SyncWithValidationInterfaceQueue();
UnregisterValidationInterface(pwalletMain.get());
}
24 changes: 24 additions & 0 deletions src/wallet/test/pos_test_fixture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2021 The PIVX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#ifndef PIVX_POS_TEST_FIXTURE_H
#define PIVX_POS_TEST_FIXTURE_H

#include "test/test_pivx.h"

class CWallet;

/*
* A text fixture with a preloaded 250-blocks regtest chain running running on PoS
* and a wallet containing the key used for the coinbase outputs.
*/
struct TestPoSChainSetup: public TestChainSetup
{
std::unique_ptr<CWallet> pwalletMain;

TestPoSChainSetup();
~TestPoSChainSetup();
};

#endif // PIVX_POS_TEST_FIXTURE_H

0 comments on commit a195c2e

Please sign in to comment.