Skip to content

Commit

Permalink
No required options in TOML parsing (#2245)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermelawless authored Aug 24, 2019
1 parent 6f84d60 commit c906a1c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
51 changes: 51 additions & 0 deletions nano/core_test/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,36 @@ TEST (toml, daemon_config_deserialize_no_defaults)
ASSERT_NE (conf.node.stat_config.log_samples_filename, defaults.node.stat_config.log_samples_filename);
}

/** There should be no required values **/
TEST (toml, daemon_config_no_required)
{
std::stringstream ss;

// A config with no values, only categories
ss << R"toml(
[node]
[node.diagnostics.txn_tracking]
[node.httpcallback]
[node.ipc.local]
[node.ipc.tcp]
[node.logging]
[node.statistics.log]
[node.statistics.sampling]
[node.websocket]
[opencl]
[rpc]
[rpc.child_process]
)toml";

nano::tomlconfig toml;
toml.read (ss);
nano::daemon_config conf;
nano::daemon_config defaults;
conf.deserialize_toml (toml);

ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message ();
}

/** Deserialize an rpc config with non-default values */
TEST (toml, rpc_config_deserialize_no_defaults)
{
Expand Down Expand Up @@ -485,3 +515,24 @@ TEST (toml, rpc_config_deserialize_no_defaults)
ASSERT_NE (conf.rpc_process.ipc_port, defaults.rpc_process.ipc_port);
ASSERT_NE (conf.rpc_process.num_ipc_connections, defaults.rpc_process.num_ipc_connections);
}

/** There should be no required values **/
TEST (toml, rpc_config_no_required)
{
std::stringstream ss;

// A config with no values, only categories
ss << R"toml(
[version]
[process]
[secure]
)toml";

nano::tomlconfig toml;
toml.read (ss);
nano::rpc_config conf;
nano::rpc_config defaults;
conf.deserialize_toml (toml);

ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message ();
}
14 changes: 7 additions & 7 deletions nano/lib/rpcconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ nano::error nano::rpc_secure_config::serialize_toml (nano::tomlconfig & toml) co

nano::error nano::rpc_secure_config::deserialize_toml (nano::tomlconfig & toml)
{
toml.get_required<bool> ("enable", enable);
toml.get_required<bool> ("verbose_logging", verbose_logging);
toml.get_required<std::string> ("server_key_passphrase", server_key_passphrase);
toml.get_required<std::string> ("server_cert_path", server_cert_path);
toml.get_required<std::string> ("server_key_path", server_key_path);
toml.get_required<std::string> ("server_dh_path", server_dh_path);
toml.get_required<std::string> ("client_certs_path", client_certs_path);
toml.get<bool> ("enable", enable);
toml.get<bool> ("verbose_logging", verbose_logging);
toml.get<std::string> ("server_key_passphrase", server_key_passphrase);
toml.get<std::string> ("server_cert_path", server_cert_path);
toml.get<std::string> ("server_key_path", server_key_path);
toml.get<std::string> ("server_dh_path", server_dh_path);
toml.get<std::string> ("client_certs_path", client_certs_path);
return toml.get_error ();
}

Expand Down
2 changes: 1 addition & 1 deletion nano/node/websocketconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nano::error nano::websocket::config::serialize_toml (nano::tomlconfig & toml) co
nano::error nano::websocket::config::deserialize_toml (nano::tomlconfig & toml)
{
toml.get<bool> ("enable", enabled);
toml.get_required<boost::asio::ip::address_v6> ("address", address);
toml.get<boost::asio::ip::address_v6> ("address", address);
toml.get<uint16_t> ("port", port);
return toml.get_error ();
}
Expand Down

0 comments on commit c906a1c

Please sign in to comment.