rippled
owners.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/owners.h>
21 
22 namespace ripple {
23 namespace test {
24 namespace jtx {
25 
26 namespace detail {
27 
29 owned_count_of(ReadView const& view, AccountID const& id, LedgerEntryType type)
30 {
31  std::uint32_t count = 0;
33  view, id, [&count, type](std::shared_ptr<SLE const> const& sle) {
34  if (sle->getType() == type)
35  ++count;
36  });
37  return count;
38 }
39 
40 void
42  Env& env,
43  AccountID const& id,
44  LedgerEntryType type,
45  std::uint32_t value)
46 {
47  env.test.expect(owned_count_of(*env.current(), id, type) == value);
48 }
49 
50 } // namespace detail
51 
52 void
54 {
55  env.test.expect(env.le(account_)->getFieldU32(sfOwnerCount) == value_);
56 }
57 
58 } // namespace jtx
59 } // namespace test
60 } // namespace ripple
ripple::sfOwnerCount
const SF_UINT32 sfOwnerCount
std::shared_ptr
STL class.
ripple::test::jtx::detail::owned_count_of
std::uint32_t owned_count_of(ReadView const &view, AccountID const &id, LedgerEntryType type)
Definition: owners.cpp:29
ripple::test::jtx::owners::account_
Account account_
Definition: owners.h:72
ripple::test::jtx::detail::owned_count_helper
void owned_count_helper(Env &env, AccountID const &id, LedgerEntryType type, std::uint32_t value)
Definition: owners.cpp:41
ripple::base_uint< 160, detail::AccountIDTag >
std::uint32_t
ripple::test::jtx::Env::test
beast::unit_test::suite & test
Definition: Env.h:119
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerEntryType
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:53
ripple::test::jtx::Env::le
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition: Env.cpp:216
ripple::forEachItem
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
Definition: View.cpp:367
ripple::test::jtx::owners::operator()
void operator()(Env &env) const
Definition: owners.cpp:53
ripple::test::jtx::owners::value_
std::uint32_t value_
Definition: owners.h:73
ripple::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:300
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116