Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

accounting_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <wallet/wallet.h>
6 
8 
9 #include <stdint.h>
10 
11 #include <boost/test/unit_test.hpp>
12 
14 
15 static void
16 GetResults(CWallet& wallet, std::map<CAmount, CAccountingEntry>& results)
17 {
18  std::list<CAccountingEntry> aes;
19 
20  results.clear();
22  wallet.ListAccountCreditDebit("", aes);
23  for (CAccountingEntry& ae : aes)
24  {
25  results[ae.nOrderPos] = ae;
26  }
27 }
28 
29 BOOST_AUTO_TEST_CASE(acc_orderupgrade)
30 {
31  std::vector<CWalletTx*> vpwtx;
32  CWalletTx wtx;
34  std::map<CAmount, CAccountingEntry> results;
35 
36  LOCK(m_wallet.cs_wallet);
37 
38  ae.strAccount = "";
39  ae.nCreditDebit = 1;
40  ae.nTime = 1333333333;
41  ae.strOtherAccount = "b";
42  ae.strComment = "";
43  m_wallet.AddAccountingEntry(ae);
44 
45  wtx.mapValue["comment"] = "z";
46  m_wallet.AddToWallet(wtx);
47  vpwtx.push_back(&m_wallet.mapWallet[wtx.GetHash()]);
48  vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
49  vpwtx[0]->nOrderPos = -1;
50 
51  ae.nTime = 1333333336;
52  ae.strOtherAccount = "c";
53  m_wallet.AddAccountingEntry(ae);
54 
55  GetResults(m_wallet, results);
56 
57  BOOST_CHECK(m_wallet.nOrderPosNext == 3);
58  BOOST_CHECK(2 == results.size());
59  BOOST_CHECK(results[0].nTime == 1333333333);
60  BOOST_CHECK(results[0].strComment.empty());
61  BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
62  BOOST_CHECK(results[2].nTime == 1333333336);
63  BOOST_CHECK(results[2].strOtherAccount == "c");
64 
65 
66  ae.nTime = 1333333330;
67  ae.strOtherAccount = "d";
68  ae.nOrderPos = m_wallet.IncOrderPosNext();
69  m_wallet.AddAccountingEntry(ae);
70 
71  GetResults(m_wallet, results);
72 
73  BOOST_CHECK(results.size() == 3);
74  BOOST_CHECK(m_wallet.nOrderPosNext == 4);
75  BOOST_CHECK(results[0].nTime == 1333333333);
76  BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
77  BOOST_CHECK(results[2].nTime == 1333333336);
78  BOOST_CHECK(results[3].nTime == 1333333330);
79  BOOST_CHECK(results[3].strComment.empty());
80 
81 
82  wtx.mapValue["comment"] = "y";
83  {
84  CMutableTransaction tx(*wtx.tx);
85  --tx.nLockTime; // Just to change the hash :)
86  wtx.SetTx(MakeTransactionRef(std::move(tx)));
87  }
88  m_wallet.AddToWallet(wtx);
89  vpwtx.push_back(&m_wallet.mapWallet[wtx.GetHash()]);
90  vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
91 
92  wtx.mapValue["comment"] = "x";
93  {
94  CMutableTransaction tx(*wtx.tx);
95  --tx.nLockTime; // Just to change the hash :)
96  wtx.SetTx(MakeTransactionRef(std::move(tx)));
97  }
98  m_wallet.AddToWallet(wtx);
99  vpwtx.push_back(&m_wallet.mapWallet[wtx.GetHash()]);
100  vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
101  vpwtx[2]->nOrderPos = -1;
102 
103  GetResults(m_wallet, results);
104 
105  BOOST_CHECK(results.size() == 3);
106  BOOST_CHECK(m_wallet.nOrderPosNext == 6);
107  BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
108  BOOST_CHECK(results[1].nTime == 1333333333);
109  BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
110  BOOST_CHECK(results[3].nTime == 1333333336);
111  BOOST_CHECK(results[4].nTime == 1333333330);
112  BOOST_CHECK(results[4].strComment.empty());
113  BOOST_CHECK(5 == vpwtx[1]->nOrderPos);
114 
115 
116  ae.nTime = 1333333334;
117  ae.strOtherAccount = "e";
118  ae.nOrderPos = -1;
119  m_wallet.AddAccountingEntry(ae);
120 
121  GetResults(m_wallet, results);
122 
123  BOOST_CHECK(results.size() == 4);
124  BOOST_CHECK(m_wallet.nOrderPosNext == 7);
125  BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
126  BOOST_CHECK(results[1].nTime == 1333333333);
127  BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
128  BOOST_CHECK(results[3].nTime == 1333333336);
129  BOOST_CHECK(results[3].strComment.empty());
130  BOOST_CHECK(results[4].nTime == 1333333330);
131  BOOST_CHECK(results[4].strComment.empty());
132  BOOST_CHECK(results[5].nTime == 1333333334);
133  BOOST_CHECK(6 == vpwtx[1]->nOrderPos);
134 }
135 
void SetTx(CTransactionRef arg)
Definition: wallet.h:238
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:640
const uint256 & GetHash() const
Definition: wallet.h:272
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:311
static void GetResults(CWallet &wallet, std::map< CAmount, CAccountingEntry > &results)
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:346
std::string strComment
Definition: wallet.h:638
DBErrors ReorderTransactions()
Definition: wallet.cpp:920
CTransactionRef tx
Definition: wallet.h:210
#define LOCK(cs)
Definition: sync.h:178
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:280
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
Testing setup and teardown for wallet.
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &entries)
Definition: wallet.cpp:4135
Internal transfers.
Definition: wallet.h:631
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
A mutable version of CTransaction.
Definition: transaction.h:291
std::string strOtherAccount
Definition: wallet.h:637
CAmount nCreditDebit
Definition: wallet.h:635
int64_t nTime
Definition: wallet.h:636
#define BOOST_CHECK(expr)
Definition: object.cpp:17
std::string strAccount
Definition: wallet.h:634
Released under the MIT license