Skip to content

Commit

Permalink
Fix base_asset value in getAggregatePrice (#1467)
Browse files Browse the repository at this point in the history
Fixes #1372
  • Loading branch information
PeterChen13579 authored Jun 18, 2024
1 parent e135aa4 commit c795cf3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/rpc/handlers/GetAggregatePrice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ class GetAggregatePriceHandler {
static auto const rpcSpec = RpcSpec{
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
// validate quoteAsset in accordance to the currency code found in XRPL doc:
// validate quoteAsset and base_asset in accordance to the currency code found in XRPL doc:
// https://xrpl.org/docs/references/protocol/data-types/currency-formats#currency-codes
// usually Clio returns rpcMALFORMED_CURRENCY , return InvalidParam here just to mimic rippled
{JS(base_asset), validation::Required{}, validation::Type<std::string>{}},
{JS(base_asset),
validation::Required{},
meta::WithCustomError{validation::CurrencyValidator, Status(RippledError::rpcINVALID_PARAMS)}},
{JS(quote_asset),
validation::Required{},
meta::WithCustomError{validation::CurrencyValidator, Status(RippledError::rpcINVALID_PARAMS)}},
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 @@ -144,6 +144,38 @@ generateTestValuesForParametersTest()
"invalidParams",
"Required field 'base_asset' missing"
},
GetAggregatePriceParamTestCaseBundle{
"invalid_base_asset",
R"({
"quote_asset" : "USD",
"base_asset": "asdf",
"oracles":
[
{
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
"oracle_document_id": 2
}
]
})",
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"invalid_base_asset2",
R"({
"quote_asset" : "USD",
"base_asset": "+aa",
"oracles":
[
{
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
"oracle_document_id": 2
}
]
})",
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"no_quote_asset",
R"({
Expand Down

0 comments on commit c795cf3

Please sign in to comment.