rippled
Loading...
Searching...
No Matches
ServerDefinitions_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/beast/unit_test.h>
4#include <xrpl/protocol/jss.h>
5
6namespace ripple {
7
8namespace test {
9
11{
12public:
13 void
15 {
16 testcase("server_definitions");
17
18 using namespace test::jtx;
19
20 {
21 Env env(*this);
22 auto const result = env.rpc("server_definitions");
23 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
24 BEAST_EXPECT(result[jss::result][jss::status] == "success");
25 BEAST_EXPECT(result[jss::result].isMember(jss::FIELDS));
26 BEAST_EXPECT(result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES));
27 BEAST_EXPECT(
28 result[jss::result].isMember(jss::TRANSACTION_RESULTS));
29 BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_TYPES));
30 BEAST_EXPECT(result[jss::result].isMember(jss::TYPES));
31 BEAST_EXPECT(result[jss::result].isMember(jss::hash));
32
33 // test a random element of each result
34 // (testing the whole output would be difficult to maintain)
35
36 {
37 auto const firstField = result[jss::result][jss::FIELDS][0u];
38 BEAST_EXPECT(firstField[0u].asString() == "Generic");
39 BEAST_EXPECT(
40 firstField[1][jss::isSerialized].asBool() == false);
41 BEAST_EXPECT(
42 firstField[1][jss::isSigningField].asBool() == false);
43 BEAST_EXPECT(firstField[1][jss::isVLEncoded].asBool() == false);
44 BEAST_EXPECT(firstField[1][jss::nth].asUInt() == 0);
45 BEAST_EXPECT(firstField[1][jss::type].asString() == "Unknown");
46 }
47
48 BEAST_EXPECT(
49 result[jss::result][jss::LEDGER_ENTRY_TYPES]["AccountRoot"]
50 .asUInt() == 97);
51 BEAST_EXPECT(
52 result[jss::result][jss::TRANSACTION_RESULTS]["tecDIR_FULL"]
53 .asUInt() == 121);
54 BEAST_EXPECT(
55 result[jss::result][jss::TRANSACTION_TYPES]["Payment"]
56 .asUInt() == 0);
57 BEAST_EXPECT(
58 result[jss::result][jss::TYPES]["AccountID"].asUInt() == 8);
59
60 // check exception SFields
61 {
62 auto const fieldExists = [&](std::string name) {
63 for (auto& field : result[jss::result][jss::FIELDS])
64 {
65 if (field[0u].asString() == name)
66 {
67 return true;
68 }
69 }
70 return false;
71 };
72 BEAST_EXPECT(fieldExists("Generic"));
73 BEAST_EXPECT(fieldExists("Invalid"));
74 BEAST_EXPECT(fieldExists("ObjectEndMarker"));
75 BEAST_EXPECT(fieldExists("ArrayEndMarker"));
76 BEAST_EXPECT(fieldExists("taker_gets_funded"));
77 BEAST_EXPECT(fieldExists("taker_pays_funded"));
78 BEAST_EXPECT(fieldExists("hash"));
79 BEAST_EXPECT(fieldExists("index"));
80 }
81
82 // test that base_uint types are replaced with "Hash" prefix
83 {
84 auto const types = result[jss::result][jss::TYPES];
85 BEAST_EXPECT(types["Hash128"].asUInt() == 4);
86 BEAST_EXPECT(types["Hash160"].asUInt() == 17);
87 BEAST_EXPECT(types["Hash192"].asUInt() == 21);
88 BEAST_EXPECT(types["Hash256"].asUInt() == 5);
89 BEAST_EXPECT(types["Hash384"].asUInt() == 22);
90 BEAST_EXPECT(types["Hash512"].asUInt() == 23);
91 }
92 }
93
94 // test providing the same hash
95 {
96 Env env(*this);
97 auto const firstResult = env.rpc("server_definitions");
98 auto const hash = firstResult[jss::result][jss::hash].asString();
99 auto const hashParam =
100 std::string("{ ") + "\"hash\": \"" + hash + "\"}";
101
102 auto const result =
103 env.rpc("json", "server_definitions", hashParam);
104 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
105 BEAST_EXPECT(result[jss::result][jss::status] == "success");
106 BEAST_EXPECT(!result[jss::result].isMember(jss::FIELDS));
107 BEAST_EXPECT(
108 !result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES));
109 BEAST_EXPECT(
110 !result[jss::result].isMember(jss::TRANSACTION_RESULTS));
111 BEAST_EXPECT(!result[jss::result].isMember(jss::TRANSACTION_TYPES));
112 BEAST_EXPECT(!result[jss::result].isMember(jss::TYPES));
113 BEAST_EXPECT(result[jss::result].isMember(jss::hash));
114 }
115
116 // test providing a different hash
117 {
118 Env env(*this);
119 std::string const hash =
120 "54296160385A27154BFA70A239DD8E8FD4CC2DB7BA32D970BA3A5B132CF749"
121 "D1";
122 auto const hashParam =
123 std::string("{ ") + "\"hash\": \"" + hash + "\"}";
124
125 auto const result =
126 env.rpc("json", "server_definitions", hashParam);
127 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
128 BEAST_EXPECT(result[jss::result][jss::status] == "success");
129 BEAST_EXPECT(result[jss::result].isMember(jss::FIELDS));
130 BEAST_EXPECT(result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES));
131 BEAST_EXPECT(
132 result[jss::result].isMember(jss::TRANSACTION_RESULTS));
133 BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_TYPES));
134 BEAST_EXPECT(result[jss::result].isMember(jss::TYPES));
135 BEAST_EXPECT(result[jss::result].isMember(jss::hash));
136 }
137 }
138
139 void
140 run() override
141 {
143 }
144};
145
146BEAST_DEFINE_TESTSUITE(ServerDefinitions, rpc, ripple);
147
148} // namespace test
149} // namespace ripple
std::string asString() const
Returns the unquoted string value.
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
A transaction testing environment.
Definition Env.h:102
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:772
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:16
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6