Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
accounting_tests.cpp
Go to the documentation of this file.
1 #include <boost/test/unit_test.hpp>
2 
3 #include <boost/foreach.hpp>
4 
5 #include "init.h"
6 #include "wallet.h"
7 #include "walletdb.h"
8 
9 BOOST_AUTO_TEST_SUITE(accounting_tests)
10 
11 static void
12 GetResults(CWalletDB& walletdb, std::map<int64, CAccountingEntry>& results)
13 {
14  std::list<CAccountingEntry> aes;
15 
16  results.clear();
17  BOOST_CHECK(walletdb.ReorderTransactions(pwalletMain) == DB_LOAD_OK);
18  walletdb.ListAccountCreditDebit("", aes);
19  BOOST_FOREACH(CAccountingEntry& ae, aes)
20  {
21  results[ae.nOrderPos] = ae;
22  }
23 }
24 
25 BOOST_AUTO_TEST_CASE(acc_orderupgrade)
26 {
28  std::vector<CWalletTx*> vpwtx;
29  CWalletTx wtx;
31  std::map<int64, CAccountingEntry> results;
32 
33  ae.strAccount = "";
34  ae.nCreditDebit = 1;
35  ae.nTime = 1333333333;
36  ae.strOtherAccount = "b";
37  ae.strComment = "";
38  walletdb.WriteAccountingEntry(ae);
39 
40  wtx.mapValue["comment"] = "z";
42  vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
43  vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
44  vpwtx[0]->nOrderPos = -1;
45 
46  ae.nTime = 1333333336;
47  ae.strOtherAccount = "c";
48  walletdb.WriteAccountingEntry(ae);
49 
50  GetResults(walletdb, results);
51 
52  BOOST_CHECK(pwalletMain->nOrderPosNext == 3);
53  BOOST_CHECK(2 == results.size());
54  BOOST_CHECK(results[0].nTime == 1333333333);
55  BOOST_CHECK(results[0].strComment.empty());
56  BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
57  BOOST_CHECK(results[2].nTime == 1333333336);
58  BOOST_CHECK(results[2].strOtherAccount == "c");
59 
60 
61  ae.nTime = 1333333330;
62  ae.strOtherAccount = "d";
64  walletdb.WriteAccountingEntry(ae);
65 
66  GetResults(walletdb, results);
67 
68  BOOST_CHECK(results.size() == 3);
69  BOOST_CHECK(pwalletMain->nOrderPosNext == 4);
70  BOOST_CHECK(results[0].nTime == 1333333333);
71  BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
72  BOOST_CHECK(results[2].nTime == 1333333336);
73  BOOST_CHECK(results[3].nTime == 1333333330);
74  BOOST_CHECK(results[3].strComment.empty());
75 
76 
77  wtx.mapValue["comment"] = "y";
78  --wtx.nLockTime; // Just to change the hash :)
80  vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
81  vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
82 
83  wtx.mapValue["comment"] = "x";
84  --wtx.nLockTime; // Just to change the hash :)
86  vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
87  vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
88  vpwtx[2]->nOrderPos = -1;
89 
90  GetResults(walletdb, results);
91 
92  BOOST_CHECK(results.size() == 3);
93  BOOST_CHECK(pwalletMain->nOrderPosNext == 6);
94  BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
95  BOOST_CHECK(results[1].nTime == 1333333333);
96  BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
97  BOOST_CHECK(results[3].nTime == 1333333336);
98  BOOST_CHECK(results[4].nTime == 1333333330);
99  BOOST_CHECK(results[4].strComment.empty());
100  BOOST_CHECK(5 == vpwtx[1]->nOrderPos);
101 
102 
103  ae.nTime = 1333333334;
104  ae.strOtherAccount = "e";
105  ae.nOrderPos = -1;
106  walletdb.WriteAccountingEntry(ae);
107 
108  GetResults(walletdb, results);
109 
110  BOOST_CHECK(results.size() == 4);
111  BOOST_CHECK(pwalletMain->nOrderPosNext == 7);
112  BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
113  BOOST_CHECK(results[1].nTime == 1333333333);
114  BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
115  BOOST_CHECK(results[3].nTime == 1333333336);
116  BOOST_CHECK(results[3].strComment.empty());
117  BOOST_CHECK(results[4].nTime == 1333333330);
118  BOOST_CHECK(results[4].strComment.empty());
119  BOOST_CHECK(results[5].nTime == 1333333334);
120  BOOST_CHECK(6 == vpwtx[1]->nOrderPos);
121 }
122 
123 BOOST_AUTO_TEST_SUITE_END()
int64 nTime
Definition: wallet.h:791
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
uint256 GetHash() const
Definition: main.h:515
mapValue_t mapValue
Definition: wallet.h:374
std::string strComment
Definition: wallet.h:793
unsigned int nLockTime
Definition: main.h:486
bool WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:46
CWallet * pwalletMain
Definition: init.cpp:31
Access to the wallet database (wallet.dat)
Definition: walletdb.h:27
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:367
std::string strWalletFile
Definition: wallet.h:86
Internal transfers.
Definition: wallet.h:786
int64 nOrderPosNext
Definition: wallet.h:116
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:115
int64 nOrderPos
Definition: wallet.h:795
int64 nCreditDebit
Definition: wallet.h:790
std::string strOtherAccount
Definition: wallet.h:792
int64 IncOrderPosNext(CWalletDB *pwalletdb=NULL)
Increment the next transaction order id.
Definition: wallet.cpp:303
bool AddToWallet(const CWalletTx &wtxIn)
Definition: wallet.cpp:374
long long int64
Definition: serialize.h:25
std::string strAccount
Definition: wallet.h:789