rippled
Loading...
Searching...
No Matches
ServerInfo_test.cpp
1#include <test/jtx.h>
2
3#include <xrpld/core/ConfigSections.h>
4
5#include <xrpl/beast/unit_test.h>
6#include <xrpl/protocol/jss.h>
7#include <xrpl/server/NetworkOPs.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) ||
85 (git[jss::hash].isString() && git[jss::hash].asString().size() == 40));
86 BEAST_EXPECT(
87 !git.isMember(jss::branch) ||
88 (git[jss::branch].isString() && !git[jss::branch].asString().empty()));
89 }
90 }
91
92 {
93 Env env(*this);
94
95 // Call NetworkOPs directly and set the admin flag to false.
96 auto const result = env.app().getOPs().getServerInfo(true, false, false);
97 // Expect that the admin ports are not included in the result.
98 auto const& ports = result[jss::ports];
99 BEAST_EXPECT(ports.isArray() && ports.size() == 0);
100 // Expect that git info is absent
101 BEAST_EXPECT(!result.isMember(jss::git));
102 }
103
104 {
105 Env env(*this, makeValidatorConfig());
106 auto const& config = env.app().config();
107
108 auto const rpc_port = config["port_rpc"].get<unsigned int>("port");
109 auto const grpc_port = config[SECTION_PORT_GRPC].get<unsigned int>("port");
110 auto const ws_port = config["port_ws"].get<unsigned int>("port");
111 BEAST_EXPECT(grpc_port);
112 BEAST_EXPECT(rpc_port);
113 BEAST_EXPECT(ws_port);
114
115 auto const result = env.rpc("server_info");
116 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
117 BEAST_EXPECT(result[jss::result][jss::status] == "success");
118 BEAST_EXPECT(result[jss::result].isMember(jss::info));
119 BEAST_EXPECT(
120 result[jss::result][jss::info][jss::pubkey_validator] ==
122
123 auto const& ports = result[jss::result][jss::info][jss::ports];
124 BEAST_EXPECT(ports.isArray() && ports.size() == 3);
125 for (auto const& port : ports)
126 {
127 auto const& proto = port[jss::protocol];
128 BEAST_EXPECT(proto.isArray());
129 auto const p = port[jss::port].asUInt();
130 BEAST_EXPECT(p == rpc_port || p == ws_port || p == grpc_port);
131 if (p == grpc_port)
132 {
133 BEAST_EXPECT(proto.size() == 1);
134 BEAST_EXPECT(proto[0u].asString() == "grpc");
135 }
136 if (p == rpc_port)
137 {
138 BEAST_EXPECT(proto.size() == 2);
139 BEAST_EXPECT(proto[0u].asString() == "http");
140 BEAST_EXPECT(proto[1u].asString() == "ws2");
141 }
142 if (p == ws_port)
143 {
144 BEAST_EXPECT(proto.size() == 1);
145 BEAST_EXPECT(proto[0u].asString() == "ws");
146 }
147 }
148 }
149 }
150
151 void
152 run() override
153 {
155 }
156};
157
158BEAST_DEFINE_TESTSUITE(ServerInfo, rpc, xrpl);
159
160} // namespace test
161} // namespace xrpl
A testsuite class.
Definition suite.h:51
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:150
virtual Config & config()=0
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
virtual NetworkOPs & getOPs()=0
void run() override
Runs the suite.
static std::unique_ptr< Config > makeValidatorConfig()
A transaction testing environment.
Definition Env.h:122
Application & app()
Definition Env.h:259
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:847
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:15
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:5