From c795cf371a6c603e405661d075f49fd77c674e5f Mon Sep 17 00:00:00 2001 From: Peter Chen <34582813+PeterChen13579@users.noreply.github.com> Date: Tue, 18 Jun 2024 09:04:33 -0400 Subject: [PATCH] Fix base_asset value in getAggregatePrice (#1467) Fixes #1372 --- src/rpc/handlers/GetAggregatePrice.hpp | 6 ++-- .../rpc/handlers/GetAggregatePriceTests.cpp | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/rpc/handlers/GetAggregatePrice.hpp b/src/rpc/handlers/GetAggregatePrice.hpp index 81914033..b2a173d5 100644 --- a/src/rpc/handlers/GetAggregatePrice.hpp +++ b/src/rpc/handlers/GetAggregatePrice.hpp @@ -163,10 +163,12 @@ public: 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{}}, + {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)}}, diff --git a/tests/unit/rpc/handlers/GetAggregatePriceTests.cpp b/tests/unit/rpc/handlers/GetAggregatePriceTests.cpp index 078bb244..b8e06fd2 100644 --- a/tests/unit/rpc/handlers/GetAggregatePriceTests.cpp +++ b/tests/unit/rpc/handlers/GetAggregatePriceTests.cpp @@ -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"({