22#include <xrpld/rpc/detail/RPCHelpers.h>
24#include <xrpl/protocol/jss.h>
33 testcase(
"right api_version: explicitly specified or filled by parser");
35 using namespace test::jtx;
38 auto isCorrectReply = [](
Json::Value const& re) ->
bool {
39 if (re.isMember(jss::error))
41 return re.isMember(jss::version);
47 "{\"api_version\": " +
50 BEAST_EXPECT(isCorrectReply(jrr));
52 jrr = env.rpc(
"version")[jss::result];
53 BEAST_EXPECT(isCorrectReply(jrr));
59 testcase(
"wrong api_version: too low, too high, or wrong format");
61 using namespace test::jtx;
64 auto badVersion = [](
Json::Value const& re) ->
bool {
65 if (re.isMember(
"error_what"))
66 if (re[
"error_what"].isString())
68 return re[
"error_what"].asString().find(
69 jss::invalid_API_version.c_str()) == 0;
77 "{\"api_version\": " +
79 BEAST_EXPECT(badVersion(re));
81 BEAST_EXPECT(env.app().config().BETA_RPC_API);
85 "{\"api_version\": " +
92 BEAST_EXPECT(badVersion(re));
94 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
95 BEAST_EXPECT(badVersion(re));
101 testcase(
"test getAPIVersionNumber function");
103 unsigned int versionIfUnspecified =
150 j_object[jss::api_version] =
"a";
159 testcase(
"batch, all good request");
161 using namespace test::jtx;
164 auto const without_api_verion =
std::string(
"{ ") +
165 "\"jsonrpc\": \"2.0\", "
166 "\"ripplerpc\": \"2.0\", "
168 "\"method\": \"version\", "
171 "\"jsonrpc\": \"2.0\", "
172 "\"ripplerpc\": \"2.0\", "
174 "\"method\": \"version\", "
176 "\"api_version\": " +
179 "json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
181 if (!BEAST_EXPECT(re.isArray()))
183 if (!BEAST_EXPECT(re.size() == 2))
186 re[0u].isMember(jss::result) &&
187 re[0u][jss::result].isMember(jss::version));
189 re[1u].isMember(jss::result) &&
190 re[1u][jss::result].isMember(jss::version));
196 testcase(
"batch, with a bad request");
198 using namespace test::jtx;
201 BEAST_EXPECT(env.app().config().BETA_RPC_API);
202 auto const without_api_verion =
std::string(
"{ ") +
203 "\"jsonrpc\": \"2.0\", "
204 "\"ripplerpc\": \"2.0\", "
206 "\"method\": \"version\", "
208 auto const with_wrong_api_verion =
std::string(
"{ ") +
209 "\"jsonrpc\": \"2.0\", "
210 "\"ripplerpc\": \"2.0\", "
212 "\"method\": \"version\", "
214 "\"api_version\": " +
222 '[' + without_api_verion +
", " + with_wrong_api_verion +
']');
224 if (!BEAST_EXPECT(re.isArray()))
226 if (!BEAST_EXPECT(re.size() == 2))
229 re[0u].isMember(jss::result) &&
230 re[0u][jss::result].isMember(jss::version));
231 BEAST_EXPECT(re[1u].isMember(jss::error));
259 testcase(
"test version RPC with api_version >= 2");
261 using namespace test::jtx;
263 c->loadFromString(
"\n[beta_rpc_api]\n1\n");
266 if (!BEAST_EXPECT(env.app().config().BETA_RPC_API ==
true))
275 if (!BEAST_EXPECT(jrr.isMember(jss::version)))
277 if (!BEAST_EXPECT(jrr[jss::version].isMember(jss::first)) &&
278 jrr[jss::version].isMember(jss::last))
281 jrr[jss::version][jss::first] ==
300BEAST_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
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
static constexpr auto apiBetaVersion
static constexpr auto apiVersionIfUnspecified
static constexpr auto apiInvalidVersion
static constexpr auto apiMinimumSupportedVersion
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.