2016-12-31 19:01:21 +01:00
|
|
|
// Copyright (c) 2012-2016 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-03-18 10:11:00 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <wallet/wallet.h>
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <wallet/test/wallet_test_fixture.h>
|
2015-03-03 16:49:12 +01:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2017-11-18 08:55:45 +01:00
|
|
|
extern std::unique_ptr<CWallet> pwalletMain;
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2016-04-18 14:54:57 +02:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
static void
|
2016-09-10 04:23:36 +02:00
|
|
|
GetResults(std::map<CAmount, CAccountingEntry>& results)
|
2012-05-28 01:06:09 +02:00
|
|
|
{
|
|
|
|
std::list<CAccountingEntry> aes;
|
|
|
|
|
|
|
|
results.clear();
|
2016-09-10 04:21:44 +02:00
|
|
|
BOOST_CHECK(pwalletMain->ReorderTransactions() == DB_LOAD_OK);
|
2016-09-10 03:53:23 +02:00
|
|
|
pwalletMain->ListAccountCreditDebit("", aes);
|
2017-06-02 03:18:57 +02:00
|
|
|
for (CAccountingEntry& ae : aes)
|
2012-05-28 01:06:09 +02:00
|
|
|
{
|
|
|
|
results[ae.nOrderPos] = ae;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|
|
|
{
|
|
|
|
std::vector<CWalletTx*> vpwtx;
|
|
|
|
CWalletTx wtx;
|
|
|
|
CAccountingEntry ae;
|
2014-04-23 00:46:19 +02:00
|
|
|
std::map<CAmount, CAccountingEntry> results;
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2014-01-23 20:18:26 +01:00
|
|
|
LOCK(pwalletMain->cs_wallet);
|
|
|
|
|
2012-05-28 01:06:09 +02:00
|
|
|
ae.strAccount = "";
|
|
|
|
ae.nCreditDebit = 1;
|
|
|
|
ae.nTime = 1333333333;
|
|
|
|
ae.strOtherAccount = "b";
|
|
|
|
ae.strComment = "";
|
2016-09-10 04:22:59 +02:00
|
|
|
pwalletMain->AddAccountingEntry(ae);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
wtx.mapValue["comment"] = "z";
|
2016-06-08 06:41:03 +02:00
|
|
|
pwalletMain->AddToWallet(wtx);
|
2012-05-28 01:06:09 +02:00
|
|
|
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
|
|
|
|
vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
|
|
|
|
vpwtx[0]->nOrderPos = -1;
|
|
|
|
|
|
|
|
ae.nTime = 1333333336;
|
|
|
|
ae.strOtherAccount = "c";
|
2016-09-10 04:22:59 +02:00
|
|
|
pwalletMain->AddAccountingEntry(ae);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2016-09-10 04:23:36 +02:00
|
|
|
GetResults(results);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 3);
|
|
|
|
BOOST_CHECK(2 == results.size());
|
|
|
|
BOOST_CHECK(results[0].nTime == 1333333333);
|
|
|
|
BOOST_CHECK(results[0].strComment.empty());
|
|
|
|
BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
|
|
|
|
BOOST_CHECK(results[2].nTime == 1333333336);
|
|
|
|
BOOST_CHECK(results[2].strOtherAccount == "c");
|
|
|
|
|
|
|
|
|
|
|
|
ae.nTime = 1333333330;
|
|
|
|
ae.strOtherAccount = "d";
|
2012-09-08 06:55:36 +02:00
|
|
|
ae.nOrderPos = pwalletMain->IncOrderPosNext();
|
2016-09-10 04:22:59 +02:00
|
|
|
pwalletMain->AddAccountingEntry(ae);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2016-09-10 04:23:36 +02:00
|
|
|
GetResults(results);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(results.size() == 3);
|
|
|
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 4);
|
|
|
|
BOOST_CHECK(results[0].nTime == 1333333333);
|
|
|
|
BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
|
|
|
|
BOOST_CHECK(results[2].nTime == 1333333336);
|
|
|
|
BOOST_CHECK(results[3].nTime == 1333333330);
|
|
|
|
BOOST_CHECK(results[3].strComment.empty());
|
|
|
|
|
|
|
|
|
|
|
|
wtx.mapValue["comment"] = "y";
|
2014-06-07 13:53:27 +02:00
|
|
|
{
|
2017-05-09 08:46:26 +02:00
|
|
|
CMutableTransaction tx(*wtx.tx);
|
2014-06-07 13:53:27 +02:00
|
|
|
--tx.nLockTime; // Just to change the hash :)
|
2016-11-12 01:54:51 +01:00
|
|
|
wtx.SetTx(MakeTransactionRef(std::move(tx)));
|
2014-06-07 13:53:27 +02:00
|
|
|
}
|
2016-06-08 06:41:03 +02:00
|
|
|
pwalletMain->AddToWallet(wtx);
|
2012-05-28 01:06:09 +02:00
|
|
|
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
|
|
|
|
vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
|
|
|
|
|
|
|
|
wtx.mapValue["comment"] = "x";
|
2014-06-07 13:53:27 +02:00
|
|
|
{
|
2017-05-09 08:46:26 +02:00
|
|
|
CMutableTransaction tx(*wtx.tx);
|
2014-06-07 13:53:27 +02:00
|
|
|
--tx.nLockTime; // Just to change the hash :)
|
2016-11-12 01:54:51 +01:00
|
|
|
wtx.SetTx(MakeTransactionRef(std::move(tx)));
|
2014-06-07 13:53:27 +02:00
|
|
|
}
|
2016-06-08 06:41:03 +02:00
|
|
|
pwalletMain->AddToWallet(wtx);
|
2012-05-28 01:06:09 +02:00
|
|
|
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
|
|
|
|
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
|
|
|
|
vpwtx[2]->nOrderPos = -1;
|
|
|
|
|
2016-09-10 04:23:36 +02:00
|
|
|
GetResults(results);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(results.size() == 3);
|
|
|
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 6);
|
|
|
|
BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
|
|
|
|
BOOST_CHECK(results[1].nTime == 1333333333);
|
|
|
|
BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
|
|
|
|
BOOST_CHECK(results[3].nTime == 1333333336);
|
|
|
|
BOOST_CHECK(results[4].nTime == 1333333330);
|
|
|
|
BOOST_CHECK(results[4].strComment.empty());
|
|
|
|
BOOST_CHECK(5 == vpwtx[1]->nOrderPos);
|
|
|
|
|
|
|
|
|
|
|
|
ae.nTime = 1333333334;
|
|
|
|
ae.strOtherAccount = "e";
|
|
|
|
ae.nOrderPos = -1;
|
2016-09-10 04:22:59 +02:00
|
|
|
pwalletMain->AddAccountingEntry(ae);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
2016-09-10 04:23:36 +02:00
|
|
|
GetResults(results);
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
BOOST_CHECK(results.size() == 4);
|
|
|
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 7);
|
|
|
|
BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
|
|
|
|
BOOST_CHECK(results[1].nTime == 1333333333);
|
|
|
|
BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
|
|
|
|
BOOST_CHECK(results[3].nTime == 1333333336);
|
|
|
|
BOOST_CHECK(results[3].strComment.empty());
|
|
|
|
BOOST_CHECK(results[4].nTime == 1333333330);
|
|
|
|
BOOST_CHECK(results[4].strComment.empty());
|
|
|
|
BOOST_CHECK(results[5].nTime == 1333333334);
|
|
|
|
BOOST_CHECK(6 == vpwtx[1]->nOrderPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|