rippled
Loading...
Searching...
No Matches
ServerInfo_test.cpp
1#include <test/jtx.h>
2
3#include <xrpld/app/misc/NetworkOPs.h>
4#include <xrpld/core/ConfigSections.h>
5
6#include <xrpl/beast/unit_test.h>
7#include <xrpl/protocol/jss.h>
8
9#include <boost/format.hpp>
10
11namespace xrpl {
12
13namespace test {
14
15namespace validator_data {
16static auto const public_key = "nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
17
18static auto const token =
19 "eyJ2YWxpZGF0aW9uX3NlY3JldF9rZXkiOiI5ZWQ0NWY4NjYyNDFjYzE4YTI3NDdiNT\n"
20 "QzODdjMDYyNTkwNzk3MmY0ZTcxOTAyMzFmYWE5Mzc0NTdmYTlkYWY2IiwibWFuaWZl\n"
21 "c3QiOiJKQUFBQUFGeEllMUZ0d21pbXZHdEgyaUNjTUpxQzlnVkZLaWxHZncxL3ZDeE\n"
22 "hYWExwbGMyR25NaEFrRTFhZ3FYeEJ3RHdEYklENk9NU1l1TTBGREFscEFnTms4U0tG\n"
23 "bjdNTzJmZGtjd1JRSWhBT25ndTlzQUtxWFlvdUorbDJWMFcrc0FPa1ZCK1pSUzZQU2\n"
24 "hsSkFmVXNYZkFpQnNWSkdlc2FhZE9KYy9hQVpva1MxdnltR21WcmxIUEtXWDNZeXd1\n"
25 "NmluOEhBU1FLUHVnQkQ2N2tNYVJGR3ZtcEFUSGxHS0pkdkRGbFdQWXk1QXFEZWRGdj\n"
26 "VUSmEydzBpMjFlcTNNWXl3TFZKWm5GT3I3QzBrdzJBaVR6U0NqSXpkaXRROD0ifQ==\n";
27} // namespace validator_data
28
30{
31public:
34 {
35 auto p = std::make_unique<Config>();
36 boost::format toLoad(R"rippleConfig(
37[validator_token]
38%1%
39
40[validators]
41%2%
42
43[port_grpc]
44ip = 0.0.0.0
45port = 50051
46
47[port_admin]
48ip = 0.0.0.0
49port = 50052
50protocol = wss2
51admin = 127.0.0.1
52)rippleConfig");
53
54 p->loadFromString(boost::str(toLoad % validator_data::token % validator_data::public_key));
55
57
58 return p;
59 }
60
61 void
63 {
64 testcase("server_info");
65
66 using namespace test::jtx;
67
68 {
69 Env env(*this);
70 auto const serverinfo = env.rpc("server_info");
71 BEAST_EXPECT(serverinfo.isMember(jss::result));
72 auto const& result = serverinfo[jss::result];
73 BEAST_EXPECT(!result.isMember(jss::error));
74 BEAST_EXPECT(result[jss::status] == "success");
75 BEAST_EXPECT(result.isMember(jss::info));
76 auto const& info = result[jss::info];
77 BEAST_EXPECT(info.isMember(jss::build_version));
78 // Git info is not guaranteed to be present
79 if (info.isMember(jss::git))
80 {
81 auto const& git = info[jss::git];
82 BEAST_EXPECT(git.isMember(jss::hash) || git.isMember(jss::branch));
83 BEAST_EXPECT(
84 !git.isMember(jss::hash) || (git[jss::hash].isString() && git[jss::hash].asString().size() == 40));
85 BEAST_EXPECT(
86 !git.isMember(jss::branch) ||
87 (git[jss::branch].isString() && git[jss::branch].asString().size() != 0));
88 }
89 }
90
91 {
92 Env env(*this);
93
94 // Call NetworkOPs directly and set the admin flag to false.
95 auto const result = env.app().getOPs().getServerInfo(true, false, 0);
96 // Expect that the admin ports are not included in the result.
97 auto const& ports = result[jss::ports];
98 BEAST_EXPECT(ports.isArray() && ports.size() == 0);
99 // Expect that git info is absent
100 BEAST_EXPECT(!result.isMember(jss::git));
101 }
102
103 {
104 Env env(*this, makeValidatorConfig());
105 auto const& config = env.app().config();
106
107 auto const rpc_port = config["port_rpc"].get<unsigned int>("port");
108 auto const grpc_port = config[SECTION_PORT_GRPC].get<unsigned int>("port");
109 auto const ws_port = config["port_ws"].get<unsigned int>("port");
110 BEAST_EXPECT(grpc_port);
111 BEAST_EXPECT(rpc_port);
112 BEAST_EXPECT(ws_port);
113
114 auto const result = env.rpc("server_info");
115 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
116 BEAST_EXPECT(result[jss::result][jss::status] == "success");
117 BEAST_EXPECT(result[jss::result].isMember(jss::info));
118 BEAST_EXPECT(result[jss::result][jss::info][jss::pubkey_validator] == validator_data::public_key);
119
120 auto const& ports = result[jss::result][jss::info][jss::ports];
121 BEAST_EXPECT(ports.isArray() && ports.size() == 3);
122 for (auto const& port : ports)
123 {
124 auto const& proto = port[jss::protocol];
125 BEAST_EXPECT(proto.isArray());
126 auto const p = port[jss::port].asUInt();
127 BEAST_EXPECT(p == rpc_port || p == ws_port || p == grpc_port);
128 if (p == grpc_port)
129 {
130 BEAST_EXPECT(proto.size() == 1);
131 BEAST_EXPECT(proto[0u].asString() == "grpc");
132 }
133 if (p == rpc_port)
134 {
135 BEAST_EXPECT(proto.size() == 2);
136 BEAST_EXPECT(proto[0u].asString() == "http");
137 BEAST_EXPECT(proto[1u].asString() == "ws2");
138 }
139 if (p == ws_port)
140 {
141 BEAST_EXPECT(proto.size() == 1);
142 BEAST_EXPECT(proto[0u].asString() == "ws");
143 }
144 }
145 }
146 }
147
148 void
149 run() override
150 {
152 }
153};
154
155BEAST_DEFINE_TESTSUITE(ServerInfo, rpc, xrpl);
156
157} // namespace test
158} // namespace xrpl
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:148
virtual Config & config()=0
virtual NetworkOPs & getOPs()=0
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
void run() override
Runs the suite.
static std::unique_ptr< Config > makeValidatorConfig()
A transaction testing environment.
Definition Env.h:98
Application & app()
Definition Env.h:230
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
T is_same_v
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition envconfig.cpp:12
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6