Missing "tx_hash" for transaction_entry (#758)

Fixes #759
This commit is contained in:
cyan317
2023-07-11 16:47:47 +01:00
committed by GitHub
parent e79425bc21
commit d7b84a2e7a
5 changed files with 10 additions and 3 deletions

View File

@@ -80,6 +80,8 @@ getErrorInfo(ClioError code)
{ClioError::rpcMALFORMED_ADDRESS, "malformedAddress", "Malformed address."}, {ClioError::rpcMALFORMED_ADDRESS, "malformedAddress", "Malformed address."},
{ClioError::rpcINVALID_HOT_WALLET, "invalidHotWallet", "Invalid hot wallet."}, {ClioError::rpcINVALID_HOT_WALLET, "invalidHotWallet", "Invalid hot wallet."},
{ClioError::rpcUNKNOWN_OPTION, "unknownOption", "Unknown option."}, {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::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_IS_MISSING, JS(missingCommand), "Method is not specified or is not a string."},
{ClioError::rpcCOMMAND_NOT_STRING, "commandNotString", "Method is not a string."}, {ClioError::rpcCOMMAND_NOT_STRING, "commandNotString", "Method is not a string."},

View File

@@ -41,6 +41,7 @@ enum class ClioError {
rpcMALFORMED_ADDRESS = 5003, rpcMALFORMED_ADDRESS = 5003,
rpcINVALID_HOT_WALLET = 5004, rpcINVALID_HOT_WALLET = 5004,
rpcUNKNOWN_OPTION = 5005, rpcUNKNOWN_OPTION = 5005,
rpcFIELD_NOT_FOUND_TRANSACTION = 5006,
// special system errors start with 6000 // special system errors start with 6000
rpcINVALID_API_VERSION = 6000, rpcINVALID_API_VERSION = 6000,

View File

@@ -21,6 +21,7 @@
#include <backend/BackendInterface.h> #include <backend/BackendInterface.h>
#include <rpc/RPCHelpers.h> #include <rpc/RPCHelpers.h>
#include <rpc/common/MetaProcessors.h>
#include <rpc/common/Types.h> #include <rpc/common/Types.h>
#include <rpc/common/Validators.h> #include <rpc/common/Validators.h>
@@ -65,7 +66,9 @@ public:
spec([[maybe_unused]] uint32_t apiVersion) const spec([[maybe_unused]] uint32_t apiVersion) const
{ {
static auto const rpcSpec = RpcSpec{ 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_hash), validation::Uint256HexStringValidator},
{JS(ledger_index), validation::LedgerIndexValidator}, {JS(ledger_index), validation::LedgerIndexValidator},
}; };

View File

@@ -85,6 +85,7 @@ public:
case RPC::ClioError::rpcMALFORMED_OWNER: case RPC::ClioError::rpcMALFORMED_OWNER:
case RPC::ClioError::rpcMALFORMED_ADDRESS: case RPC::ClioError::rpcMALFORMED_ADDRESS:
case RPC::ClioError::rpcINVALID_HOT_WALLET: case RPC::ClioError::rpcINVALID_HOT_WALLET:
case RPC::ClioError::rpcFIELD_NOT_FOUND_TRANSACTION:
assert(false); // this should never happen assert(false); // this should never happen
break; break;
} }

View File

@@ -45,8 +45,8 @@ TEST_F(RPCTransactionEntryHandlerTest, TxHashNotProvide)
auto const output = handler.process(json::parse("{}"), Context{std::ref(yield)}); auto const output = handler.process(json::parse("{}"), Context{std::ref(yield)});
ASSERT_FALSE(output); ASSERT_FALSE(output);
auto const err = RPC::makeError(output.error()); auto const err = RPC::makeError(output.error());
EXPECT_EQ(err.at("error").as_string(), "invalidParams"); EXPECT_EQ(err.at("error").as_string(), "fieldNotFoundTransaction");
EXPECT_EQ(err.at("error_message").as_string(), "Required field 'tx_hash' missing"); EXPECT_EQ(err.at("error_message").as_string(), "Missing field.");
}); });
} }