xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
impl
balance.cpp
1
#include <test/jtx/balance.h>
2
3
#include <test/jtx/Env.h>
4
5
#include <xrpl/protocol/AccountID.h>
6
#include <xrpl/protocol/Indexes.h>
7
#include <xrpl/protocol/Issue.h>
8
#include <xrpl/protocol/MPTIssue.h>
9
#include <xrpl/protocol/SField.h>
10
#include <xrpl/protocol/STAmount.h>
11
12
#include <
variant
>
13
14
namespace
xrpl::test::jtx
{
15
16
#define TEST_EXPECT(cond) env.test.expect(cond, __FILE__, __LINE__)
17
#define TEST_EXPECTS(cond, reason) \
18
((cond) ? (env.test.pass(), true) : (env.test.fail((reason), __FILE__, __LINE__), false))
19
20
void
21
doBalance
(
Env
& env,
AccountID
const
& account,
bool
kNone
,
STAmount
const
& value,
Issue
const
& issue)
22
{
23
if
(
isXRP
(issue))
24
{
25
auto
const
sle = env.
le
(
keylet::account
(account));
26
if
(
kNone
)
27
{
28
TEST_EXPECT(!sle);
29
}
30
else
if
(TEST_EXPECT(sle))
31
{
32
TEST_EXPECTS(
33
sle->getFieldAmount(sfBalance) == value,
34
sle->getFieldAmount(sfBalance).getText() +
" / "
+ value.getText());
35
}
36
}
37
else
38
{
39
auto
const
sle = env.
le
(
keylet::trustLine
(account, issue));
40
if
(
kNone
)
41
{
42
TEST_EXPECT(!sle);
43
}
44
else
if
(TEST_EXPECT(sle))
45
{
46
auto
amount = sle->getFieldAmount(sfBalance);
47
amount.get<
Issue
>().account = value.getIssuer();
48
if
(account > value.getIssuer())
49
amount.negate();
50
TEST_EXPECTS(amount == value, amount.getText());
51
}
52
}
53
}
54
55
void
56
doBalance
(
57
Env
& env,
58
AccountID
const
& account,
59
bool
kNone
,
60
STAmount
const
& value,
61
MPTIssue
const
& mptIssue)
62
{
63
auto
const
sle = env.
le
(
keylet::mptoken
(mptIssue.
getMptID
(), account));
64
if
(
kNone
)
65
{
66
TEST_EXPECT(!sle);
67
}
68
else
if
(TEST_EXPECT(sle))
69
{
70
STAmount
const
amount{mptIssue, sle->getFieldU64(sfMPTAmount)};
71
TEST_EXPECT(amount == value);
72
}
73
}
74
75
void
76
Balance::operator()
(
Env
& env)
const
77
{
78
std::visit
(
79
[&](
auto
const
& issue) {
doBalance
(env,
account_
.id(),
none_
,
value_
, issue); },
80
value_
.asset().value());
81
}
82
83
}
// namespace xrpl::test::jtx
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::MPTIssue
Definition
MPTIssue.h:23
xrpl::MPTIssue::getMptID
constexpr MPTID const & getMptID() const
Definition
MPTIssue.h:43
xrpl::STAmount
Definition
STAmount.h:46
xrpl::test::jtx::Balance::operator()
void operator()(Env &) const
Definition
balance.cpp:76
xrpl::test::jtx::Balance::value_
STAmount const value_
Definition
balance.h:28
xrpl::test::jtx::Balance::account_
Account const account_
Definition
balance.h:27
xrpl::test::jtx::Balance::none_
bool const none_
Definition
balance.h:26
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::le
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition
Env.cpp:311
xrpl::keylet::mptoken
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Definition
Indexes.cpp:573
xrpl::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition
Indexes.cpp:220
xrpl::keylet::trustLine
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Definition
Indexes.cpp:275
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test::jtx::kNone
static NoneT const kNone
Definition
tags.h:9
xrpl::test::jtx::doBalance
void doBalance(Env &env, AccountID const &account, bool kNone, STAmount const &value, Issue const &issue)
Definition
balance.cpp:21
xrpl::isXRP
bool isXRP(AccountID const &c)
Definition
AccountID.h:84
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
variant
std::visit
T visit(T... args)
Generated by
1.17.0