diff options
Diffstat (limited to '')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/core_tests/wallet_tools.cpp | 7 | ||||
-rw-r--r-- | tests/performance_tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/unit_tests/main.cpp | 2 | ||||
-rw-r--r-- | tests/unit_tests/wallet_storage.cpp | 117 |
6 files changed, 125 insertions, 5 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 00896818c..736872b04 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ set(MONERO_WALLET_CRYPTO_BENCH "auto" CACHE STRING "Select wallet crypto librari # The docs say this only affects grouping in IDEs set(folder "tests") -set(TEST_DATA_DIR "${CMAKE_CURRENT_LIST_DIR}/data") +set(TEST_DATA_DIR "${CMAKE_CURRENT_BINARY_DIR}/data") if (WIN32 AND STATIC) add_definitions(-DSTATICLIB) diff --git a/tests/core_tests/wallet_tools.cpp b/tests/core_tests/wallet_tools.cpp index 5378b0254..ee29fdad1 100644 --- a/tests/core_tests/wallet_tools.cpp +++ b/tests/core_tests/wallet_tools.cpp @@ -4,7 +4,6 @@ #include "wallet_tools.h" #include <random> -#include <boost/assign.hpp> using namespace std; using namespace epee; @@ -39,7 +38,8 @@ void wallet_accessor_test::process_parsed_blocks(tools::wallet2 * wallet, uint64 void wallet_tools::process_transactions(tools::wallet2 * wallet, const std::vector<test_event_entry>& events, const cryptonote::block& blk_head, block_tracker &bt, const boost::optional<crypto::hash>& blk_tail) { - process_transactions(boost::assign::list_of(wallet), events, blk_head, bt, blk_tail); + std::vector<tools::wallet2*> wallet_vector = { wallet }; + process_transactions(wallet_vector, events, blk_head, bt, blk_tail); } void wallet_tools::process_transactions(const std::vector<tools::wallet2*>& wallets, const std::vector<test_event_entry>& events, const cryptonote::block& blk_head, block_tracker &bt, const boost::optional<crypto::hash>& blk_tail) @@ -56,7 +56,8 @@ void wallet_tools::process_transactions(const std::vector<tools::wallet2*>& wall } void wallet_tools::process_transactions(tools::wallet2 * wallet, const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t & mtx, block_tracker &bt){ - process_transactions(boost::assign::list_of(wallet), blockchain, mtx, bt); + std::vector<tools::wallet2*> wallet_vector = { wallet }; + process_transactions(wallet_vector, blockchain, mtx, bt); } void wallet_tools::process_transactions(const std::vector<tools::wallet2*>& wallets, const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t & mtx, block_tracker &bt) diff --git a/tests/performance_tests/CMakeLists.txt b/tests/performance_tests/CMakeLists.txt index 7462f7119..5dd278c6f 100644 --- a/tests/performance_tests/CMakeLists.txt +++ b/tests/performance_tests/CMakeLists.txt @@ -67,6 +67,7 @@ target_link_libraries(performance_tests common cncrypto epee + seraphis_crypto ${Boost_CHRONO_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBRARIES}) diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 40f37c4ed..212f834d2 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -123,6 +123,7 @@ target_link_libraries(unit_tests rpc net serialization + seraphis_crypto wallet p2p version diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index 586cb7c60..4094d79b7 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char** argv) ::testing::InitGoogleTest(&argc, argv); // the default test data directory is ../data (relative to the executable's directory) - const auto default_test_data_dir = boost::filesystem::path(argv[0]).parent_path().parent_path() / "data"; + const auto default_test_data_dir = boost::filesystem::canonical(argv[0]).parent_path().parent_path() / "data"; po::options_description desc_options("Command line options"); const command_line::arg_descriptor<std::string> arg_data_dir = { "data-dir", "Data files directory", default_test_data_dir.string() }; diff --git a/tests/unit_tests/wallet_storage.cpp b/tests/unit_tests/wallet_storage.cpp index dacaff960..ff01e452c 100644 --- a/tests/unit_tests/wallet_storage.cpp +++ b/tests/unit_tests/wallet_storage.cpp @@ -29,6 +29,8 @@ #include "unit_tests_utils.h" #include "gtest/gtest.h" +#include <cctype> + #include "file_io_utils.h" #include "wallet/wallet2.h" @@ -38,6 +40,9 @@ using namespace epee::file_io_utils; static constexpr const char WALLET_00fd416a_PRIMARY_ADDRESS[] = "45p2SngJAPSJbqSiUvYfS3BfhEdxZmv8pDt25oW1LzxrZv9Uq6ARagiFViMGUE3gJk5VPWingCXVf1p2tyAy6SUeSHPhbve"; +// https://github.com/monero-project/monero/blob/67d190ce7c33602b6a3b804f633ee1ddb7fbb4a1/src/wallet/wallet2.cpp#L156 +static constexpr const char WALLET2_ASCII_OUTPUT_MAGIC[] = "MoneroAsciiDataV1"; + TEST(wallet_storage, store_to_file2file) { const path source_wallet_file = unit_test::data_dir / "wallet_00fd416a"; @@ -264,3 +269,115 @@ TEST(wallet_storage, change_password_mem2file) EXPECT_EQ(primary_address_1, primary_address_2); } + +TEST(wallet_storage, gen_ascii_format) +{ + const path target_wallet_file = unit_test::data_dir / "wallet_gen_ascii_format"; + + if (is_file_exist(target_wallet_file.string())) + remove(target_wallet_file); + if (is_file_exist(target_wallet_file.string() + ".keys")) + remove(target_wallet_file.string() + ".keys"); + ASSERT_FALSE(is_file_exist(target_wallet_file.string())); + ASSERT_FALSE(is_file_exist(target_wallet_file.string() + ".keys")); + + const epee::wipeable_string password("https://safecurves.cr.yp.to/rigid.html"); + + std::string primary_address_1, primary_address_2; + { + tools::wallet2 w; + w.set_export_format(tools::wallet2::Ascii); + ASSERT_EQ(tools::wallet2::Ascii, w.export_format()); + w.generate(target_wallet_file.string(), password); + primary_address_1 = w.get_address_as_str(); + } + + ASSERT_TRUE(is_file_exist(target_wallet_file.string())); + ASSERT_TRUE(is_file_exist(target_wallet_file.string() + ".keys")); + + // Assert that we store keys in ascii format + { + std::string key_file_contents; + ASSERT_TRUE(epee::file_io_utils::load_file_to_string(target_wallet_file.string() + ".keys", key_file_contents)); + EXPECT_NE(std::string::npos, key_file_contents.find(WALLET2_ASCII_OUTPUT_MAGIC)); + for (const char c : key_file_contents) + ASSERT_TRUE(std::isprint(c) || c == '\n' || c == '\r'); + } + + { + tools::wallet2 w; + w.set_export_format(tools::wallet2::Ascii); + ASSERT_EQ(tools::wallet2::Ascii, w.export_format()); + w.load(target_wallet_file.string(), password); + primary_address_2 = w.get_address_as_str(); + } + + EXPECT_EQ(primary_address_1, primary_address_2); +} + +TEST(wallet_storage, change_export_format) +{ + const path target_wallet_file = unit_test::data_dir / "wallet_change_export_format"; + + if (is_file_exist(target_wallet_file.string())) + remove(target_wallet_file); + if (is_file_exist(target_wallet_file.string() + ".keys")) + remove(target_wallet_file.string() + ".keys"); + ASSERT_FALSE(is_file_exist(target_wallet_file.string())); + ASSERT_FALSE(is_file_exist(target_wallet_file.string() + ".keys")); + + const epee::wipeable_string password("https://safecurves.cr.yp.to/rigid.html"); + + std::string primary_address_1, primary_address_2; + { + tools::wallet2 w; + ASSERT_EQ(tools::wallet2::Binary, w.export_format()); + w.generate(target_wallet_file.string(), password); + primary_address_1 = w.get_address_as_str(); + w.store(); + + // Assert that we initially store keys in binary format + { + std::string key_file_contents; + ASSERT_TRUE(epee::file_io_utils::load_file_to_string(target_wallet_file.string() + ".keys", key_file_contents)); + EXPECT_EQ(std::string::npos, key_file_contents.find(WALLET2_ASCII_OUTPUT_MAGIC)); + bool only_printable = true; + for (const char c : key_file_contents) + { + if (!std::isprint(c) && c != '\n' && c != '\r') + { + only_printable = false; + break; + } + } + EXPECT_FALSE(only_printable); + } + + // switch formats and store + w.set_export_format(tools::wallet2::Ascii); + ASSERT_EQ(tools::wallet2::Ascii, w.export_format()); + w.store_to("", password, /*force_rewrite_keys=*/ true); + } + + ASSERT_TRUE(is_file_exist(target_wallet_file.string())); + ASSERT_TRUE(is_file_exist(target_wallet_file.string() + ".keys")); + + // Assert that we store keys in ascii format + { + std::string key_file_contents; + ASSERT_TRUE(epee::file_io_utils::load_file_to_string(target_wallet_file.string() + ".keys", key_file_contents)); + EXPECT_NE(std::string::npos, key_file_contents.find(WALLET2_ASCII_OUTPUT_MAGIC)); + for (const char c : key_file_contents) + ASSERT_TRUE(std::isprint(c) || c == '\n' || c == '\r'); + } + + { + tools::wallet2 w; + w.set_export_format(tools::wallet2::Ascii); + ASSERT_EQ(tools::wallet2::Ascii, w.export_format()); + w.load(target_wallet_file.string(), password); + primary_address_2 = w.get_address_as_str(); + } + + EXPECT_EQ(primary_address_1, primary_address_2); +} |