xrpld
Loading...
Searching...
No Matches
GetCounts_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/pay.h>
6
7#include <xrpl/basics/CountedObject.h>
8#include <xrpl/beast/unit_test/suite.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/protocol/jss.h>
11
12#include <thread>
13
14namespace xrpl {
15
17{
18 void
20 {
21 using namespace test::jtx;
22 Env env(*this);
23
24 json::Value result;
25 {
26 using namespace std::chrono_literals;
27 // Add a little delay so the App's "uptime" will have a value.
29 // check counts with no transactions posted
30 result = env.rpc("get_counts")[jss::result];
31 BEAST_EXPECT(result[jss::status] == "success");
32 BEAST_EXPECT(!result.isMember("Transaction"));
33 BEAST_EXPECT(!result.isMember("STObject"));
34 BEAST_EXPECT(!result.isMember("HashRouterEntry"));
35 BEAST_EXPECT(result.isMember(jss::uptime) && !result[jss::uptime].asString().empty());
36 BEAST_EXPECT(result.isMember(jss::dbKBTotal) && result[jss::dbKBTotal].asInt() > 0);
37 }
38
39 // create some transactions
40 env.close();
41 Account const alice{"alice"};
42 Account const bob{"bob"};
43 env.fund(XRP(10000), alice, bob);
44 env.trust(alice["USD"](1000), bob);
45 for (auto i = 0; i < 20; ++i)
46 {
47 env(pay(alice, bob, alice["USD"](5)));
48 env.close();
49 }
50
51 {
52 // check counts, default params
53 result = env.rpc("get_counts")[jss::result];
54 BEAST_EXPECT(result[jss::status] == "success");
55 // compare with values reported by CountedObjects
56 auto const& objectCounts = CountedObjects::getInstance().getCounts(10);
57 for (auto const& it : objectCounts)
58 {
59 BEAST_EXPECTS(result.isMember(it.first), it.first);
60 BEAST_EXPECTS(result[it.first].asInt() == it.second, it.first);
61 }
62 BEAST_EXPECT(!result.isMember(jss::local_txs));
63 }
64
65 {
66 // make request with min threshold 100 and verify
67 // that only STObject and NodeObject are reported
68 result = env.rpc("get_counts", "100")[jss::result];
69 BEAST_EXPECT(result[jss::status] == "success");
70
71 // compare with values reported by CountedObjects
72 auto const& objectCounts = CountedObjects::getInstance().getCounts(100);
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(result.isMember(jss::local_txs) && result[jss::local_txs].asInt() > 0);
91 }
92 }
93
94public:
95 void
96 run() override
97 {
99 }
100};
101
103
104} // namespace xrpl
A testsuite class.
Definition suite.h:50
Represents a JSON value.
Definition json_value.h:130
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.
Int asInt() const
List getCounts(int minimumThreshold) const
static CountedObjects & getInstance() noexcept
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:5
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
T sleep_for(T... args)