rippled
Loading...
Searching...
No Matches
balance.cpp
1#include <test/jtx/balance.h>
2
3namespace xrpl {
4namespace test {
5namespace jtx {
6
7#define TEST_EXPECT(cond) env.test.expect(cond, __FILE__, __LINE__)
8#define TEST_EXPECTS(cond, reason) \
9 ((cond) ? (env.test.pass(), true) : (env.test.fail((reason), __FILE__, __LINE__), false))
10
11void
12doBalance(Env& env, AccountID const& account, bool none, STAmount const& value, Issue const& issue)
13{
14 if (isXRP(issue))
15 {
16 auto const sle = env.le(keylet::account(account));
17 if (none)
18 {
19 TEST_EXPECT(!sle);
20 }
21 else if (TEST_EXPECT(sle))
22 {
23 TEST_EXPECTS(
24 sle->getFieldAmount(sfBalance) == value,
25 sle->getFieldAmount(sfBalance).getText() + " / " + value.getText());
26 }
27 }
28 else
29 {
30 auto const sle = env.le(keylet::line(account, issue));
31 if (none)
32 {
33 TEST_EXPECT(!sle);
34 }
35 else if (TEST_EXPECT(sle))
36 {
37 auto amount = sle->getFieldAmount(sfBalance);
38 amount.setIssuer(issue.account);
39 if (account > issue.account)
40 amount.negate();
41 TEST_EXPECTS(amount == value, amount.getText());
42 }
43 }
44}
45
46void
47doBalance(Env& env, AccountID const& account, bool none, STAmount const& value, MPTIssue const& mptIssue)
48{
49 auto const sle = env.le(keylet::mptoken(mptIssue.getMptID(), account));
50 if (none)
51 {
52 TEST_EXPECT(!sle);
53 }
54 else if (TEST_EXPECT(sle))
55 {
56 STAmount const amount{mptIssue, sle->getFieldU64(sfMPTAmount)};
57 TEST_EXPECT(amount == value);
58 }
59}
60
61void
63{
64 return std::visit(
65 [&](auto const& issue) { doBalance(env, account_.id(), none_, value_, issue); }, value_.asset().value());
66}
67
68} // namespace jtx
69} // namespace test
70} // namespace xrpl
constexpr value_type const & value() const
Definition Asset.h:154
A currency issued by an account.
Definition Issue.h:13
AccountID account
Definition Issue.h:16
constexpr MPTID const & getMptID() const
Definition MPTIssue.h:26
std::string getText() const override
Definition STAmount.cpp:639
Asset const & asset() const
Definition STAmount.h:441
AccountID id() const
Returns the Account ID.
Definition Account.h:87
A transaction testing environment.
Definition Env.h:119
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition Env.cpp:249
void operator()(Env &) const
Definition balance.cpp:62
Account const account_
Definition balance.h:22
STAmount const value_
Definition balance.h:23
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:214
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Definition Indexes.cpp:474
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
static none_t const none
Definition tags.h:14
auto const amount
void doBalance(Env &env, AccountID const &account, bool none, STAmount const &value, Issue const &issue)
Definition balance.cpp:12
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool isXRP(AccountID const &c)
Definition AccountID.h:70
T visit(T... args)