rippled
Loading...
Searching...
No Matches
GetCounts_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2017 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.h>
21#include <xrpl/basics/CountedObject.h>
22#include <xrpl/beast/unit_test.h>
23#include <xrpl/protocol/SField.h>
24#include <xrpl/protocol/jss.h>
25
26namespace ripple {
27
29{
30 void
32 {
33 using namespace test::jtx;
34 Env env(*this);
35
36 Json::Value result;
37 {
38 using namespace std::chrono_literals;
39 // Add a little delay so the App's "uptime" will have a value.
41 // check counts with no transactions posted
42 result = env.rpc("get_counts")[jss::result];
43 BEAST_EXPECT(result[jss::status] == "success");
44 BEAST_EXPECT(!result.isMember("Transaction"));
45 BEAST_EXPECT(!result.isMember("STObject"));
46 BEAST_EXPECT(!result.isMember("HashRouterEntry"));
47 BEAST_EXPECT(
48 result.isMember(jss::uptime) &&
49 !result[jss::uptime].asString().empty());
50 BEAST_EXPECT(
51 result.isMember(jss::dbKBTotal) &&
52 result[jss::dbKBTotal].asInt() > 0);
53 }
54
55 // create some transactions
56 env.close();
57 Account alice{"alice"};
58 Account bob{"bob"};
59 env.fund(XRP(10000), alice, bob);
60 env.trust(alice["USD"](1000), bob);
61 for (auto i = 0; i < 20; ++i)
62 {
63 env(pay(alice, bob, alice["USD"](5)));
64 env.close();
65 }
66
67 {
68 // check counts, default params
69 result = env.rpc("get_counts")[jss::result];
70 BEAST_EXPECT(result[jss::status] == "success");
71 // compare with values reported by CountedObjects
72 auto const& objectCounts =
74 for (auto const& it : objectCounts)
75 {
76 BEAST_EXPECTS(result.isMember(it.first), it.first);
77 BEAST_EXPECTS(result[it.first].asInt() == it.second, it.first);
78 }
79 BEAST_EXPECT(!result.isMember(jss::local_txs));
80 }
81
82 {
83 // make request with min threshold 100 and verify
84 // that only STObject and NodeObject are reported
85 result = env.rpc("get_counts", "100")[jss::result];
86 BEAST_EXPECT(result[jss::status] == "success");
87
88 // compare with values reported by CountedObjects
89 auto const& objectCounts =
91 for (auto const& it : objectCounts)
92 {
93 BEAST_EXPECTS(result.isMember(it.first), it.first);
94 BEAST_EXPECTS(result[it.first].asInt() == it.second, it.first);
95 }
96 BEAST_EXPECT(!result.isMember("Transaction"));
97 BEAST_EXPECT(!result.isMember("STTx"));
98 BEAST_EXPECT(!result.isMember("STArray"));
99 BEAST_EXPECT(!result.isMember("HashRouterEntry"));
100 BEAST_EXPECT(!result.isMember("STLedgerEntry"));
101 }
102
103 {
104 // local_txs field will exist when there are open Txs
105 env(pay(alice, bob, alice["USD"](5)));
106 result = env.rpc("get_counts")[jss::result];
107 // deliberately don't call close so we have open Tx
108 BEAST_EXPECT(
109 result.isMember(jss::local_txs) &&
110 result[jss::local_txs].asInt() > 0);
111 }
112 }
113
114public:
115 void
116 run() override
117 {
119 }
120};
121
122BEAST_DEFINE_TESTSUITE(GetCounts, rpc, ripple);
123
124} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
Int asInt() const
Definition: json_value.cpp:509
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:475
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:949
A testsuite class.
Definition: suite.h:55
static CountedObjects & getInstance() noexcept
List getCounts(int minimumThreshold) const
void run() override
Runs the suite.
T empty(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
T sleep_for(T... args)