22#include <xrpl/protocol/ApiVersion.h>
23#include <xrpl/protocol/jss.h>
32 testcase(
"right api_version: explicitly specified or filled by parser");
34 using namespace test::jtx;
37 auto isCorrectReply = [](
Json::Value const& re) ->
bool {
38 if (re.isMember(jss::error))
40 return re.isMember(jss::version);
46 "{\"api_version\": " +
49 BEAST_EXPECT(isCorrectReply(jrr));
51 jrr = env.rpc(
"version")[jss::result];
52 BEAST_EXPECT(isCorrectReply(jrr));
58 testcase(
"wrong api_version: too low, too high, or wrong format");
60 using namespace test::jtx;
63 auto badVersion = [](
Json::Value const& re) ->
bool {
64 if (re.isMember(
"error_what"))
65 if (re[
"error_what"].isString())
67 return re[
"error_what"].asString().find(
68 jss::invalid_API_version.c_str()) == 0;
76 "{\"api_version\": " +
78 BEAST_EXPECT(badVersion(re));
80 BEAST_EXPECT(env.app().config().BETA_RPC_API);
84 "{\"api_version\": " +
91 BEAST_EXPECT(badVersion(re));
93 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
94 BEAST_EXPECT(badVersion(re));
100 testcase(
"test getAPIVersionNumber function");
102 unsigned int versionIfUnspecified =
149 j_object[jss::api_version] =
"a";
158 testcase(
"batch, all good request");
160 using namespace test::jtx;
163 auto const without_api_verion =
std::string(
"{ ") +
164 "\"jsonrpc\": \"2.0\", "
165 "\"ripplerpc\": \"2.0\", "
167 "\"method\": \"version\", "
170 "\"jsonrpc\": \"2.0\", "
171 "\"ripplerpc\": \"2.0\", "
173 "\"method\": \"version\", "
175 "\"api_version\": " +
178 "json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
180 if (!BEAST_EXPECT(re.isArray()))
182 if (!BEAST_EXPECT(re.size() == 2))
185 re[0u].isMember(jss::result) &&
186 re[0u][jss::result].isMember(jss::version));
188 re[1u].isMember(jss::result) &&
189 re[1u][jss::result].isMember(jss::version));
195 testcase(
"batch, with a bad request");
197 using namespace test::jtx;
200 BEAST_EXPECT(env.app().config().BETA_RPC_API);
201 auto const without_api_verion =
std::string(
"{ ") +
202 "\"jsonrpc\": \"2.0\", "
203 "\"ripplerpc\": \"2.0\", "
205 "\"method\": \"version\", "
207 auto const with_wrong_api_verion =
std::string(
"{ ") +
208 "\"jsonrpc\": \"2.0\", "
209 "\"ripplerpc\": \"2.0\", "
211 "\"method\": \"version\", "
213 "\"api_version\": " +
221 '[' + without_api_verion +
", " + with_wrong_api_verion +
']');
223 if (!BEAST_EXPECT(re.isArray()))
225 if (!BEAST_EXPECT(re.size() == 2))
228 re[0u].isMember(jss::result) &&
229 re[0u][jss::result].isMember(jss::version));
230 BEAST_EXPECT(re[1u].isMember(jss::error));
258 testcase(
"test version RPC with api_version >= 2");
260 using namespace test::jtx;
262 c->loadFromString(
"\n[beta_rpc_api]\n1\n");
265 if (!BEAST_EXPECT(env.app().config().BETA_RPC_API ==
true))
274 if (!BEAST_EXPECT(jrr.isMember(jss::version)))
276 if (!BEAST_EXPECT(jrr[jss::version].isMember(jss::first)) &&
277 jrr[jss::version].isMember(jss::last))
280 jrr[jss::version][jss::first] ==
299BEAST_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.