mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Change order of checks in amm_info: (#4924)
* Change order of checks in amm_info * Change amm_info error message in API version 3 * Change amm_info error tests
This commit is contained in:
@@ -174,7 +174,8 @@ public:
|
||||
std::optional<Issue> issue1 = std::nullopt,
|
||||
std::optional<Issue> issue2 = std::nullopt,
|
||||
std::optional<AccountID> const& ammAccount = std::nullopt,
|
||||
bool ignoreParams = false) const;
|
||||
bool ignoreParams = false,
|
||||
unsigned apiVersion = RPC::apiInvalidVersion) const;
|
||||
|
||||
/** Verify the AMM balances.
|
||||
*/
|
||||
|
||||
@@ -163,7 +163,8 @@ AMM::ammRpcInfo(
|
||||
std::optional<Issue> issue1,
|
||||
std::optional<Issue> issue2,
|
||||
std::optional<AccountID> const& ammAccount,
|
||||
bool ignoreParams) const
|
||||
bool ignoreParams,
|
||||
unsigned apiVersion) const
|
||||
{
|
||||
Json::Value jv;
|
||||
if (account)
|
||||
@@ -191,7 +192,10 @@ AMM::ammRpcInfo(
|
||||
if (ammAccount)
|
||||
jv[jss::amm_account] = to_string(*ammAccount);
|
||||
}
|
||||
auto jr = env_.rpc("json", "amm_info", to_string(jv));
|
||||
auto jr =
|
||||
(apiVersion == RPC::apiInvalidVersion
|
||||
? env_.rpc("json", "amm_info", to_string(jv))
|
||||
: env_.rpc(apiVersion, "json", "amm_info", to_string(jv)));
|
||||
if (jr.isObject() && jr.isMember(jss::result) &&
|
||||
jr[jss::result].isMember(jss::status))
|
||||
return jr[jss::result];
|
||||
|
||||
@@ -37,6 +37,19 @@ public:
|
||||
testcase("Errors");
|
||||
|
||||
using namespace jtx;
|
||||
|
||||
Account const bogie("bogie");
|
||||
enum TestAccount { None, Alice, Bogie };
|
||||
auto accountId = [&](AMM const& ammAlice,
|
||||
TestAccount v) -> std::optional<AccountID> {
|
||||
if (v == Alice)
|
||||
return ammAlice.ammAccount();
|
||||
else if (v == Bogie)
|
||||
return bogie;
|
||||
else
|
||||
return std::nullopt;
|
||||
};
|
||||
|
||||
// Invalid tokens pair
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
Account const gw("gw");
|
||||
@@ -48,36 +61,70 @@ public:
|
||||
|
||||
// Invalid LP account id
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
Account bogie("bogie");
|
||||
auto const jv = ammAlice.ammRpcInfo(bogie.id());
|
||||
BEAST_EXPECT(jv[jss::error_message] == "Account malformed.");
|
||||
});
|
||||
|
||||
std::vector<std::tuple<
|
||||
std::optional<Issue>,
|
||||
std::optional<Issue>,
|
||||
TestAccount,
|
||||
bool>> const invalidParams = {
|
||||
{xrpIssue(), std::nullopt, None, false},
|
||||
{std::nullopt, USD.issue(), None, false},
|
||||
{xrpIssue(), std::nullopt, Alice, false},
|
||||
{std::nullopt, USD.issue(), Alice, false},
|
||||
{xrpIssue(), USD.issue(), Alice, false},
|
||||
{std::nullopt, std::nullopt, None, true}};
|
||||
|
||||
// Invalid parameters
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
std::vector<std::tuple<
|
||||
std::optional<Issue>,
|
||||
std::optional<Issue>,
|
||||
std::optional<AccountID>,
|
||||
bool>>
|
||||
vals = {
|
||||
{xrpIssue(), std::nullopt, std::nullopt, false},
|
||||
{std::nullopt, USD.issue(), std::nullopt, false},
|
||||
{xrpIssue(), std::nullopt, ammAlice.ammAccount(), false},
|
||||
{std::nullopt, USD.issue(), ammAlice.ammAccount(), false},
|
||||
{xrpIssue(), USD.issue(), ammAlice.ammAccount(), false},
|
||||
{std::nullopt, std::nullopt, std::nullopt, true}};
|
||||
for (auto const& [iss1, iss2, acct, ignoreParams] : vals)
|
||||
for (auto const& [iss1, iss2, acct, ignoreParams] : invalidParams)
|
||||
{
|
||||
auto const jv = ammAlice.ammRpcInfo(
|
||||
std::nullopt, std::nullopt, iss1, iss2, acct, ignoreParams);
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
iss1,
|
||||
iss2,
|
||||
accountId(ammAlice, acct),
|
||||
ignoreParams);
|
||||
BEAST_EXPECT(jv[jss::error_message] == "Invalid parameters.");
|
||||
}
|
||||
});
|
||||
|
||||
// Invalid parameters *and* invalid LP account, default API version
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
for (auto const& [iss1, iss2, acct, ignoreParams] : invalidParams)
|
||||
{
|
||||
auto const jv = ammAlice.ammRpcInfo(
|
||||
bogie, //
|
||||
std::nullopt,
|
||||
iss1,
|
||||
iss2,
|
||||
accountId(ammAlice, acct),
|
||||
ignoreParams);
|
||||
BEAST_EXPECT(jv[jss::error_message] == "Invalid parameters.");
|
||||
}
|
||||
});
|
||||
|
||||
// Invalid parameters *and* invalid LP account, API version 3
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
for (auto const& [iss1, iss2, acct, ignoreParams] : invalidParams)
|
||||
{
|
||||
auto const jv = ammAlice.ammRpcInfo(
|
||||
bogie, //
|
||||
std::nullopt,
|
||||
iss1,
|
||||
iss2,
|
||||
accountId(ammAlice, acct),
|
||||
ignoreParams,
|
||||
3);
|
||||
BEAST_EXPECT(jv[jss::error_message] == "Account malformed.");
|
||||
}
|
||||
});
|
||||
|
||||
// Invalid AMM account id
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
Account bogie("bogie");
|
||||
auto const jv = ammAlice.ammRpcInfo(
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
@@ -86,6 +133,54 @@ public:
|
||||
bogie.id());
|
||||
BEAST_EXPECT(jv[jss::error_message] == "Account malformed.");
|
||||
});
|
||||
|
||||
std::vector<std::tuple<
|
||||
std::optional<Issue>,
|
||||
std::optional<Issue>,
|
||||
TestAccount,
|
||||
bool>> const invalidParamsBadAccount = {
|
||||
{xrpIssue(), std::nullopt, None, false},
|
||||
{std::nullopt, USD.issue(), None, false},
|
||||
{xrpIssue(), std::nullopt, Bogie, false},
|
||||
{std::nullopt, USD.issue(), Bogie, false},
|
||||
{xrpIssue(), USD.issue(), Bogie, false},
|
||||
{std::nullopt, std::nullopt, None, true}};
|
||||
|
||||
// Invalid parameters *and* invalid AMM account, default API version
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
for (auto const& [iss1, iss2, acct, ignoreParams] :
|
||||
invalidParamsBadAccount)
|
||||
{
|
||||
auto const jv = ammAlice.ammRpcInfo(
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
iss1,
|
||||
iss2,
|
||||
accountId(ammAlice, acct),
|
||||
ignoreParams);
|
||||
BEAST_EXPECT(jv[jss::error_message] == "Invalid parameters.");
|
||||
}
|
||||
});
|
||||
|
||||
// Invalid parameters *and* invalid AMM account, API version 3
|
||||
testAMM([&](AMM& ammAlice, Env&) {
|
||||
for (auto const& [iss1, iss2, acct, ignoreParams] :
|
||||
invalidParamsBadAccount)
|
||||
{
|
||||
auto const jv = ammAlice.ammRpcInfo(
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
iss1,
|
||||
iss2,
|
||||
accountId(ammAlice, acct),
|
||||
ignoreParams,
|
||||
3);
|
||||
BEAST_EXPECT(
|
||||
jv[jss::error_message] ==
|
||||
(acct == Bogie ? std::string("Account malformed.")
|
||||
: std::string("Invalid parameters.")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user