The start of CLI tests (#2403)
* The start of CLI tests * Add needed header file after merge * Serg review comments
This commit is contained in:
parent
71f7e7e996
commit
712d6981f6
4 changed files with 62 additions and 3 deletions
|
@ -5,6 +5,7 @@ add_executable (core_test
|
|||
block.cpp
|
||||
block_store.cpp
|
||||
bootstrap.cpp
|
||||
cli.cpp
|
||||
confirmation_height.cpp
|
||||
confirmation_solicitor.cpp
|
||||
conflicts.cpp
|
||||
|
|
58
nano/core_test/cli.cpp
Normal file
58
nano/core_test/cli.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include <nano/core_test/testutil.hpp>
|
||||
#include <nano/node/cli.hpp>
|
||||
#include <nano/secure/utility.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <regex>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string call_cli_command (boost::program_options::variables_map const & vm);
|
||||
}
|
||||
|
||||
TEST (cli, key_create)
|
||||
{
|
||||
boost::program_options::variables_map vm;
|
||||
vm.emplace ("key_create", boost::program_options::variable_value ());
|
||||
auto output = call_cli_command (vm);
|
||||
|
||||
// Extract the private, public and account values. The regular expression extracts anything between the semi-colon and new line.
|
||||
std::regex regexpr (": (\\w+)");
|
||||
std::smatch matches;
|
||||
std::vector<std::string> vals;
|
||||
std::string::const_iterator search_start (output.cbegin ());
|
||||
while (std::regex_search (search_start, output.cend (), matches, regexpr))
|
||||
{
|
||||
ASSERT_NE (matches[1].str (), "");
|
||||
vals.push_back (matches[1].str ());
|
||||
search_start = matches.suffix ().first;
|
||||
}
|
||||
|
||||
// Get the contents of the private key and check that the public key and account are successfully derived from the private key
|
||||
auto private_key_str = vals.front ();
|
||||
nano::private_key private_key;
|
||||
private_key.decode_hex (private_key_str);
|
||||
|
||||
auto public_key = nano::pub_key (private_key);
|
||||
ASSERT_EQ (vals[1], public_key.to_string ());
|
||||
ASSERT_EQ (vals[2], public_key.to_account ());
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string call_cli_command (boost::program_options::variables_map const & vm)
|
||||
{
|
||||
std::stringstream ss;
|
||||
nano::cout_redirect redirect (ss.rdbuf ());
|
||||
|
||||
// Execute CLI command. This populates the stringstream with a string like: "Private: 123\n Public: 456\n Account: nano_123"
|
||||
auto ec = nano::handle_node_options (vm);
|
||||
release_assert (!static_cast<bool> (ec));
|
||||
return ss.str ();
|
||||
}
|
||||
}
|
|
@ -153,7 +153,7 @@ void database_write_lock_error (std::error_code & ec)
|
|||
ec = nano::error_cli::database_write_error;
|
||||
}
|
||||
|
||||
bool copy_database (boost::filesystem::path const & data_path, boost::program_options::variables_map & vm, boost::filesystem::path const & output_path, std::error_code & ec)
|
||||
bool copy_database (boost::filesystem::path const & data_path, boost::program_options::variables_map const & vm, boost::filesystem::path const & output_path, std::error_code & ec)
|
||||
{
|
||||
bool success = false;
|
||||
bool needs_to_write = vm.count ("unchecked_clear") || vm.count ("clear_send_ids") || vm.count ("online_weight_clear") || vm.count ("peer_clear") || vm.count ("confirmation_height_clear") || vm.count ("rebuild_database");
|
||||
|
@ -203,7 +203,7 @@ bool copy_database (boost::filesystem::path const & data_path, boost::program_op
|
|||
}
|
||||
}
|
||||
|
||||
std::error_code nano::handle_node_options (boost::program_options::variables_map & vm)
|
||||
std::error_code nano::handle_node_options (boost::program_options::variables_map const & vm)
|
||||
{
|
||||
std::error_code ec;
|
||||
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
|
||||
|
|
|
@ -22,7 +22,7 @@ enum class error_cli
|
|||
void add_node_options (boost::program_options::options_description &);
|
||||
void add_node_flag_options (boost::program_options::options_description &);
|
||||
std::error_code update_flags (nano::node_flags &, boost::program_options::variables_map const &);
|
||||
std::error_code handle_node_options (boost::program_options::variables_map &);
|
||||
std::error_code handle_node_options (boost::program_options::variables_map const &);
|
||||
}
|
||||
|
||||
REGISTER_ERROR_CODES (nano, error_cli)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue