21#include <xrpld/rpc/detail/RPCHelpers.h>
22#include <xrpl/protocol/jss.h>
31 testcase(
"right api_version: explicitly specified or filled by parser");
33 using namespace test::jtx;
36 auto isCorrectReply = [](
Json::Value const& re) ->
bool {
37 if (re.isMember(jss::error))
39 return re.isMember(jss::version);
45 "{\"api_version\": " +
48 BEAST_EXPECT(isCorrectReply(jrr));
50 jrr = env.rpc(
"version")[jss::result];
51 BEAST_EXPECT(isCorrectReply(jrr));
57 testcase(
"wrong api_version: too low, too high, or wrong format");
59 using namespace test::jtx;
62 auto badVersion = [](
Json::Value const& re) ->
bool {
63 if (re.isMember(
"error_what"))
64 if (re[
"error_what"].isString())
66 return re[
"error_what"].asString().find(
67 jss::invalid_API_version.c_str()) == 0;
75 "{\"api_version\": " +
77 BEAST_EXPECT(badVersion(re));
79 BEAST_EXPECT(env.app().config().BETA_RPC_API);
83 "{\"api_version\": " +
90 BEAST_EXPECT(badVersion(re));
92 re = env.rpc(
"json",
"version",
"{\"api_version\": \"a\"}");
93 BEAST_EXPECT(badVersion(re));
99 testcase(
"test getAPIVersionNumber function");
101 unsigned int versionIfUnspecified =
148 j_object[jss::api_version] =
"a";
157 testcase(
"batch, all good request");
159 using namespace test::jtx;
162 auto const without_api_verion =
std::string(
"{ ") +
163 "\"jsonrpc\": \"2.0\", "
164 "\"ripplerpc\": \"2.0\", "
166 "\"method\": \"version\", "
169 "\"jsonrpc\": \"2.0\", "
170 "\"ripplerpc\": \"2.0\", "
172 "\"method\": \"version\", "
174 "\"api_version\": " +
177 "json2",
'[' + without_api_verion +
", " + with_api_verion +
']');
179 if (!BEAST_EXPECT(re.isArray()))
181 if (!BEAST_EXPECT(re.size() == 2))
184 re[0u].isMember(jss::result) &&
185 re[0u][jss::result].isMember(jss::version));
187 re[1u].isMember(jss::result) &&
188 re[1u][jss::result].isMember(jss::version));
194 testcase(
"batch, with a bad request");
196 using namespace test::jtx;
199 BEAST_EXPECT(env.app().config().BETA_RPC_API);
200 auto const without_api_verion =
std::string(
"{ ") +
201 "\"jsonrpc\": \"2.0\", "
202 "\"ripplerpc\": \"2.0\", "
204 "\"method\": \"version\", "
206 auto const with_wrong_api_verion =
std::string(
"{ ") +
207 "\"jsonrpc\": \"2.0\", "
208 "\"ripplerpc\": \"2.0\", "
210 "\"method\": \"version\", "
212 "\"api_version\": " +
220 '[' + without_api_verion +
", " + with_wrong_api_verion +
']');
222 if (!BEAST_EXPECT(re.isArray()))
224 if (!BEAST_EXPECT(re.size() == 2))
227 re[0u].isMember(jss::result) &&
228 re[0u][jss::result].isMember(jss::version));
229 BEAST_EXPECT(re[1u].isMember(jss::error));
257 testcase(
"test version RPC with api_version >= 2");
259 using namespace test::jtx;
261 c->loadFromString(
"\n[beta_rpc_api]\n1\n");
264 if (!BEAST_EXPECT(env.app().config().BETA_RPC_API ==
true))
273 if (!BEAST_EXPECT(jrr.isMember(jss::version)))
275 if (!BEAST_EXPECT(jrr[jss::version].isMember(jss::first)) &&
276 jrr[jss::version].isMember(jss::last))
279 jrr[jss::version][jss::first] ==
298BEAST_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).
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
static constexpr auto apiMaximumSupportedVersion
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.