rippled
Loading...
Searching...
No Matches
GetCounts_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/beast/unit_test.h>
5#include <xrpl/protocol/SField.h>
6#include <xrpl/protocol/jss.h>
7
8namespace ripple {
9
11{
12 void
14 {
15 using namespace test::jtx;
16 Env env(*this);
17
18 Json::Value result;
19 {
20 using namespace std::chrono_literals;
21 // Add a little delay so the App's "uptime" will have a value.
23 // check counts with no transactions posted
24 result = env.rpc("get_counts")[jss::result];
25 BEAST_EXPECT(result[jss::status] == "success");
26 BEAST_EXPECT(!result.isMember("Transaction"));
27 BEAST_EXPECT(!result.isMember("STObject"));
28 BEAST_EXPECT(!result.isMember("HashRouterEntry"));
29 BEAST_EXPECT(
30 result.isMember(jss::uptime) &&
31 !result[jss::uptime].asString().empty());
32 BEAST_EXPECT(
33 result.isMember(jss::dbKBTotal) &&
34 result[jss::dbKBTotal].asInt() > 0);
35 }
36
37 // create some transactions
38 env.close();
39 Account alice{"alice"};
40 Account bob{"bob"};
41 env.fund(XRP(10000), alice, bob);
42 env.trust(alice["USD"](1000), bob);
43 for (auto i = 0; i < 20; ++i)
44 {
45 env(pay(alice, bob, alice["USD"](5)));
46 env.close();
47 }
48
49 {
50 // check counts, default params
51 result = env.rpc("get_counts")[jss::result];
52 BEAST_EXPECT(result[jss::status] == "success");
53 // compare with values reported by CountedObjects
54 auto const& objectCounts =
56 for (auto const& it : objectCounts)
57 {
58 BEAST_EXPECTS(result.isMember(it.first), it.first);
59 BEAST_EXPECTS(result[it.first].asInt() == it.second, it.first);
60 }
61 BEAST_EXPECT(!result.isMember(jss::local_txs));
62 }
63
64 {
65 // make request with min threshold 100 and verify
66 // that only STObject and NodeObject are reported
67 result = env.rpc("get_counts", "100")[jss::result];
68 BEAST_EXPECT(result[jss::status] == "success");
69
70 // compare with values reported by CountedObjects
71 auto const& objectCounts =
73 for (auto const& it : objectCounts)
74 {
75 BEAST_EXPECTS(result.isMember(it.first), it.first);
76 BEAST_EXPECTS(result[it.first].asInt() == it.second, it.first);
77 }
78 BEAST_EXPECT(!result.isMember("Transaction"));
79 BEAST_EXPECT(!result.isMember("STTx"));
80 BEAST_EXPECT(!result.isMember("STArray"));
81 BEAST_EXPECT(!result.isMember("HashRouterEntry"));
82 BEAST_EXPECT(!result.isMember("STLedgerEntry"));
83 }
84
85 {
86 // local_txs field will exist when there are open Txs
87 env(pay(alice, bob, alice["USD"](5)));
88 result = env.rpc("get_counts")[jss::result];
89 // deliberately don't call close so we have open Tx
90 BEAST_EXPECT(
91 result.isMember(jss::local_txs) &&
92 result[jss::local_txs].asInt() > 0);
93 }
94 }
95
96public:
97 void
98 run() override
99 {
101 }
102};
103
104BEAST_DEFINE_TESTSUITE(GetCounts, rpc, ripple);
105
106} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
Int asInt() const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
A testsuite class.
Definition suite.h:52
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:6
T sleep_for(T... args)