mirror of
https://github.com/Xahau/xahaud.git
synced 2026-04-29 15:37:46 +00:00
APIv2(ledger_entry): return "invalidParams" when fields missing (#4552)
Improve error handling for ledger_entry by returning an "invalidParams" error when one or more request fields are specified incorrectly, or one or more required fields are missing. For example, if none of of the following fields is provided, then the API should return an invalidParams error: * index, account_root, directory, offer, ripple_state, check, escrow, payment_channel, deposit_preauth, ticket Prior to this commit, the API returned an "unknownOption" error instead. Since the error was actually due to invalid parameters, rather than unknown options, this error was misleading. Since this is an API breaking change, the "invalidParams" error is only returned for requests using api_version: 2 and above. To maintain backward compatibility, the "unknownOption" error is still returned for api_version: 1. Related: #4573 Fix #4303
This commit is contained in:
@@ -520,7 +520,12 @@ doLedgerEntry(RPC::JsonContext& context)
|
||||
}
|
||||
}
|
||||
else
|
||||
jvResult[jss::error] = "unknownOption";
|
||||
{
|
||||
if (context.apiVersion < 2u)
|
||||
jvResult[jss::error] = "unknownOption";
|
||||
else
|
||||
jvResult[jss::error] = "invalidParams";
|
||||
}
|
||||
}
|
||||
|
||||
if (uNodeIndex.isNonZero())
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
||||
#include <test/app/Import_json.h>
|
||||
#include <test/jtx.h>
|
||||
|
||||
@@ -1832,9 +1833,11 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
testLedgerEntryUnknownOption()
|
||||
testLedgerEntryInvalidParams(unsigned int apiVersion)
|
||||
{
|
||||
testcase("ledger_entry Request Unknown Option");
|
||||
testcase(
|
||||
"ledger_entry Request With Invalid Parameters v" +
|
||||
std::to_string(apiVersion));
|
||||
using namespace test::jtx;
|
||||
Env env{*this};
|
||||
|
||||
@@ -1842,11 +1845,16 @@ public:
|
||||
|
||||
// "features" is not an option supported by ledger_entry.
|
||||
Json::Value jvParams;
|
||||
jvParams[jss::api_version] = apiVersion;
|
||||
jvParams[jss::features] = ledgerHash;
|
||||
jvParams[jss::ledger_hash] = ledgerHash;
|
||||
Json::Value const jrr =
|
||||
env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
|
||||
checkErrorValue(jrr, "unknownOption", "");
|
||||
|
||||
if (apiVersion < 2u)
|
||||
checkErrorValue(jrr, "unknownOption", "");
|
||||
else
|
||||
checkErrorValue(jrr, "invalidParams", "");
|
||||
}
|
||||
|
||||
/// @brief ledger RPC requests as a way to drive
|
||||
@@ -2356,11 +2364,18 @@ public:
|
||||
testLedgerEntryTicket();
|
||||
testLedgerEntryURIToken();
|
||||
testLedgerEntryImportVLSeq();
|
||||
testLedgerEntryUnknownOption();
|
||||
testLookupLedger();
|
||||
testNoQueue();
|
||||
testQueue();
|
||||
testLedgerAccountsOption();
|
||||
|
||||
// version specific tests
|
||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
||||
testVersion <= RPC::apiBetaVersion;
|
||||
++testVersion)
|
||||
{
|
||||
testLedgerEntryInvalidParams(testVersion);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user