20 #include <ripple/protocol/jss.h>
21 #include <ripple/rpc/impl/RPCHelpers.h>
31 testcase(
"right api_version: explicitly specified or filled by parser");
33 using namespace test::jtx;
36 auto isCorrectReply = [](
Json::Value const& re) ->
bool {
37 if (re.isMember(jss::error))
39 return re.isMember(jss::version);
45 "{\"api_version\": " +
48 BEAST_EXPECT(isCorrectReply(jrr));
50 jrr = env.rpc(
"version")[jss::result];
51 BEAST_EXPECT(isCorrectReply(jrr));
57 testcase(
"wrong api_version: too low, too high, or wrong format");
59 using namespace test::jtx;
63 if (re.isMember(
"error_what"))
64 if (re[
"error_what"].isString())
65 return re[
"error_what"].asString();
72 "{\"api_version\": " +
74 BEAST_EXPECT(get_error_what(re).find(jss::invalid_API_version.c_str()));
79 "{\"api_version\": " +
81 BEAST_EXPECT(get_error_what(re).find(jss::invalid_API_version.c_str()));
83 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
84 BEAST_EXPECT(get_error_what(re).find(jss::invalid_API_version.c_str()));
90 testcase(
"test getAPIVersionNumber function");
92 unsigned int versionIfUnspecified =
128 j_object[jss::api_version] =
"a";
136 testcase(
"batch, all good request");
138 using namespace test::jtx;
141 auto const without_api_verion =
std::string(
"{ ") +
142 "\"jsonrpc\": \"2.0\", "
143 "\"ripplerpc\": \"2.0\", "
145 "\"method\": \"version\", "
148 "\"jsonrpc\": \"2.0\", "
149 "\"ripplerpc\": \"2.0\", "
151 "\"method\": \"version\", "
153 "\"api_version\": " +
156 "json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
158 if (!BEAST_EXPECT(re.isArray()))
160 if (!BEAST_EXPECT(re.size() == 2))
163 re[0u].isMember(jss::result) &&
164 re[0u][jss::result].isMember(jss::version));
166 re[1u].isMember(jss::result) &&
167 re[1u][jss::result].isMember(jss::version));
173 testcase(
"batch, with a bad request");
175 using namespace test::jtx;
178 auto const without_api_verion =
std::string(
"{ ") +
179 "\"jsonrpc\": \"2.0\", "
180 "\"ripplerpc\": \"2.0\", "
182 "\"method\": \"version\", "
184 auto const with_wrong_api_verion =
std::string(
"{ ") +
185 "\"jsonrpc\": \"2.0\", "
186 "\"ripplerpc\": \"2.0\", "
188 "\"method\": \"version\", "
190 "\"api_version\": " +
194 '[' + without_api_verion +
", " + with_wrong_api_verion +
']');
196 if (!BEAST_EXPECT(re.isArray()))
198 if (!BEAST_EXPECT(re.size() == 2))
201 re[0u].isMember(jss::result) &&
202 re[0u][jss::result].isMember(jss::version));
203 BEAST_EXPECT(re[1u].isMember(jss::error));