Skip to content

Commit

Permalink
Fix empty currency (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyyan317 authored and kuznetsss committed Jun 21, 2024
1 parent c795cf3 commit 4940d46
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rpc/common/Validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <fmt/core.h>
#include <ripple/basics/base_uint.h>
#include <ripple/protocol/AccountID.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/UintTypes.h>
#include <ripple/protocol/tokens.h>

Expand Down Expand Up @@ -140,8 +141,12 @@ CustomValidator CurrencyValidator =
if (!value.is_string())
return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + "NotString"}};

auto const currencyStr = boost::json::value_to<std::string>(value);
if (currencyStr.empty())
return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + "IsEmpty"}};

ripple::Currency currency;
if (!ripple::to_currency(currency, boost::json::value_to<std::string>(value)))
if (!ripple::to_currency(currency, currencyStr))
return Error{Status{ClioError::rpcMALFORMED_CURRENCY, "malformedCurrency"}};

return MaybeError{};
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/rpc/handlers/GetAggregatePriceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ generateTestValuesForParametersTest()
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"emtpy_base_asset",
R"({
"quote_asset" : "USD",
"base_asset": "",
"oracles":
[
{
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
"oracle_document_id": 2
}
]
})",
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"invalid_base_asset2",
R"({
Expand Down Expand Up @@ -207,6 +223,22 @@ generateTestValuesForParametersTest()
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"empty_quote_asset",
R"({
"quote_asset" : "",
"base_asset": "USD",
"oracles":
[
{
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
"oracle_document_id": 2
}
]
})",
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"invalid_quote_asset2",
R"({
Expand Down

0 comments on commit 4940d46

Please sign in to comment.