diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 54efcc8b9f166..986025eb716b3 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -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 # diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index cd0e81583d830..cad742bb43bde 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -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 diff --git a/src/wallet/test/pos_test_fixture.cpp b/src/wallet/test/pos_test_fixture.cpp new file mode 100644 index 0000000000000..85dae892e1cb0 --- /dev/null +++ b/src/wallet/test/pos_test_fixture.cpp @@ -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 + +TestPoSChainSetup::TestPoSChainSetup() : TestChainSetup(0) +{ + initZKSNARKS(); // init zk-snarks lib + + bool fFirstRun; + pwalletMain = std::make_unique("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()); +} diff --git a/src/wallet/test/pos_test_fixture.h b/src/wallet/test/pos_test_fixture.h new file mode 100644 index 0000000000000..8948c8d83b27d --- /dev/null +++ b/src/wallet/test/pos_test_fixture.h @@ -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 pwalletMain; + + TestPoSChainSetup(); + ~TestPoSChainSetup(); +}; + +#endif // PIVX_POS_TEST_FIXTURE_H