From d7b84a2e7a800a9721499a9d27ef4e5530f1b443 Mon Sep 17 00:00:00 2001 From: cyan317 <120398799+cindyyan317@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:47:47 +0100 Subject: [PATCH] Missing "tx_hash" for transaction_entry (#758) Fixes #759 --- src/rpc/Errors.cpp | 2 ++ src/rpc/Errors.h | 1 + src/rpc/handlers/TransactionEntry.h | 5 ++++- src/webserver/details/ErrorHandling.h | 1 + unittests/rpc/handlers/TransactionEntryTest.cpp | 4 ++-- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rpc/Errors.cpp b/src/rpc/Errors.cpp index 5ca1f626..bed0dacb 100644 --- a/src/rpc/Errors.cpp +++ b/src/rpc/Errors.cpp @@ -80,6 +80,8 @@ getErrorInfo(ClioError code) {ClioError::rpcMALFORMED_ADDRESS, "malformedAddress", "Malformed address."}, {ClioError::rpcINVALID_HOT_WALLET, "invalidHotWallet", "Invalid hot wallet."}, {ClioError::rpcUNKNOWN_OPTION, "unknownOption", "Unknown option."}, + {ClioError::rpcFIELD_NOT_FOUND_TRANSACTION, "fieldNotFoundTransaction", "Missing field."}, + // special system errors {ClioError::rpcINVALID_API_VERSION, JS(invalid_API_version), "Invalid API version."}, {ClioError::rpcCOMMAND_IS_MISSING, JS(missingCommand), "Method is not specified or is not a string."}, {ClioError::rpcCOMMAND_NOT_STRING, "commandNotString", "Method is not a string."}, diff --git a/src/rpc/Errors.h b/src/rpc/Errors.h index 8880dc0d..d15c3274 100644 --- a/src/rpc/Errors.h +++ b/src/rpc/Errors.h @@ -41,6 +41,7 @@ enum class ClioError { rpcMALFORMED_ADDRESS = 5003, rpcINVALID_HOT_WALLET = 5004, rpcUNKNOWN_OPTION = 5005, + rpcFIELD_NOT_FOUND_TRANSACTION = 5006, // special system errors start with 6000 rpcINVALID_API_VERSION = 6000, diff --git a/src/rpc/handlers/TransactionEntry.h b/src/rpc/handlers/TransactionEntry.h index 647fb2cf..9f6acc9a 100644 --- a/src/rpc/handlers/TransactionEntry.h +++ b/src/rpc/handlers/TransactionEntry.h @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -65,7 +66,9 @@ public: spec([[maybe_unused]] uint32_t apiVersion) const { static auto const rpcSpec = RpcSpec{ - {JS(tx_hash), validation::Required{}, validation::Uint256HexStringValidator}, + {JS(tx_hash), + meta::WithCustomError{validation::Required{}, Status(ClioError::rpcFIELD_NOT_FOUND_TRANSACTION)}, + validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator}, {JS(ledger_index), validation::LedgerIndexValidator}, }; diff --git a/src/webserver/details/ErrorHandling.h b/src/webserver/details/ErrorHandling.h index 0f8964c0..8b175860 100644 --- a/src/webserver/details/ErrorHandling.h +++ b/src/webserver/details/ErrorHandling.h @@ -85,6 +85,7 @@ public: case RPC::ClioError::rpcMALFORMED_OWNER: case RPC::ClioError::rpcMALFORMED_ADDRESS: case RPC::ClioError::rpcINVALID_HOT_WALLET: + case RPC::ClioError::rpcFIELD_NOT_FOUND_TRANSACTION: assert(false); // this should never happen break; } diff --git a/unittests/rpc/handlers/TransactionEntryTest.cpp b/unittests/rpc/handlers/TransactionEntryTest.cpp index 097a64f5..4198b7b6 100644 --- a/unittests/rpc/handlers/TransactionEntryTest.cpp +++ b/unittests/rpc/handlers/TransactionEntryTest.cpp @@ -45,8 +45,8 @@ TEST_F(RPCTransactionEntryHandlerTest, TxHashNotProvide) auto const output = handler.process(json::parse("{}"), Context{std::ref(yield)}); ASSERT_FALSE(output); auto const err = RPC::makeError(output.error()); - EXPECT_EQ(err.at("error").as_string(), "invalidParams"); - EXPECT_EQ(err.at("error_message").as_string(), "Required field 'tx_hash' missing"); + EXPECT_EQ(err.at("error").as_string(), "fieldNotFoundTransaction"); + EXPECT_EQ(err.at("error_message").as_string(), "Missing field."); }); }