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);
28 BEAST_EXPECT(isCorrectReply(jrr));
30 jrr = env.rpc(
"version")[jss::result];
31 BEAST_EXPECT(isCorrectReply(jrr));
37 testcase(
"wrong api_version: too low, too high, or wrong format");
39 using namespace test::jtx;
42 auto badVersion = [](
Json::Value const& re) ->
bool {
43 if (re.isMember(
"error_what"))
44 if (re[
"error_what"].isString())
46 return re[
"error_what"].asString().find(jss::invalid_API_version.c_str()) == 0;
53 BEAST_EXPECT(badVersion(re));
55 BEAST_EXPECT(env.app().config().BETA_RPC_API);
59 "{\"api_version\": " +
61 BEAST_EXPECT(badVersion(re));
63 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
64 BEAST_EXPECT(badVersion(re));
70 testcase(
"test getAPIVersionNumber function");
102 j_object[jss::api_version] =
"a";
109 testcase(
"batch, all good request");
111 using namespace test::jtx;
114 auto const without_api_verion =
std::string(
"{ ") +
115 "\"jsonrpc\": \"2.0\", "
116 "\"ripplerpc\": \"2.0\", "
118 "\"method\": \"version\", "
121 "\"jsonrpc\": \"2.0\", "
122 "\"ripplerpc\": \"2.0\", "
124 "\"method\": \"version\", "
126 "\"api_version\": " +
128 auto re = env.rpc(
"json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
130 if (!BEAST_EXPECT(re.isArray()))
132 if (!BEAST_EXPECT(re.size() == 2))
134 BEAST_EXPECT(re[0u].isMember(jss::result) && re[0u][jss::result].isMember(jss::version));
135 BEAST_EXPECT(re[1u].isMember(jss::result) && re[1u][jss::result].isMember(jss::version));
141 testcase(
"batch, with a bad request");
143 using namespace test::jtx;
146 BEAST_EXPECT(env.app().config().BETA_RPC_API);
147 auto const without_api_verion =
std::string(
"{ ") +
148 "\"jsonrpc\": \"2.0\", "
149 "\"ripplerpc\": \"2.0\", "
151 "\"method\": \"version\", "
153 auto const with_wrong_api_verion =
std::string(
"{ ") +
154 "\"jsonrpc\": \"2.0\", "
155 "\"ripplerpc\": \"2.0\", "
157 "\"method\": \"version\", "
159 "\"api_version\": " +
161 auto re = env.rpc(
"json2",
'[' + without_api_verion +
", " + with_wrong_api_verion +
']');
163 if (!BEAST_EXPECT(re.isArray()))
165 if (!BEAST_EXPECT(re.size() == 2))
167 BEAST_EXPECT(re[0u].isMember(jss::result) && re[0u][jss::result].isMember(jss::version));
168 BEAST_EXPECT(re[1u].isMember(jss::error));
196 testcase(
"test version RPC with api_version >= 2");
198 using namespace test::jtx;
200 c->loadFromString(
"\n[beta_rpc_api]\n1\n");
203 if (!BEAST_EXPECT(env.app().config().BETA_RPC_API ==
true))
209 if (!BEAST_EXPECT(jrr.isMember(jss::version)))
211 if (!BEAST_EXPECT(jrr[jss::version].isMember(jss::first)) && jrr[jss::version].isMember(jss::last))
231BEAST_DEFINE_TESTSUITE(Version, rpc,
xrpl);
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 apiBetaVersion
static constexpr auto apiInvalidVersion
static constexpr auto apiMinimumSupportedVersion
static constexpr auto apiMaximumSupportedVersion
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
static constexpr auto apiVersionIfUnspecified
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.