rippled
Loading...
Searching...
No Matches
balance.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx/balance.h>
21
22namespace ripple {
23namespace test {
24namespace jtx {
25
26void
28{
29 if (isXRP(value_.issue()))
30 {
31 auto const sle = env.le(account_);
32 if (none_)
33 {
34 env.test.expect(!sle);
35 }
36 else if (env.test.expect(sle))
37 {
38 env.test.expect(sle->getFieldAmount(sfBalance) == value_);
39 }
40 }
41 else
42 {
43 auto const sle = env.le(keylet::line(account_.id(), value_.issue()));
44 if (none_)
45 {
46 env.test.expect(!sle);
47 }
48 else if (env.test.expect(sle))
49 {
50 auto amount = sle->getFieldAmount(sfBalance);
51 amount.setIssuer(value_.issue().account);
52 if (account_.id() > value_.issue().account)
53 amount.negate();
54 env.test.expect(amount == value_);
55 }
56 }
57}
58
59} // namespace jtx
60} // namespace test
61} // namespace ripple
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:229
AccountID account
Definition Issue.h:36
Issue const & issue() const
Definition STAmount.h:496
AccountID id() const
Returns the Account ID.
Definition Account.h:107
A transaction testing environment.
Definition Env.h:121
beast::unit_test::suite & test
Definition Env.h:123
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition Env.cpp:267
void operator()(Env &) const
Definition balance.cpp:27
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:244
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
bool isXRP(AccountID const &c)
Definition AccountID.h:90