Return correct error code for node_to_shard command errors

This commit is contained in:
Edward Hennis
2021-11-22 18:28:17 -05:00
committed by manojsdoshi
parent f0c237e001
commit 5050b366d9
4 changed files with 76 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ namespace ripple {
bool
isRpcError(Json::Value jvResult);
Json::Value
rpcError(int iError, Json::Value jvResult = Json::Value(Json::objectValue));
rpcError(int iError);
} // namespace ripple

View File

@@ -26,8 +26,9 @@ struct RPCErr;
// VFALCO NOTE Deprecated function
Json::Value
rpcError(int iError, Json::Value jvResult)
rpcError(int iError)
{
Json::Value jvResult(Json::objectValue);
RPC::inject_error(iError, jvResult);
return jvResult;
}

View File

@@ -38,7 +38,7 @@ doNodeToShard(RPC::JsonContext& context)
// Shard store must be enabled
auto const shardStore = context.app.getShardStore();
if (!shardStore)
return rpcError(rpcINTERNAL, "No shard store");
return RPC::make_error(rpcNOT_ENABLED);
if (!context.params.isMember(jss::action))
return RPC::missing_field_error(jss::action);

View File

@@ -21,6 +21,7 @@
#include <ripple/beast/utility/temp_dir.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/nodestore/DatabaseShard.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/jss.h>
#include <test/jtx/Env.h>
@@ -52,6 +53,76 @@ class NodeToShardRPC_test : public beast::unit_test::suite
}
public:
void
testDisabled()
{
testcase("Disabled");
beast::temp_dir tempDir;
jtx::Env env = [&] {
auto c = jtx::envconfig();
auto& sectionNode = c->section(ConfigSection::nodeDatabase());
sectionNode.set("earliest_seq", "257");
sectionNode.set("ledgers_per_shard", "256");
c->setupControl(true, true, true);
return jtx::Env(*this, std::move(c));
}();
std::uint8_t const numberOfShards = 10;
// Create some ledgers so that we can initiate a
// shard store database import.
for (int i = 0; i < 256 * (numberOfShards + 1); ++i)
{
env.close();
}
{
auto shardStore = env.app().getShardStore();
if (!BEAST_EXPECT(!shardStore))
return;
}
{
// Try the node_to_shard status RPC command. Should fail.
Json::Value jvParams;
jvParams[jss::action] = "status";
auto const result = env.rpc(
"json", "node_to_shard", to_string(jvParams))[jss::result];
BEAST_EXPECT(result[jss::error_code] == rpcNOT_ENABLED);
}
{
// Try to start a shard store import via the RPC
// interface. Should fail.
Json::Value jvParams;
jvParams[jss::action] = "start";
auto const result = env.rpc(
"json", "node_to_shard", to_string(jvParams))[jss::result];
BEAST_EXPECT(result[jss::error_code] == rpcNOT_ENABLED);
}
{
// Try the node_to_shard status RPC command. Should fail.
Json::Value jvParams;
jvParams[jss::action] = "status";
auto const result = env.rpc(
"json", "node_to_shard", to_string(jvParams))[jss::result];
BEAST_EXPECT(result[jss::error_code] == rpcNOT_ENABLED);
}
}
void
testStart()
{
@@ -321,6 +392,7 @@ public:
void
run() override
{
testDisabled();
testStart();
testStop();
}