Skip to content

Commit

Permalink
Merge #11718: tests: move pwalletMain to wallet test fixture
Browse files Browse the repository at this point in the history
49bd659 tests: move pwalletMain to wallet test fixture (Wladimir J. van der Laan)

Pull request description:

  Scope the variable instead of using an external global; this is how test fixtures are intended to be used.

  Followup to #11713.

Tree-SHA512: 7d5bda93cdfe1329c8fe39bd72965906e36dad72fbb5d344ebedf26e66b1857510d01a3c2872d7f718fdeb23365e6ba71991aafe68e82781c6767a086b6d1590
  • Loading branch information
laanwj committed Nov 19, 2017
2 parents 0d89fa0 + 49bd659 commit 9cdd2bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/wallet/test/accounting_tests.cpp
Expand Up @@ -10,18 +10,16 @@

#include <boost/test/unit_test.hpp>

extern std::unique_ptr<CWallet> pwalletMain;

BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)

static void
GetResults(std::map<CAmount, CAccountingEntry>& results)
GetResults(CWallet *wallet, std::map<CAmount, CAccountingEntry>& results)
{
std::list<CAccountingEntry> aes;

results.clear();
BOOST_CHECK(pwalletMain->ReorderTransactions() == DB_LOAD_OK);
pwalletMain->ListAccountCreditDebit("", aes);
BOOST_CHECK(wallet->ReorderTransactions() == DB_LOAD_OK);
wallet->ListAccountCreditDebit("", aes);
for (CAccountingEntry& ae : aes)
{
results[ae.nOrderPos] = ae;
Expand Down Expand Up @@ -54,7 +52,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
ae.strOtherAccount = "c";
pwalletMain->AddAccountingEntry(ae);

GetResults(results);
GetResults(pwalletMain.get(), results);

BOOST_CHECK(pwalletMain->nOrderPosNext == 3);
BOOST_CHECK(2 == results.size());
Expand All @@ -70,7 +68,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
ae.nOrderPos = pwalletMain->IncOrderPosNext();
pwalletMain->AddAccountingEntry(ae);

GetResults(results);
GetResults(pwalletMain.get(), results);

BOOST_CHECK(results.size() == 3);
BOOST_CHECK(pwalletMain->nOrderPosNext == 4);
Expand Down Expand Up @@ -102,7 +100,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
vpwtx[2]->nOrderPos = -1;

GetResults(results);
GetResults(pwalletMain.get(), results);

BOOST_CHECK(results.size() == 3);
BOOST_CHECK(pwalletMain->nOrderPosNext == 6);
Expand All @@ -120,7 +118,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
ae.nOrderPos = -1;
pwalletMain->AddAccountingEntry(ae);

GetResults(results);
GetResults(pwalletMain.get(), results);

BOOST_CHECK(results.size() == 4);
BOOST_CHECK(pwalletMain->nOrderPosNext == 7);
Expand Down
4 changes: 0 additions & 4 deletions src/wallet/test/wallet_test_fixture.cpp
Expand Up @@ -6,9 +6,6 @@

#include <rpc/server.h>
#include <wallet/db.h>
#include <wallet/wallet.h>

std::unique_ptr<CWallet> pwalletMain;

WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
TestingSetup(chainName)
Expand All @@ -27,7 +24,6 @@ WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
WalletTestingSetup::~WalletTestingSetup()
{
UnregisterValidationInterface(pwalletMain.get());
pwalletMain.reset();

bitdb.Flush(true);
bitdb.Reset();
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/test/wallet_test_fixture.h
Expand Up @@ -7,11 +7,15 @@

#include <test/test_bitcoin.h>

#include <wallet/wallet.h>

/** Testing setup and teardown for wallet.
*/
struct WalletTestingSetup: public TestingSetup {
explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
~WalletTestingSetup();

std::unique_ptr<CWallet> pwalletMain;
};

#endif
Expand Down
2 changes: 0 additions & 2 deletions src/wallet/test/wallet_tests.cpp
Expand Up @@ -19,8 +19,6 @@
#include <boost/test/unit_test.hpp>
#include <univalue.h>

extern std::unique_ptr<CWallet> pwalletMain;

extern UniValue importmulti(const JSONRPCRequest& request);
extern UniValue dumpwallet(const JSONRPCRequest& request);
extern UniValue importwallet(const JSONRPCRequest& request);
Expand Down

0 comments on commit 9cdd2bc

Please sign in to comment.