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 xrpl {
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(result[jss::result].isMember(jss::TRANSACTION_RESULTS));
28 BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_TYPES));
29 BEAST_EXPECT(result[jss::result].isMember(jss::TYPES));
30 BEAST_EXPECT(result[jss::result].isMember(jss::hash));
31
32 // test a random element of each result
33 // (testing the whole output would be difficult to maintain)
34
35 {
36 auto const firstField = result[jss::result][jss::FIELDS][0u];
37 BEAST_EXPECT(firstField[0u].asString() == "Generic");
38 BEAST_EXPECT(firstField[1][jss::isSerialized].asBool() == false);
39 BEAST_EXPECT(firstField[1][jss::isSigningField].asBool() == false);
40 BEAST_EXPECT(firstField[1][jss::isVLEncoded].asBool() == false);
41 BEAST_EXPECT(firstField[1][jss::nth].asUInt() == 0);
42 BEAST_EXPECT(firstField[1][jss::type].asString() == "Unknown");
43 }
44
45 BEAST_EXPECT(result[jss::result][jss::LEDGER_ENTRY_TYPES]["AccountRoot"].asUInt() == 97);
46 BEAST_EXPECT(result[jss::result][jss::TRANSACTION_RESULTS]["tecDIR_FULL"].asUInt() == 121);
47 BEAST_EXPECT(result[jss::result][jss::TRANSACTION_TYPES]["Payment"].asUInt() == 0);
48 BEAST_EXPECT(result[jss::result][jss::TYPES]["AccountID"].asUInt() == 8);
49
50 // check exception SFields
51 {
52 auto const fieldExists = [&](std::string name) {
53 for (auto& field : result[jss::result][jss::FIELDS])
54 {
55 if (field[0u].asString() == name)
56 {
57 return true;
58 }
59 }
60 return false;
61 };
62 BEAST_EXPECT(fieldExists("Generic"));
63 BEAST_EXPECT(fieldExists("Invalid"));
64 BEAST_EXPECT(fieldExists("ObjectEndMarker"));
65 BEAST_EXPECT(fieldExists("ArrayEndMarker"));
66 BEAST_EXPECT(fieldExists("taker_gets_funded"));
67 BEAST_EXPECT(fieldExists("taker_pays_funded"));
68 BEAST_EXPECT(fieldExists("hash"));
69 BEAST_EXPECT(fieldExists("index"));
70 }
71
72 // test that base_uint types are replaced with "Hash" prefix
73 {
74 auto const types = result[jss::result][jss::TYPES];
75 BEAST_EXPECT(types["Hash128"].asUInt() == 4);
76 BEAST_EXPECT(types["Hash160"].asUInt() == 17);
77 BEAST_EXPECT(types["Hash192"].asUInt() == 21);
78 BEAST_EXPECT(types["Hash256"].asUInt() == 5);
79 BEAST_EXPECT(types["Hash384"].asUInt() == 22);
80 BEAST_EXPECT(types["Hash512"].asUInt() == 23);
81 }
82 }
83
84 // test providing the same hash
85 {
86 Env env(*this);
87 auto const firstResult = env.rpc("server_definitions");
88 auto const hash = firstResult[jss::result][jss::hash].asString();
89 auto const hashParam = std::string("{ ") + "\"hash\": \"" + hash + "\"}";
90
91 auto const result = env.rpc("json", "server_definitions", hashParam);
92 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
93 BEAST_EXPECT(result[jss::result][jss::status] == "success");
94 BEAST_EXPECT(!result[jss::result].isMember(jss::FIELDS));
95 BEAST_EXPECT(!result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES));
96 BEAST_EXPECT(!result[jss::result].isMember(jss::TRANSACTION_RESULTS));
97 BEAST_EXPECT(!result[jss::result].isMember(jss::TRANSACTION_TYPES));
98 BEAST_EXPECT(!result[jss::result].isMember(jss::TYPES));
99 BEAST_EXPECT(result[jss::result].isMember(jss::hash));
100 }
101
102 // test providing a different hash
103 {
104 Env env(*this);
105 std::string const hash =
106 "54296160385A27154BFA70A239DD8E8FD4CC2DB7BA32D970BA3A5B132CF749"
107 "D1";
108 auto const hashParam = std::string("{ ") + "\"hash\": \"" + hash + "\"}";
109
110 auto const result = env.rpc("json", "server_definitions", hashParam);
111 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
112 BEAST_EXPECT(result[jss::result][jss::status] == "success");
113 BEAST_EXPECT(result[jss::result].isMember(jss::FIELDS));
114 BEAST_EXPECT(result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES));
115 BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_RESULTS));
116 BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_TYPES));
117 BEAST_EXPECT(result[jss::result].isMember(jss::TYPES));
118 BEAST_EXPECT(result[jss::result].isMember(jss::hash));
119 }
120 }
121
122 void
123 run() override
124 {
126 }
127};
128
129BEAST_DEFINE_TESTSUITE(ServerDefinitions, rpc, xrpl);
130
131} // namespace test
132} // namespace xrpl
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:148
A transaction testing environment.
Definition Env.h:98
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:749
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