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 ripple {
12
13namespace test {
14
15namespace validator_data {
16static auto const public_key =
17 "nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
18
19static auto const token =
20 "eyJ2YWxpZGF0aW9uX3NlY3JldF9rZXkiOiI5ZWQ0NWY4NjYyNDFjYzE4YTI3NDdiNT\n"
21 "QzODdjMDYyNTkwNzk3MmY0ZTcxOTAyMzFmYWE5Mzc0NTdmYTlkYWY2IiwibWFuaWZl\n"
22 "c3QiOiJKQUFBQUFGeEllMUZ0d21pbXZHdEgyaUNjTUpxQzlnVkZLaWxHZncxL3ZDeE\n"
23 "hYWExwbGMyR25NaEFrRTFhZ3FYeEJ3RHdEYklENk9NU1l1TTBGREFscEFnTms4U0tG\n"
24 "bjdNTzJmZGtjd1JRSWhBT25ndTlzQUtxWFlvdUorbDJWMFcrc0FPa1ZCK1pSUzZQU2\n"
25 "hsSkFmVXNYZkFpQnNWSkdlc2FhZE9KYy9hQVpva1MxdnltR21WcmxIUEtXWDNZeXd1\n"
26 "NmluOEhBU1FLUHVnQkQ2N2tNYVJGR3ZtcEFUSGxHS0pkdkRGbFdQWXk1QXFEZWRGdj\n"
27 "VUSmEydzBpMjFlcTNNWXl3TFZKWm5GT3I3QzBrdzJBaVR6U0NqSXpkaXRROD0ifQ==\n";
28} // namespace validator_data
29
31{
32public:
35 {
36 auto p = std::make_unique<Config>();
37 boost::format toLoad(R"rippleConfig(
38[validator_token]
39%1%
40
41[validators]
42%2%
43
44[port_grpc]
45ip = 0.0.0.0
46port = 50051
47
48[port_admin]
49ip = 0.0.0.0
50port = 50052
51protocol = wss2
52admin = 127.0.0.1
53)rippleConfig");
54
55 p->loadFromString(boost::str(
57
59
60 return p;
61 }
62
63 void
65 {
66 testcase("server_info");
67
68 using namespace test::jtx;
69
70 {
71 Env env(*this);
72 auto const serverinfo = env.rpc("server_info");
73 BEAST_EXPECT(serverinfo.isMember(jss::result));
74 auto const& result = serverinfo[jss::result];
75 BEAST_EXPECT(!result.isMember(jss::error));
76 BEAST_EXPECT(result[jss::status] == "success");
77 BEAST_EXPECT(result.isMember(jss::info));
78 auto const& info = result[jss::info];
79 BEAST_EXPECT(info.isMember(jss::build_version));
80 // Git info is not guaranteed to be present
81 if (info.isMember(jss::git))
82 {
83 auto const& git = info[jss::git];
84 BEAST_EXPECT(
85 git.isMember(jss::hash) || git.isMember(jss::branch));
86 BEAST_EXPECT(
87 !git.isMember(jss::hash) ||
88 (git[jss::hash].isString() &&
89 git[jss::hash].asString().size() == 40));
90 BEAST_EXPECT(
91 !git.isMember(jss::branch) ||
92 (git[jss::branch].isString() &&
93 git[jss::branch].asString().size() != 0));
94 }
95 }
96
97 {
98 Env env(*this);
99
100 // Call NetworkOPs directly and set the admin flag to false.
101 auto const result =
102 env.app().getOPs().getServerInfo(true, false, 0);
103 // Expect that the admin ports are not included in the result.
104 auto const& ports = result[jss::ports];
105 BEAST_EXPECT(ports.isArray() && ports.size() == 0);
106 // Expect that git info is absent
107 BEAST_EXPECT(!result.isMember(jss::git));
108 }
109
110 {
111 Env env(*this, makeValidatorConfig());
112 auto const& config = env.app().config();
113
114 auto const rpc_port = config["port_rpc"].get<unsigned int>("port");
115 auto const grpc_port =
116 config[SECTION_PORT_GRPC].get<unsigned int>("port");
117 auto const ws_port = config["port_ws"].get<unsigned int>("port");
118 BEAST_EXPECT(grpc_port);
119 BEAST_EXPECT(rpc_port);
120 BEAST_EXPECT(ws_port);
121
122 auto const result = env.rpc("server_info");
123 BEAST_EXPECT(!result[jss::result].isMember(jss::error));
124 BEAST_EXPECT(result[jss::result][jss::status] == "success");
125 BEAST_EXPECT(result[jss::result].isMember(jss::info));
126 BEAST_EXPECT(
127 result[jss::result][jss::info][jss::pubkey_validator] ==
129
130 auto const& ports = result[jss::result][jss::info][jss::ports];
131 BEAST_EXPECT(ports.isArray() && ports.size() == 3);
132 for (auto const& port : ports)
133 {
134 auto const& proto = port[jss::protocol];
135 BEAST_EXPECT(proto.isArray());
136 auto const p = port[jss::port].asUInt();
137 BEAST_EXPECT(p == rpc_port || p == ws_port || p == grpc_port);
138 if (p == grpc_port)
139 {
140 BEAST_EXPECT(proto.size() == 1);
141 BEAST_EXPECT(proto[0u].asString() == "grpc");
142 }
143 if (p == rpc_port)
144 {
145 BEAST_EXPECT(proto.size() == 2);
146 BEAST_EXPECT(proto[0u].asString() == "http");
147 BEAST_EXPECT(proto[1u].asString() == "ws2");
148 }
149 if (p == ws_port)
150 {
151 BEAST_EXPECT(proto.size() == 1);
152 BEAST_EXPECT(proto[0u].asString() == "ws");
153 }
154 }
155 }
156 }
157
158 void
159 run() override
160 {
162 }
163};
164
165BEAST_DEFINE_TESTSUITE(ServerInfo, rpc, ripple);
166
167} // namespace test
168} // namespace ripple
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
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:102
Application & app()
Definition Env.h:242
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
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