xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
rpc
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
14
namespace
xrpl
{
15
16
class
GetCounts_test
:
public
beast::unit_test::Suite
17
{
18
void
19
testGetCounts
()
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.
28
std::this_thread::sleep_for
(1s);
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
94
public
:
95
void
96
run
()
override
97
{
98
testGetCounts
();
99
}
100
};
101
102
BEAST_DEFINE_TESTSUITE
(GetCounts,
rpc
,
xrpl
);
103
104
}
// namespace xrpl
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition
json_value.cpp:494
json::Value::isMember
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition
json_value.cpp:1049
json::Value::asInt
Int asInt() const
Definition
json_value.cpp:530
xrpl::CountedObjects::getCounts
List getCounts(int minimumThreshold) const
Definition
CountedObject.cpp:20
xrpl::CountedObjects::getInstance
static CountedObjects & getInstance() noexcept
Definition
CountedObject.cpp:8
xrpl::GetCounts_test
Definition
GetCounts_test.cpp:17
xrpl::GetCounts_test::run
void run() override
Runs the suite.
Definition
GetCounts_test.cpp:96
xrpl::GetCounts_test::testGetCounts
void testGetCounts()
Definition
GetCounts_test.cpp:19
std::string::empty
T empty(T... args)
xrpl::rpc
API version numbers used in later API versions.
Definition
ApiVersion.h:36
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::FeePayerType::Account
@ Account
Definition
Transactor.h:145
xrpl::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
std::this_thread::sleep_for
T sleep_for(T... args)
thread
Generated by
1.17.0