Skip to content

Commit c795cf3

Browse files
Fix base_asset value in getAggregatePrice (#1467)
Fixes #1372
1 parent e135aa4 commit c795cf3

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/rpc/handlers/GetAggregatePrice.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ class GetAggregatePriceHandler {
163163
static auto const rpcSpec = RpcSpec{
164164
{JS(ledger_hash), validation::Uint256HexStringValidator},
165165
{JS(ledger_index), validation::LedgerIndexValidator},
166-
// validate quoteAsset in accordance to the currency code found in XRPL doc:
166+
// validate quoteAsset and base_asset in accordance to the currency code found in XRPL doc:
167167
// https://xrpl.org/docs/references/protocol/data-types/currency-formats#currency-codes
168168
// usually Clio returns rpcMALFORMED_CURRENCY , return InvalidParam here just to mimic rippled
169-
{JS(base_asset), validation::Required{}, validation::Type<std::string>{}},
169+
{JS(base_asset),
170+
validation::Required{},
171+
meta::WithCustomError{validation::CurrencyValidator, Status(RippledError::rpcINVALID_PARAMS)}},
170172
{JS(quote_asset),
171173
validation::Required{},
172174
meta::WithCustomError{validation::CurrencyValidator, Status(RippledError::rpcINVALID_PARAMS)}},

tests/unit/rpc/handlers/GetAggregatePriceTests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@ generateTestValuesForParametersTest()
144144
"invalidParams",
145145
"Required field 'base_asset' missing"
146146
},
147+
GetAggregatePriceParamTestCaseBundle{
148+
"invalid_base_asset",
149+
R"({
150+
"quote_asset" : "USD",
151+
"base_asset": "asdf",
152+
"oracles":
153+
[
154+
{
155+
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
156+
"oracle_document_id": 2
157+
}
158+
]
159+
})",
160+
"invalidParams",
161+
"Invalid parameters."
162+
},
163+
GetAggregatePriceParamTestCaseBundle{
164+
"invalid_base_asset2",
165+
R"({
166+
"quote_asset" : "USD",
167+
"base_asset": "+aa",
168+
"oracles":
169+
[
170+
{
171+
"account": "rGh1VZCRBJY6rJiaFpD4LZtyHiuCkC8aeD",
172+
"oracle_document_id": 2
173+
}
174+
]
175+
})",
176+
"invalidParams",
177+
"Invalid parameters."
178+
},
147179
GetAggregatePriceParamTestCaseBundle{
148180
"no_quote_asset",
149181
R"({

0 commit comments

Comments
 (0)