diff options
Diffstat (limited to 'tests')
35 files changed, 178 insertions, 45 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a5f5335db..762eee776 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -111,7 +111,7 @@ add_test( COMMAND hash-target-tests) set(enabled_tests - coretests + core_tests difficulty hash performance_tests diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index a0be3db96..fd07a5d2e 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -34,12 +34,8 @@ #include "include_base_utils.h" #include "version.h" - -using namespace epee; - #include <iostream> #include <sstream> -using namespace std; #include <boost/program_options.hpp> @@ -56,6 +52,8 @@ using namespace std; #endif namespace po = boost::program_options; +using namespace std; +using namespace epee; using namespace cryptonote; using namespace crypto; @@ -71,7 +69,7 @@ int main(int argc, char* argv[]) TRY_ENTRY(); - + tools::on_startup(); string_tools::set_module_name_and_folder(argv[0]); //set up logging options @@ -81,7 +79,7 @@ int main(int argc, char* argv[]) po::options_description desc("Allowed options"); // tools::get_default_data_dir() can't be called during static initialization - command_line::add_arg(desc, command_line::arg_data_dir, tools::get_default_data_dir()); + command_line::add_arg(desc, cryptonote::arg_data_dir, tools::get_default_data_dir()); nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<tests::proxy_core> >::init_options(desc); po::variables_map vm; diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt index a24bd4fce..68f2e9816 100644 --- a/tests/core_tests/CMakeLists.txt +++ b/tests/core_tests/CMakeLists.txt @@ -58,10 +58,10 @@ set(core_tests_headers v2_tests.h rct.h) -add_executable(coretests +add_executable(core_tests ${core_tests_sources} ${core_tests_headers}) -target_link_libraries(coretests +target_link_libraries(core_tests PRIVATE cryptonote_core p2p @@ -69,10 +69,10 @@ target_link_libraries(coretests epee ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBRARIES}) -set_property(TARGET coretests +set_property(TARGET core_tests PROPERTY FOLDER "tests") add_test( - NAME coretests - COMMAND coretests --generate_and_play_test_data) + NAME core_tests + COMMAND core_tests --generate_and_play_test_data) diff --git a/tests/core_tests/block_reward.cpp b/tests/core_tests/block_reward.cpp index 9f3939652..8e68554d3 100644 --- a/tests/core_tests/block_reward.cpp +++ b/tests/core_tests/block_reward.cpp @@ -29,8 +29,6 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" - #include "block_reward.h" using namespace epee; diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index db44cd279..94b636f82 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "block_validation.h" using namespace epee; using namespace cryptonote; diff --git a/tests/core_tests/chain_split_1.cpp b/tests/core_tests/chain_split_1.cpp index eaaa3e045..79aecb1c0 100644 --- a/tests/core_tests/chain_split_1.cpp +++ b/tests/core_tests/chain_split_1.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "chain_split_1.h" using namespace std; diff --git a/tests/core_tests/chain_switch_1.cpp b/tests/core_tests/chain_switch_1.cpp index b04d05219..01cf00f7a 100644 --- a/tests/core_tests/chain_switch_1.cpp +++ b/tests/core_tests/chain_switch_1.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "chain_switch_1.h" using namespace epee; using namespace cryptonote; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 2b713cab9..4c5dc6c9a 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -47,6 +47,7 @@ using namespace std; using namespace epee; +using namespace crypto; using namespace cryptonote; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 3e5b949c8..9eba347cd 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -47,6 +47,7 @@ namespace int main(int argc, char* argv[]) { TRY_ENTRY(); + tools::on_startup(); epee::string_tools::set_module_name_and_folder(argv[0]); //set up logging options diff --git a/tests/core_tests/double_spend.cpp b/tests/core_tests/double_spend.cpp index 58114b026..d82120254 100644 --- a/tests/core_tests/double_spend.cpp +++ b/tests/core_tests/double_spend.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "double_spend.h" using namespace epee; using namespace cryptonote; diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp index 5a9604fc1..4abdfbff5 100644 --- a/tests/core_tests/integer_overflow.cpp +++ b/tests/core_tests/integer_overflow.cpp @@ -29,8 +29,6 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" - #include "integer_overflow.h" using namespace epee; diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp index 8a38cbc22..50f65cc67 100644 --- a/tests/core_tests/rct.cpp +++ b/tests/core_tests/rct.cpp @@ -30,7 +30,7 @@ #include "ringct/rctSigs.h" #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "rct.h" using namespace epee; using namespace crypto; diff --git a/tests/core_tests/ring_signature_1.cpp b/tests/core_tests/ring_signature_1.cpp index f9ec68e45..43c63dc53 100644 --- a/tests/core_tests/ring_signature_1.cpp +++ b/tests/core_tests/ring_signature_1.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "ring_signature_1.h" using namespace epee; using namespace cryptonote; diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index 0e4b2e71a..9987f80d6 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "tx_validation.h" using namespace epee; using namespace crypto; diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp index 6c94ac76c..6c2f91fcf 100644 --- a/tests/core_tests/v2_tests.cpp +++ b/tests/core_tests/v2_tests.cpp @@ -29,7 +29,7 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "chaingen.h" -#include "chaingen_tests_list.h" +#include "v2_tests.h" using namespace epee; using namespace crypto; diff --git a/tests/functional_tests/main.cpp b/tests/functional_tests/main.cpp index 4c9e073d4..35a0bb9bd 100644 --- a/tests/functional_tests/main.cpp +++ b/tests/functional_tests/main.cpp @@ -34,6 +34,7 @@ using namespace epee; #include "common/command_line.h" +#include "common/util.h" #include "transactions_flow_test.h" namespace po = boost::program_options; @@ -58,6 +59,7 @@ namespace int main(int argc, char* argv[]) { TRY_ENTRY(); + tools::on_startup(); string_tools::set_module_name_and_folder(argv[0]); //set up logging options diff --git a/tests/fuzz/block.cpp b/tests/fuzz/block.cpp index 099e8e3bd..03751fc14 100644 --- a/tests/fuzz/block.cpp +++ b/tests/fuzz/block.cpp @@ -27,7 +27,6 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "include_base_utils.h" -#include "common/command_line.h" #include "file_io_utils.h" #include "cryptonote_protocol/blobdatatype.h" #include "cryptonote_basic/cryptonote_basic.h" diff --git a/tests/fuzz/cold-transaction.cpp b/tests/fuzz/cold-transaction.cpp index c35d604a8..25a80fc68 100644 --- a/tests/fuzz/cold-transaction.cpp +++ b/tests/fuzz/cold-transaction.cpp @@ -27,7 +27,6 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "include_base_utils.h" -#include "common/command_line.h" #include "file_io_utils.h" #include "cryptonote_protocol/blobdatatype.h" #include "cryptonote_basic/cryptonote_basic.h" diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp index 3edf8cd19..756a8c847 100644 --- a/tests/fuzz/fuzzer.cpp +++ b/tests/fuzz/fuzzer.cpp @@ -29,6 +29,7 @@ #include <boost/program_options.hpp> #include "include_base_utils.h" #include "common/command_line.h" +#include "common/util.h" #include "fuzzer.h" #if (!defined(__clang__) || (__clang__ < 5)) @@ -48,6 +49,7 @@ using namespace boost::program_options; int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer) { TRY_ENTRY(); + tools::on_startup(); string_tools::set_module_name_and_folder(argv[0]); //set up logging options diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp index 071297ba8..42a8fa997 100644 --- a/tests/fuzz/signature.cpp +++ b/tests/fuzz/signature.cpp @@ -27,7 +27,6 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "include_base_utils.h" -#include "common/command_line.h" #include "file_io_utils.h" #include "cryptonote_protocol/blobdatatype.h" #include "cryptonote_basic/cryptonote_basic.h" diff --git a/tests/fuzz/transaction.cpp b/tests/fuzz/transaction.cpp index 21cd01bef..9e2b9f2cb 100644 --- a/tests/fuzz/transaction.cpp +++ b/tests/fuzz/transaction.cpp @@ -27,7 +27,6 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "include_base_utils.h" -#include "common/command_line.h" #include "file_io_utils.h" #include "cryptonote_protocol/blobdatatype.h" #include "cryptonote_basic/cryptonote_basic.h" diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 853ad7c8d..3434cd530 100644 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -33,6 +33,7 @@ #include "wallet/wallet2_api.h" #include "wallet/wallet2.h" #include "include_base_utils.h" +#include "common/util.h" #include <boost/chrono/chrono.hpp> #include <boost/filesystem.hpp> @@ -1138,6 +1139,7 @@ TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync) int main(int argc, char** argv) { + tools::on_startup(); // we can override default values for "TESTNET_DAEMON_ADDRESS" and "WALLETS_ROOT_DIR" const char * testnet_daemon_addr = std::getenv("TESTNET_DAEMON_ADDRESS"); diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp index 376d7ee53..a5e5b7c0c 100644 --- a/tests/net_load_tests/clt.cpp +++ b/tests/net_load_tests/clt.cpp @@ -193,7 +193,7 @@ namespace { m_thread_count = (std::max)(min_thread_count, boost::thread::hardware_concurrency() / 2); - m_tcp_server.get_config_object().m_pcommands_handler = &m_commands_handler; + m_tcp_server.get_config_object().set_handler(&m_commands_handler); m_tcp_server.get_config_object().m_invoke_timeout = CONNECTION_TIMEOUT; ASSERT_TRUE(m_tcp_server.init_server(clt_port, "127.0.0.1")); @@ -238,9 +238,10 @@ namespace static void TearDownTestCase() { // Stop server - test_levin_commands_handler commands_handler; - test_tcp_server tcp_server(epee::net_utils::e_connection_type_NET); - tcp_server.get_config_object().m_pcommands_handler = &commands_handler; + test_levin_commands_handler *commands_handler_ptr = new test_levin_commands_handler(); + test_levin_commands_handler &commands_handler = *commands_handler_ptr; + test_tcp_server tcp_server(epee::net_utils::e_connection_type_RPC); + tcp_server.get_config_object().set_handler(commands_handler_ptr, [](epee::levin::levin_commands_handler<test_connection_context> *handler)->void { delete handler; }); tcp_server.get_config_object().m_invoke_timeout = CONNECTION_TIMEOUT; if (!tcp_server.init_server(clt_port, "127.0.0.1")) return; @@ -627,6 +628,7 @@ TEST_F(net_load_test_clt, permament_open_and_close_and_connections_closed_by_ser int main(int argc, char** argv) { + tools::on_startup(); epee::debug::get_set_enable_assert(true, false); //set up logging options mlog_configure(mlog_get_default_log_path("net_load_tests_clt.log"), true); diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h index f74282683..ce9d8b6fe 100644 --- a/tests/net_load_tests/net_load_tests.h +++ b/tests/net_load_tests/net_load_tests.h @@ -151,6 +151,11 @@ namespace net_load_tests bool handle_new_connection(const boost::uuids::uuid& connection_id, bool ignore_close_fails = false) { size_t idx = m_next_opened_conn_idx.fetch_add(1, std::memory_order_relaxed); + if (idx >= m_connections.size()) + { + LOG_PRINT_L0("ERROR: connections overflow"); + exit(1); + } m_connections[idx] = connection_id; size_t prev_connection_count = m_opened_connection_count.fetch_add(1, std::memory_order_relaxed); diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp index e6dee1639..a987aa4e2 100644 --- a/tests/net_load_tests/srv.cpp +++ b/tests/net_load_tests/srv.cpp @@ -215,6 +215,7 @@ namespace int main(int argc, char** argv) { + tools::on_startup(); //set up logging options mlog_configure(mlog_get_default_log_path("net_load_tests_srv.log"), true); @@ -224,8 +225,8 @@ int main(int argc, char** argv) if (!tcp_server.init_server(srv_port, "127.0.0.1")) return 1; - srv_levin_commands_handler commands_handler(tcp_server); - tcp_server.get_config_object().m_pcommands_handler = &commands_handler; + srv_levin_commands_handler *commands_handler = new srv_levin_commands_handler(tcp_server); + tcp_server.get_config_object().set_handler(commands_handler, [](epee::levin::levin_commands_handler<test_connection_context> *handler) { delete handler; }); tcp_server.get_config_object().m_invoke_timeout = 10000; //tcp_server.get_config_object().m_max_packet_size = max_packet_size; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 3c0283eca..459eecba4 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -28,6 +28,7 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include "common/util.h" #include "performance_tests.h" #include "performance_utils.h" @@ -48,6 +49,7 @@ int main(int argc, char** argv) { + tools::on_startup(); set_process_affinity(1); set_thread_high_priority(); diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h index 061772cbd..6bf45ff83 100644 --- a/tests/performance_tests/performance_utils.h +++ b/tests/performance_tests/performance_utils.h @@ -40,7 +40,7 @@ void set_process_affinity(int core) { -#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun) return; #elif defined(BOOST_WINDOWS) DWORD_PTR mask = 1; @@ -62,7 +62,7 @@ void set_process_affinity(int core) void set_thread_high_priority() { -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun) return; #elif defined(BOOST_WINDOWS) ::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS); diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index c7efcf074..e10648d20 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -55,6 +55,7 @@ set(unit_tests_sources serialization.cpp sha256.cpp slow_memmem.cpp + subaddress.cpp test_tx_utils.cpp test_peerlist.cpp test_protocol_pack.cpp diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index d2aa31555..c749c2531 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -187,9 +187,11 @@ namespace typedef std::unique_ptr<test_connection> test_connection_ptr; - async_protocol_handler_test() + async_protocol_handler_test(): + m_pcommands_handler(new test_levin_commands_handler()), + m_commands_handler(*m_pcommands_handler) { - m_handler_config.m_pcommands_handler = &m_commands_handler; + m_handler_config.set_handler(m_pcommands_handler, [](epee::levin::levin_commands_handler<test_levin_connection_context> *handler) { delete handler; }); m_handler_config.m_invoke_timeout = invoke_timeout; m_handler_config.m_max_packet_size = max_packet_size; } @@ -212,7 +214,7 @@ namespace protected: boost::asio::io_service m_io_service; test_levin_protocol_handler_config m_handler_config; - test_levin_commands_handler m_commands_handler; + test_levin_commands_handler *m_pcommands_handler, &m_commands_handler; }; class positive_test_connection_to_levin_protocol_handler_calls : public async_protocol_handler_test diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index 2b0904224..c235f49fd 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -115,13 +115,13 @@ public: virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& details) {} virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t& details) {} - virtual uint64_t get_txpool_tx_count() const { return 0; } + virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const { return 0; } virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; } virtual void remove_txpool_tx(const crypto::hash& txid) {} virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const { return txpool_tx_meta_t(); } virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; } virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; } - virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const { return false; } + virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; } virtual void add_block( const block& blk , const size_t& block_size diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index 1706c43c9..86e7bcef3 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -35,6 +35,7 @@ #include "include_base_utils.h" #include "common/command_line.h" +#include "common/util.h" #include "unit_tests_utils.h" namespace po = boost::program_options; @@ -43,6 +44,7 @@ boost::filesystem::path unit_test::data_dir; int main(int argc, char** argv) { + tools::on_startup(); epee::string_tools::set_module_name_and_folder(argv[0]); mlog_configure(mlog_get_default_log_path("unit_tests.log"), true); epee::debug::get_set_enable_assert(true, false); @@ -51,7 +53,7 @@ int main(int argc, char** argv) po::options_description desc_options("Command line options"); const command_line::arg_descriptor<std::string> arg_data_dir = {"data-dir", "Data files directory", "", true}; - command_line::add_arg(desc_options, command_line::arg_data_dir, ""); + command_line::add_arg(desc_options, arg_data_dir, ""); po::variables_map vm; bool r = command_line::handle_error_helper(desc_options, [&]() @@ -64,7 +66,7 @@ int main(int argc, char** argv) return 1; if (vm["data-dir"].defaulted()) - unit_test::data_dir = boost::filesystem::path(epee::string_tools::get_current_module_folder()) + unit_test::data_dir = boost::filesystem::canonical(boost::filesystem::path(epee::string_tools::get_current_module_folder())) .parent_path().parent_path().parent_path().parent_path() .append("tests").append("data"); else diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp index 6ff73b107..ccca0b799 100644 --- a/tests/unit_tests/output_selection.cpp +++ b/tests/unit_tests/output_selection.cpp @@ -76,7 +76,7 @@ TEST(select_outputs, one_out_of_N) tools::wallet2::transfer_container transfers = make_transfers_container(10); transfers[6].m_block_height = 700; std::vector<size_t> unused_indices({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - std::list<size_t> selected; + std::vector<size_t> selected; SELECT(2); PICK(6); } @@ -93,7 +93,7 @@ TEST(select_outputs, order) transfers[3].m_block_height = 716; transfers[4].m_block_height = 701; std::vector<size_t> unused_indices({0, 1, 2, 3, 4}); - std::list<size_t> selected; + std::vector<size_t> selected; SELECT(0); PICK(3); // first the one that's far away PICK(2); // then the one that's close diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp index af6afa636..ef6151efb 100644 --- a/tests/unit_tests/ringct.cpp +++ b/tests/unit_tests/ringct.cpp @@ -38,6 +38,7 @@ #include "ringct/rctSigs.h" #include "ringct/rctOps.h" +using namespace std; using namespace crypto; using namespace rct; diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 011082d1c..0750ab7d1 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -49,6 +49,7 @@ #include "gtest/gtest.h" #include "unit_tests_utils.h" using namespace std; +using namespace crypto; struct Struct { diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp new file mode 100644 index 000000000..c304b7347 --- /dev/null +++ b/tests/unit_tests/subaddress.cpp @@ -0,0 +1,118 @@ +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include <boost/filesystem.hpp> +#include "gtest/gtest.h" + +#include "include_base_utils.h" +#include "wallet/wallet2.h" +#include "crypto/crypto.h" +#include "cryptonote_basic/account.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" +#include "wallet/api/subaddress.h" + +class WalletSubaddress : public ::testing::Test +{ + protected: + virtual void SetUp() + { + try + { + w1.generate(wallet_name, password, recovery_key, true, false); + } + catch (const std::exception& e) + { + LOG_ERROR("failed to generate wallet: " << e.what()); + throw e; + } + + w1.add_subaddress_account(test_label); + w1.set_subaddress_label(subaddress_index, test_label); + } + + virtual void TearDown() + { + boost::filesystem::wpath wallet_file(wallet_name); + boost::filesystem::wpath wallet_address_file(wallet_name + ".address.txt"); + boost::filesystem::wpath wallet_keys_file(wallet_name + ".keys"); + + if ( boost::filesystem::exists(wallet_file) ) + boost::filesystem::remove(wallet_file); + + if ( boost::filesystem::exists(wallet_address_file) ) + boost::filesystem::remove(wallet_address_file); + + if ( boost::filesystem::exists(wallet_keys_file) ) + boost::filesystem::remove(wallet_keys_file); + } + + tools::wallet2 w1; + std::string path_working_dir = "."; + std::string path_test_wallet = "test_wallet"; + const std::string wallet_name = path_working_dir + "/" + path_test_wallet; + const std::string password = "testpass"; + crypto::secret_key recovery_key = crypto::secret_key(); + const std::string test_label = "subaddress test label"; + + uint32_t major_index = 0; + uint32_t minor_index = 0; + const cryptonote::subaddress_index subaddress_index = {major_index, minor_index}; +}; + +TEST_F(WalletSubaddress, GetSubaddressLabel) +{ + EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index)); +} + +TEST_F(WalletSubaddress, AddSubaddress) +{ + std::string label = "test adding subaddress"; + w1.add_subaddress(0, label); + EXPECT_EQ(label, w1.get_subaddress_label({0, 1})); +} + +TEST_F(WalletSubaddress, OutOfBoundsIndexes) +{ + try + { + w1.get_subaddress_label({1,0}); + } + catch(const std::exception& e) + { + EXPECT_STREQ("index_major is out of bound", e.what()); + } + try + { + w1.get_subaddress_label({0,2}); + } + catch(const std::exception& e) + { + EXPECT_STREQ("index.minor is out of bound", e.what()); + } +} |