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);
29 BEAST_EXPECT(isCorrectReply(jrr));
31 jrr = env.rpc(
"version")[jss::result];
32 BEAST_EXPECT(isCorrectReply(jrr));
38 testcase(
"wrong api_version: too low, too high, or wrong format");
40 using namespace test::jtx;
43 auto badVersion = [](
Json::Value const& re) ->
bool {
44 if (re.isMember(
"error_what"))
46 if (re[
"error_what"].isString())
48 return re[
"error_what"].asString().find(jss::invalid_API_version.c_str()) == 0;
58 BEAST_EXPECT(badVersion(re));
60 BEAST_EXPECT(env.app().config().BETA_RPC_API);
64 "{\"api_version\": " +
69 BEAST_EXPECT(badVersion(re));
71 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
72 BEAST_EXPECT(badVersion(re));
78 testcase(
"test getAPIVersionNumber function");
80 unsigned int const versionIfUnspecified =
111 j_object[jss::api_version] =
"a";
118 testcase(
"batch, all good request");
120 using namespace test::jtx;
123 auto const without_api_verion =
std::string(
"{ ") +
124 "\"jsonrpc\": \"2.0\", "
125 "\"ripplerpc\": \"2.0\", "
127 "\"method\": \"version\", "
130 "\"jsonrpc\": \"2.0\", "
131 "\"ripplerpc\": \"2.0\", "
133 "\"method\": \"version\", "
135 "\"api_version\": " +
137 auto re = env.rpc(
"json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
139 if (!BEAST_EXPECT(re.isArray()))
141 if (!BEAST_EXPECT(re.size() == 2))
143 BEAST_EXPECT(re[0u].isMember(jss::result) && re[0u][jss::result].isMember(jss::version));
144 BEAST_EXPECT(re[1u].isMember(jss::result) && re[1u][jss::result].isMember(jss::version));
150 testcase(
"batch, with a bad request");
152 using namespace test::jtx;
155 BEAST_EXPECT(env.app().config().BETA_RPC_API);
156 auto const without_api_verion =
std::string(
"{ ") +
157 "\"jsonrpc\": \"2.0\", "
158 "\"ripplerpc\": \"2.0\", "
160 "\"method\": \"version\", "
162 auto const with_wrong_api_verion =
164 "\"jsonrpc\": \"2.0\", "
165 "\"ripplerpc\": \"2.0\", "
167 "\"method\": \"version\", "
169 "\"api_version\": " +
173 auto re = env.rpc(
"json2",
'[' + without_api_verion +
", " + with_wrong_api_verion +
']');
175 if (!BEAST_EXPECT(re.isArray()))
177 if (!BEAST_EXPECT(re.size() == 2))
179 BEAST_EXPECT(re[0u].isMember(jss::result) && re[0u][jss::result].isMember(jss::version));
180 BEAST_EXPECT(re[1u].isMember(jss::error));
208 testcase(
"test version RPC with api_version >= 2");
210 using namespace test::jtx;
212 c->loadFromString(
"\n[beta_rpc_api]\n1\n");
215 if (!BEAST_EXPECT(env.app().config().BETA_RPC_API ==
true))
223 if (!BEAST_EXPECT(jrr.isMember(jss::version)))
225 if (!BEAST_EXPECT(jrr[jss::version].isMember(jss::first)) &&
226 jrr[jss::version].isMember(jss::last))
246BEAST_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.