2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include "wallet.h"
|
|
|
|
#include "walletdb.h"
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
extern CWallet* pwalletMain;
|
|
|
|
|
2012-05-28 01:06:09 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE(accounting_tests)
|
|
|
|
|
|
|
|
static void
|
2013-04-13 07:13:08 +02:00
|
|
|
GetResults(CWalletDB& walletdb, std::map<int64_t, CAccountingEntry>& results)
|
2012-05-28 01:06:09 +02:00
|
|
|
{
|
|
|
|
std::list<CAccountingEntry> aes;
|
|
|
|
|
|
|
|
results.clear();
|
|
|
|
BOOST_CHECK(walletdb.ReorderTransactions(pwalletMain) == DB_LOAD_OK);
|
|
|
|
walletdb.ListAccountCreditDebit("", aes);
|
|
|
|
BOOST_FOREACH(CAccountingEntry& ae, aes)
|
|
|
|
{
|
|
|
|
results[ae.nOrderPos] = ae;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|
|
|
{
|
|
|
|
CWalletDB walletdb(pwalletMain->strWalletFile);
|
|
|
|
std::vector<CWalletTx*> vpwtx;
|
|
|
|
CWalletTx wtx;
|
|
|
|
CAccountingEntry ae;
|
2013-04-13 07:13:08 +02:00
|
|
|
std::map<int64_t, CAccountingEntry> results;
|
2012-05-28 01:06:09 +02:00
|
|
|
|
|
|
|
ae.strAccount = "";
|
|
|
|
ae.nCreditDebit = 1;
|
|
|
|
ae.nTime = 1333333333;
|
|
|
|
ae.strOtherAccount = "b";
|
|
|
|
ae.strComment = "";
|
|
|
|
walletdb.WriteAccountingEntry(ae);
|
|
|
|
|
|
|
|
wtx.mapValue["comment"] = "z";
|
|
|
|
pwalletMain->AddToWallet(wtx);
|
|
|
|
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
|
|
|
|
vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
|
|
|
|
vpwtx[0]->nOrderPos = -1;
|
|
|
|
|
|
|
|
ae.nTime = 1333333336;
|
|
|
|
ae.strOtherAccount = "c";
|
|
|
|
walletdb.WriteAccountingEntry(ae);
|
|
|
|
|
|
|
|
GetResults(walletdb, results);
|
|
|
|
|
|
|
|
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();
|
2012-05-28 01:06:09 +02:00
|
|
|
walletdb.WriteAccountingEntry(ae);
|
|
|
|
|
|
|
|
GetResults(walletdb, results);
|
|
|
|
|
|
|
|
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";
|
|
|
|
--wtx.nLockTime; // Just to change the hash :)
|
|
|
|
pwalletMain->AddToWallet(wtx);
|
|
|
|
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
|
|
|
|
vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
|
|
|
|
|
|
|
|
wtx.mapValue["comment"] = "x";
|
|
|
|
--wtx.nLockTime; // Just to change the hash :)
|
|
|
|
pwalletMain->AddToWallet(wtx);
|
|
|
|
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
|
|
|
|
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
|
|
|
|
vpwtx[2]->nOrderPos = -1;
|
|
|
|
|
|
|
|
GetResults(walletdb, results);
|
|
|
|
|
|
|
|
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;
|
|
|
|
walletdb.WriteAccountingEntry(ae);
|
|
|
|
|
|
|
|
GetResults(walletdb, results);
|
|
|
|
|
|
|
|
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()
|