Skip to content

Commit

Permalink
Fix quoteAsset value in getAggregatePrice (#1449)
Browse files Browse the repository at this point in the history
Fixes #1373
  • Loading branch information
PeterChen13579 authored Jun 12, 2024
1 parent f9f3bc9 commit 437ea7b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/rpc/handlers/GetAggregatePrice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "data/BackendInterface.hpp"
#include "rpc/Errors.hpp"
#include "rpc/JS.hpp"
#include "rpc/common/MetaProcessors.hpp"
#include "rpc/common/Modifiers.hpp"
#include "rpc/common/Specs.hpp"
#include "rpc/common/Types.hpp"
Expand All @@ -32,7 +33,6 @@
#include <boost/json/conversion.hpp>
#include <ripple/basics/Number.h>
#include <ripple/protocol/AccountID.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/STAmount.h>
#include <ripple/protocol/STObject.h>
#include <ripple/protocol/jss.h>
Expand All @@ -45,6 +45,7 @@
#include <string_view>
#include <utility>
#include <vector>

namespace rpc {

/**
Expand Down Expand Up @@ -162,11 +163,13 @@ class GetAggregatePriceHandler {
static auto const rpcSpec = RpcSpec{
{JS(ledger_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator},
// note: Rippled's base_asset and quote_asset can be non-string. It will eventually return
// "rpcOBJECT_NOT_FOUND". Clio will return "rpcINVALID_PARAMS" if the base_asset or quote_asset is not a
// string. User can clearly know there is a mistake in the input.
// validate quoteAsset 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(quote_asset), validation::Required{}, validation::Type<std::string>{}},
{JS(quote_asset),
validation::Required{},
meta::WithCustomError{validation::CurrencyValidator, Status(RippledError::rpcINVALID_PARAMS)}},
{JS(oracles), validation::Required{}, oraclesValidator},
// note: Unlike `rippled`, Clio only supports UInt as input, no string, no `null`, etc.
{JS(time_threshold), validation::Type<std::uint32_t>{}},
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 @@ -159,6 +159,38 @@ generateTestValuesForParametersTest()
"invalidParams",
"Required field 'quote_asset' missing"
},
GetAggregatePriceParamTestCaseBundle{
"invalid_quote_asset",
R"({
"quote_asset" : "asdf",
"base_asset": "USD",
"oracles":
[
{
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
"oracle_document_id": 2
}
]
})",
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"invalid_quote_asset2",
R"({
"quote_asset" : "+aa",
"base_asset": "USD",
"oracles":
[
{
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
"oracle_document_id": 2
}
]
})",
"invalidParams",
"Invalid parameters."
},
GetAggregatePriceParamTestCaseBundle{
"oraclesIsEmpty",
R"({
Expand Down

0 comments on commit 437ea7b

Please sign in to comment.