3#include <xrpl/protocol/ApiVersion.h>
4#include <xrpl/protocol/jss.h>
13 testcase(
"right api_version: explicitly specified or filled by parser");
15 using namespace test::jtx;
18 auto isCorrectReply = [](
Json::Value const& re) ->
bool {
19 if (re.isMember(jss::error))
21 return re.isMember(jss::version);
27 "{\"api_version\": " +
30 BEAST_EXPECT(isCorrectReply(jrr));
32 jrr = env.rpc(
"version")[jss::result];
33 BEAST_EXPECT(isCorrectReply(jrr));
39 testcase(
"wrong api_version: too low, too high, or wrong format");
41 using namespace test::jtx;
44 auto badVersion = [](
Json::Value const& re) ->
bool {
45 if (re.isMember(
"error_what"))
46 if (re[
"error_what"].isString())
48 return re[
"error_what"].asString().find(
49 jss::invalid_API_version.c_str()) == 0;
57 "{\"api_version\": " +
59 BEAST_EXPECT(badVersion(re));
61 BEAST_EXPECT(env.app().config().BETA_RPC_API);
65 "{\"api_version\": " +
72 BEAST_EXPECT(badVersion(re));
74 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
75 BEAST_EXPECT(badVersion(re));
81 testcase(
"test getAPIVersionNumber function");
83 unsigned int versionIfUnspecified =
130 j_object[jss::api_version] =
"a";
139 testcase(
"batch, all good request");
141 using namespace test::jtx;
144 auto const without_api_verion =
std::string(
"{ ") +
145 "\"jsonrpc\": \"2.0\", "
146 "\"ripplerpc\": \"2.0\", "
148 "\"method\": \"version\", "
151 "\"jsonrpc\": \"2.0\", "
152 "\"ripplerpc\": \"2.0\", "
154 "\"method\": \"version\", "
156 "\"api_version\": " +
159 "json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
161 if (!BEAST_EXPECT(re.isArray()))
163 if (!BEAST_EXPECT(re.size() == 2))
166 re[0u].isMember(jss::result) &&
167 re[0u][jss::result].isMember(jss::version));
169 re[1u].isMember(jss::result) &&
170 re[1u][jss::result].isMember(jss::version));
176 testcase(
"batch, with a bad request");
178 using namespace test::jtx;
181 BEAST_EXPECT(env.app().config().BETA_RPC_API);
182 auto const without_api_verion =
std::string(
"{ ") +
183 "\"jsonrpc\": \"2.0\", "
184 "\"ripplerpc\": \"2.0\", "
186 "\"method\": \"version\", "
188 auto const with_wrong_api_verion =
std::string(
"{ ") +
189 "\"jsonrpc\": \"2.0\", "
190 "\"ripplerpc\": \"2.0\", "
192 "\"method\": \"version\", "
194 "\"api_version\": " +
202 '[' + without_api_verion +
", " + with_wrong_api_verion +
']');
204 if (!BEAST_EXPECT(re.isArray()))
206 if (!BEAST_EXPECT(re.size() == 2))
209 re[0u].isMember(jss::result) &&
210 re[0u][jss::result].isMember(jss::version));
211 BEAST_EXPECT(re[1u].isMember(jss::error));
239 testcase(
"test version RPC with api_version >= 2");
241 using namespace test::jtx;
243 c->loadFromString(
"\n[beta_rpc_api]\n1\n");
246 if (!BEAST_EXPECT(env.app().config().BETA_RPC_API ==
true))
255 if (!BEAST_EXPECT(jrr.isMember(jss::version)))
257 if (!BEAST_EXPECT(jrr[jss::version].isMember(jss::first)) &&
258 jrr[jss::version].isMember(jss::last))
261 jrr[jss::version][jss::first] ==
280BEAST_DEFINE_TESTSUITE(Version, rpc,
ripple);
testcase_t testcase
Memberspace for declaring test cases.
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
void testGetAPIVersionNumber()
void testCorrectVersionNumber()
void run() override
Runs the suite.
void testWrongVersionNumber()
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
static constexpr auto apiMaximumSupportedVersion
static constexpr auto apiBetaVersion
static constexpr auto apiVersionIfUnspecified
static constexpr auto apiInvalidVersion
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
static constexpr auto apiMinimumSupportedVersion
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.