mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-06 12:15:52 +00:00
Return correct error code for node_to_shard command errors
This commit is contained in:
committed by
manojsdoshi
parent
f0c237e001
commit
5050b366d9
@@ -28,7 +28,7 @@ namespace ripple {
|
|||||||
bool
|
bool
|
||||||
isRpcError(Json::Value jvResult);
|
isRpcError(Json::Value jvResult);
|
||||||
Json::Value
|
Json::Value
|
||||||
rpcError(int iError, Json::Value jvResult = Json::Value(Json::objectValue));
|
rpcError(int iError);
|
||||||
|
|
||||||
} // namespace ripple
|
} // namespace ripple
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ struct RPCErr;
|
|||||||
|
|
||||||
// VFALCO NOTE Deprecated function
|
// VFALCO NOTE Deprecated function
|
||||||
Json::Value
|
Json::Value
|
||||||
rpcError(int iError, Json::Value jvResult)
|
rpcError(int iError)
|
||||||
{
|
{
|
||||||
|
Json::Value jvResult(Json::objectValue);
|
||||||
RPC::inject_error(iError, jvResult);
|
RPC::inject_error(iError, jvResult);
|
||||||
return jvResult;
|
return jvResult;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ doNodeToShard(RPC::JsonContext& context)
|
|||||||
// Shard store must be enabled
|
// Shard store must be enabled
|
||||||
auto const shardStore = context.app.getShardStore();
|
auto const shardStore = context.app.getShardStore();
|
||||||
if (!shardStore)
|
if (!shardStore)
|
||||||
return rpcError(rpcINTERNAL, "No shard store");
|
return RPC::make_error(rpcNOT_ENABLED);
|
||||||
|
|
||||||
if (!context.params.isMember(jss::action))
|
if (!context.params.isMember(jss::action))
|
||||||
return RPC::missing_field_error(jss::action);
|
return RPC::missing_field_error(jss::action);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <ripple/beast/utility/temp_dir.h>
|
#include <ripple/beast/utility/temp_dir.h>
|
||||||
#include <ripple/core/ConfigSections.h>
|
#include <ripple/core/ConfigSections.h>
|
||||||
#include <ripple/nodestore/DatabaseShard.h>
|
#include <ripple/nodestore/DatabaseShard.h>
|
||||||
|
#include <ripple/protocol/ErrorCodes.h>
|
||||||
#include <ripple/protocol/jss.h>
|
#include <ripple/protocol/jss.h>
|
||||||
#include <test/jtx/Env.h>
|
#include <test/jtx/Env.h>
|
||||||
|
|
||||||
@@ -52,6 +53,76 @@ class NodeToShardRPC_test : public beast::unit_test::suite
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
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
|
void
|
||||||
testStart()
|
testStart()
|
||||||
{
|
{
|
||||||
@@ -321,6 +392,7 @@ public:
|
|||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
|
testDisabled();
|
||||||
testStart();
|
testStart();
|
||||||
testStop();
|
testStop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user