mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improve error handling in some RPC commands
This commit is contained in:
committed by
Ed Hennis
parent
2df635693d
commit
eba5d19377
@@ -873,6 +873,25 @@ struct PayChan_test : public beast::unit_test::suite
|
||||
auto const chan1Str = to_string(channel(alice, bob, env.seq(alice)));
|
||||
env(create(alice, bob, channelFunds, settleDelay, pk));
|
||||
env.close();
|
||||
{
|
||||
// test account non-string
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_channels", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
{
|
||||
auto const r =
|
||||
env.rpc("account_channels", alice.human(), bob.human());
|
||||
|
||||
@@ -39,6 +39,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
|
||||
|
||||
{ // invalid ledger (hash)
|
||||
Json::Value params;
|
||||
params[jss::account] = Account{"bob"}.human();
|
||||
params[jss::ledger_hash] = 1;
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
@@ -56,6 +57,50 @@ class AccountCurrencies_test : public beast::unit_test::suite
|
||||
result[jss::error_message] == "Missing field 'account'.");
|
||||
}
|
||||
|
||||
{
|
||||
// test account non-string
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json",
|
||||
"account_currencies",
|
||||
to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
|
||||
{
|
||||
// test ident non-string
|
||||
auto testInvalidIdentParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::ident] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json",
|
||||
"account_currencies",
|
||||
to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'ident'.");
|
||||
};
|
||||
|
||||
testInvalidIdentParam(1);
|
||||
testInvalidIdentParam(1.1);
|
||||
testInvalidIdentParam(true);
|
||||
testInvalidIdentParam(Json::Value(Json::nullValue));
|
||||
testInvalidIdentParam(Json::Value(Json::objectValue));
|
||||
testInvalidIdentParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
|
||||
{
|
||||
Json::Value params;
|
||||
params[jss::account] =
|
||||
@@ -198,6 +243,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(AccountCurrencies, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(AccountCurrencies, rpc, ripple);
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
void
|
||||
testErrors()
|
||||
{
|
||||
testcase("Errors");
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
{
|
||||
@@ -78,12 +79,53 @@ public:
|
||||
BEAST_EXPECT(
|
||||
info[jss::result][jss::error_message] == "Account malformed.");
|
||||
}
|
||||
{
|
||||
// Cannot pass a non-string into the `account` param
|
||||
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_info", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
{
|
||||
// Cannot pass a non-string into the `ident` param
|
||||
|
||||
auto testInvalidIdentParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::ident] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_info", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'ident'.");
|
||||
};
|
||||
|
||||
testInvalidIdentParam(1);
|
||||
testInvalidIdentParam(1.1);
|
||||
testInvalidIdentParam(true);
|
||||
testInvalidIdentParam(Json::Value(Json::nullValue));
|
||||
testInvalidIdentParam(Json::Value(Json::objectValue));
|
||||
testInvalidIdentParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
}
|
||||
|
||||
// Test the "signer_lists" argument in account_info.
|
||||
void
|
||||
testSignerLists()
|
||||
{
|
||||
testcase("Signer lists");
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
Account const alice{"alice"};
|
||||
@@ -205,6 +247,7 @@ public:
|
||||
void
|
||||
testSignerListsApiVersion2()
|
||||
{
|
||||
testcase("Signer lists APIv2");
|
||||
using namespace jtx;
|
||||
Env env{*this};
|
||||
Account const alice{"alice"};
|
||||
@@ -326,6 +369,7 @@ public:
|
||||
void
|
||||
testSignerListsV2()
|
||||
{
|
||||
testcase("Signer lists v2");
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
Account const alice{"alice"};
|
||||
@@ -515,6 +559,7 @@ public:
|
||||
void
|
||||
testAccountFlags(FeatureBitset const& features)
|
||||
{
|
||||
testcase("Account flags");
|
||||
using namespace jtx;
|
||||
|
||||
Env env(*this, features);
|
||||
@@ -652,7 +697,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(AccountInfo, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(AccountInfo, rpc, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ripple {
|
||||
|
||||
namespace RPC {
|
||||
|
||||
class AccountLinesRPC_test : public beast::unit_test::suite
|
||||
class AccountLines_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
@@ -55,6 +55,25 @@ public:
|
||||
lines[jss::result][jss::error_message] ==
|
||||
RPC::make_error(rpcACT_MALFORMED)[jss::error_message]);
|
||||
}
|
||||
{
|
||||
// test account non-string
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_lines", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
Account const alice{"alice"};
|
||||
{
|
||||
// account_lines on an unfunded account.
|
||||
@@ -1474,7 +1493,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(AccountLinesRPC, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(AccountLines, rpc, ripple);
|
||||
|
||||
} // namespace RPC
|
||||
} // namespace ripple
|
||||
@@ -123,8 +123,30 @@ public:
|
||||
|
||||
// test error on no account
|
||||
{
|
||||
auto resp = env.rpc("json", "account_objects");
|
||||
BEAST_EXPECT(resp[jss::error_message] == "Syntax error.");
|
||||
Json::Value params;
|
||||
auto resp = env.rpc("json", "account_objects", to_string(params));
|
||||
BEAST_EXPECT(
|
||||
resp[jss::result][jss::error_message] ==
|
||||
"Missing field 'account'.");
|
||||
}
|
||||
// test account non-string
|
||||
{
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_objects", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
// test error on malformed account string.
|
||||
{
|
||||
@@ -1032,6 +1054,35 @@ public:
|
||||
BEAST_EXPECT(acct_objs_is_size(acct_objs(gw, jss::hashes), 0));
|
||||
}
|
||||
|
||||
void
|
||||
testAccountNFTs()
|
||||
{
|
||||
testcase("account_nfts");
|
||||
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
|
||||
// test validation
|
||||
{
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_nfts", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@@ -1039,10 +1090,11 @@ public:
|
||||
testUnsteppedThenStepped();
|
||||
testUnsteppedThenSteppedWithNFTs();
|
||||
testObjectTypes();
|
||||
testAccountNFTs();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(AccountObjects, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(AccountObjects, rpc, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
void
|
||||
testNonAdminMinLimit()
|
||||
{
|
||||
testcase("Non-Admin Min Limit");
|
||||
|
||||
using namespace jtx;
|
||||
Env env{*this, envconfig(no_admin)};
|
||||
Account const gw("G1");
|
||||
@@ -81,6 +83,9 @@ public:
|
||||
void
|
||||
testSequential(bool asAdmin)
|
||||
{
|
||||
testcase(
|
||||
std::string("Sequential - ") + (asAdmin ? "admin" : "non-admin"));
|
||||
|
||||
using namespace jtx;
|
||||
Env env{*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||
Account const gw("G1");
|
||||
@@ -215,6 +220,8 @@ public:
|
||||
void
|
||||
testBadInput()
|
||||
{
|
||||
testcase("Bad input");
|
||||
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
Account const gw("G1");
|
||||
@@ -233,6 +240,26 @@ public:
|
||||
BEAST_EXPECT(jrr[jss::error_message] == "Syntax error.");
|
||||
}
|
||||
|
||||
{
|
||||
// test account non-string
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_offers", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
|
||||
{
|
||||
// empty string account
|
||||
Json::Value jvParams;
|
||||
@@ -282,7 +309,9 @@ public:
|
||||
jvParams.toStyledString())[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(jrr[jss::status] == "error");
|
||||
BEAST_EXPECT(jrr[jss::error_message] == "Invalid parameters.");
|
||||
BEAST_EXPECTS(
|
||||
jrr[jss::error_message] == "Invalid field 'marker'.",
|
||||
jrr.toStyledString());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -326,7 +355,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(AccountOffers, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(AccountOffers, rpc, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -109,6 +109,7 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
void
|
||||
testParameters(unsigned int apiVersion)
|
||||
{
|
||||
testcase("Parameters APIv" + std::to_string(apiVersion));
|
||||
using namespace test::jtx;
|
||||
|
||||
Env env(*this);
|
||||
@@ -353,6 +354,25 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcLGR_IDX_MALFORMED));
|
||||
}
|
||||
// test account non-string
|
||||
{
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
auto jrr = env.rpc(
|
||||
"json", "account_tx", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
// test binary and forward for bool/non bool values
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
@@ -388,6 +408,8 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
void
|
||||
testContents()
|
||||
{
|
||||
testcase("Contents");
|
||||
|
||||
// Get results for all transaction types that can be associated
|
||||
// with an account. Start by generating all transaction types.
|
||||
using namespace test::jtx;
|
||||
@@ -600,6 +622,8 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
void
|
||||
testAccountDelete()
|
||||
{
|
||||
testcase("AccountDelete");
|
||||
|
||||
// Verify that if an account is resurrected then the account_tx RPC
|
||||
// command still recovers all transactions on that account before
|
||||
// and after resurrection.
|
||||
@@ -740,7 +764,7 @@ public:
|
||||
testAccountDelete();
|
||||
}
|
||||
};
|
||||
BEAST_DEFINE_TESTSUITE(AccountTx, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(AccountTx, rpc, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -64,6 +64,27 @@ class NoRippleCheck_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(result[jss::error_message] == "Missing field 'role'.");
|
||||
}
|
||||
|
||||
// test account non-string
|
||||
{
|
||||
auto testInvalidAccountParam = [&](auto const& param) {
|
||||
Json::Value params;
|
||||
params[jss::account] = param;
|
||||
params[jss::role] = "user";
|
||||
auto jrr = env.rpc(
|
||||
"json", "noripple_check", to_string(params))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::error_message] == "Invalid field 'account'.");
|
||||
};
|
||||
|
||||
testInvalidAccountParam(1);
|
||||
testInvalidAccountParam(1.1);
|
||||
testInvalidAccountParam(true);
|
||||
testInvalidAccountParam(Json::Value(Json::nullValue));
|
||||
testInvalidAccountParam(Json::Value(Json::objectValue));
|
||||
testInvalidAccountParam(Json::Value(Json::arrayValue));
|
||||
}
|
||||
|
||||
{ // invalid role field
|
||||
Json::Value params;
|
||||
params[jss::account] = alice.human();
|
||||
@@ -369,12 +390,12 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(NoRippleCheck, app, ripple);
|
||||
BEAST_DEFINE_TESTSUITE(NoRippleCheck, rpc, ripple);
|
||||
|
||||
// These tests that deal with limit amounts are slow because of the
|
||||
// offer/account setup, so making them manual -- the additional coverage
|
||||
// provided by them is minimal
|
||||
|
||||
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(NoRippleCheckLimits, app, ripple, 1);
|
||||
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(NoRippleCheckLimits, rpc, ripple, 1);
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user