Process RPC incorrect enable_control checking when using watch_work (#2462)
* Process RPC incorrect enable_control setting for watch_work * Simplify with boost::optional::get_value_or (thanks Gui) * get_value_or is deprecated, use value_or and simplify a little more
This commit is contained in:
parent
475c32e23e
commit
9403335501
2 changed files with 44 additions and 4 deletions
|
@ -86,9 +86,9 @@ void nano::rpc_handler::process_request ()
|
|||
}
|
||||
else if (action == "process")
|
||||
{
|
||||
auto force = request.get_optional<bool> ("force");
|
||||
auto watch_work = request.get_optional<bool> ("watch_work");
|
||||
if (((force.is_initialized () && *force) || (watch_work.is_initialized () && !*watch_work)) && !rpc_config.enable_control)
|
||||
auto force = request.get_optional<bool> ("force").value_or (false);
|
||||
auto watch_work = request.get_optional<bool> ("watch_work").value_or (true);
|
||||
if ((force || watch_work) && !rpc_config.enable_control)
|
||||
{
|
||||
json_error_response (response, rpc_control_disabled_ec.message ());
|
||||
error = true;
|
||||
|
|
|
@ -1798,7 +1798,7 @@ TEST (rpc, process_block_with_work_watcher)
|
|||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "process");
|
||||
request.put ("work_watcher", true);
|
||||
request.put ("watch_work", true);
|
||||
std::string json;
|
||||
send->serialize_json (json);
|
||||
request.put ("block", json);
|
||||
|
@ -1835,6 +1835,46 @@ TEST (rpc, process_block_with_work_watcher)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_GT (updated_difficulty, difficulty1);
|
||||
|
||||
// Try without enable_control which watch_work requires if set to true
|
||||
{
|
||||
nano::rpc_config rpc_config (nano::get_available_port (), false);
|
||||
rpc_config.rpc_process.ipc_port = node1.config.ipc_config.transport_tcp.port;
|
||||
nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config);
|
||||
nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor);
|
||||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "process");
|
||||
request.put ("watch_work", true);
|
||||
std::string json;
|
||||
send->serialize_json (json);
|
||||
request.put ("block", json);
|
||||
{
|
||||
test_response response (request, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response.status == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
std::error_code ec (nano::error_rpc::rpc_control_disabled);
|
||||
ASSERT_EQ (ec.message (), response.json.get<std::string> ("error"));
|
||||
}
|
||||
|
||||
// Check no enable_control error message is present when not watching work
|
||||
request.put ("watch_work", false);
|
||||
{
|
||||
test_response response (request, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response.status == 0)
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
std::error_code ec (nano::error_rpc::rpc_control_disabled);
|
||||
ASSERT_NE (ec.message (), response.json.get<std::string> ("error"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST (rpc, process_block_no_work)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue