aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/long_term_block_weight.cpp46
-rw-r--r--tests/unit_tests/net.cpp103
-rw-r--r--tests/unit_tests/output_distribution.cpp12
-rw-r--r--tests/unit_tests/scaling_2021.cpp7
-rw-r--r--tests/unit_tests/wallet_storage.cpp266
6 files changed, 320 insertions, 115 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 57bd568fc..a9f0944c8 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -98,6 +98,7 @@ set(unit_tests_sources
output_selection.cpp
vercmp.cpp
ringdb.cpp
+ wallet_storage.cpp
wipeable_string.cpp
is_hdd.cpp
aligned.cpp
diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp
index b9ce2b247..5d954bf0c 100644
--- a/tests/unit_tests/long_term_block_weight.cpp
+++ b/tests/unit_tests/long_term_block_weight.cpp
@@ -106,16 +106,9 @@ static uint32_t lcg()
}
-struct BlockchainAndPool
-{
- cryptonote::tx_memory_pool txpool;
- cryptonote::Blockchain bc;
- BlockchainAndPool(): txpool(bc), bc(txpool) {}
-};
-
#define PREFIX_WINDOW(hf_version,window) \
- BlockchainAndPool bap; \
- cryptonote::Blockchain *bc = &bap.bc; \
+ cryptonote::BlockchainAndPool bap; \
+ cryptonote::Blockchain *bc = &bap.blockchain; \
struct get_test_options { \
const std::pair<uint8_t, uint64_t> hard_forks[3]; \
const cryptonote::test_options test_options = { \
@@ -407,3 +400,38 @@ TEST(long_term_block_weight, long_growth_spike_and_drop)
ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
ASSERT_LT(long_term_effective_median_block_weight, 300000 * 1.09);
}
+
+TEST(long_term_block_weight, cache_matches_true_value)
+{
+ PREFIX(16);
+
+ // Add big blocks to increase the block weight limit
+ for (uint64_t h = 0; h <= 2000; ++h)
+ {
+ size_t w = bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ bc->update_next_cumulative_weight_limit();
+ }
+
+ ASSERT_GT(bc->get_current_cumulative_block_weight_limit() * 10/17 , 300000);
+
+ // Add small blocks to the top of the chain
+ for (uint64_t h = 2000; h <= 5001; ++h)
+ {
+ size_t w = (bc->get_current_cumulative_block_weight_median() * 10/17) - 1000;
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ bc->update_next_cumulative_weight_limit();
+ }
+
+ // get the weight limit
+ uint64_t weight_limit = bc->get_current_cumulative_block_weight_limit();
+ // refresh the cache
+ bc->m_long_term_block_weights_cache_rolling_median.clear();
+ bc->get_long_term_block_weight_median(bc->get_db().height() - TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW, TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW);
+ bc->update_next_cumulative_weight_limit();
+
+ // make sure the weight limit is the same
+ ASSERT_EQ(weight_limit, bc->get_current_cumulative_block_weight_limit());
+}
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 03072b283..b9555b213 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -74,6 +74,8 @@ namespace
"xmrto2bturnore26.onion";
static constexpr const char v3_onion[] =
"vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion";
+ static constexpr const char v3_onion_2[] =
+ "zpv4fa3szgel7vf6jdjeugizdclq2vzkelscs2bhbgnlldzzggcen3ad.onion";
}
TEST(tor_address, constants)
@@ -94,12 +96,10 @@ TEST(tor_address, invalid)
EXPECT_TRUE(net::tor_address::make(":").has_error());
EXPECT_TRUE(net::tor_address::make(".onion").has_error());
EXPECT_TRUE(net::tor_address::make(".onion:").has_error());
- EXPECT_TRUE(net::tor_address::make(v2_onion + 1).has_error());
EXPECT_TRUE(net::tor_address::make(v3_onion + 1).has_error());
- EXPECT_TRUE(net::tor_address::make(boost::string_ref{v2_onion, sizeof(v2_onion) - 2}).has_error());
EXPECT_TRUE(net::tor_address::make(boost::string_ref{v3_onion, sizeof(v3_onion) - 2}).has_error());
- EXPECT_TRUE(net::tor_address::make(std::string{v2_onion} + ":-").has_error());
- EXPECT_TRUE(net::tor_address::make(std::string{v2_onion} + ":900a").has_error());
+ EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":-").has_error());
+ EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":900a").has_error());
EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":65536").has_error());
EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":-1").has_error());
@@ -163,11 +163,11 @@ TEST(tor_address, valid)
EXPECT_FALSE(address2.less(*address1));
EXPECT_FALSE(address1->less(address2));
- address2 = MONERO_UNWRAP(net::tor_address::make(std::string{v2_onion} + ":6545"));
+ address2 = MONERO_UNWRAP(net::tor_address::make(std::string{v3_onion_2} + ":6545"));
EXPECT_EQ(6545, address2.port());
- EXPECT_STREQ(v2_onion, address2.host_str());
- EXPECT_EQ(std::string{v2_onion} + ":6545", address2.str().c_str());
+ EXPECT_STREQ(v3_onion_2, address2.host_str());
+ EXPECT_EQ(std::string{v3_onion_2} + ":6545", address2.str().c_str());
EXPECT_TRUE(address2.is_blockable());
EXPECT_FALSE(address2.equal(*address1));
EXPECT_FALSE(address1->equal(address2));
@@ -244,57 +244,6 @@ namespace
};
}
-TEST(tor_address, epee_serializev_v2)
-{
- epee::byte_slice buffer{};
- {
- test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
- EXPECT_FALSE(command.tor.is_unknown());
- EXPECT_NE(net::tor_address{}, command.tor);
- EXPECT_STREQ(v2_onion, command.tor.host_str());
- EXPECT_EQ(10u, command.tor.port());
-
- epee::serialization::portable_storage stg{};
- EXPECT_TRUE(command.store(stg));
- EXPECT_TRUE(stg.store_to_binary(buffer));
- }
-
- test_command_tor command{};
- {
- EXPECT_TRUE(command.tor.is_unknown());
- EXPECT_EQ(net::tor_address{}, command.tor);
- EXPECT_STREQ(net::tor_address::unknown_str(), command.tor.host_str());
- EXPECT_EQ(0u, command.tor.port());
-
- epee::serialization::portable_storage stg{};
- EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
- EXPECT_TRUE(command.load(stg));
- }
- EXPECT_FALSE(command.tor.is_unknown());
- EXPECT_NE(net::tor_address{}, command.tor);
- EXPECT_STREQ(v2_onion, command.tor.host_str());
- EXPECT_EQ(10u, command.tor.port());
-
- // make sure that exceeding max buffer doesn't destroy tor_address::_load
- {
- epee::serialization::portable_storage stg{};
- stg.load_from_binary(epee::to_span(buffer));
-
- std::string host{};
- ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
- EXPECT_EQ(std::strlen(v2_onion), host.size());
-
- host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
- EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
- }
-
- EXPECT_TRUE(command.tor.is_unknown());
- EXPECT_EQ(net::tor_address{}, command.tor);
- EXPECT_STREQ(net::tor_address::unknown_str(), command.tor.host_str());
- EXPECT_EQ(0u, command.tor.port());
-}
-
TEST(tor_address, epee_serializev_v3)
{
epee::byte_slice buffer{};
@@ -397,41 +346,6 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_EQ(0u, command.tor.port());
}
-TEST(tor_address, boost_serialize_v2)
-{
- std::string buffer{};
- {
- const net::tor_address tor = MONERO_UNWRAP(net::tor_address::make(v2_onion, 10));
- EXPECT_FALSE(tor.is_unknown());
- EXPECT_NE(net::tor_address{}, tor);
- EXPECT_STREQ(v2_onion, tor.host_str());
- EXPECT_EQ(10u, tor.port());
-
- std::ostringstream stream{};
- {
- boost::archive::portable_binary_oarchive archive{stream};
- archive << tor;
- }
- buffer = stream.str();
- }
-
- net::tor_address tor{};
- {
- EXPECT_TRUE(tor.is_unknown());
- EXPECT_EQ(net::tor_address{}, tor);
- EXPECT_STREQ(net::tor_address::unknown_str(), tor.host_str());
- EXPECT_EQ(0u, tor.port());
-
- std::istringstream stream{buffer};
- boost::archive::portable_binary_iarchive archive{stream};
- archive >> tor;
- }
- EXPECT_FALSE(tor.is_unknown());
- EXPECT_NE(net::tor_address{}, tor);
- EXPECT_STREQ(v2_onion, tor.host_str());
- EXPECT_EQ(10u, tor.port());
-}
-
TEST(tor_address, boost_serialize_v3)
{
std::string buffer{};
@@ -511,6 +425,9 @@ TEST(get_network_address, onion)
address = net::get_network_address(".onion", 0);
EXPECT_EQ(net::error::invalid_tor_address, address);
+ address = net::get_network_address(v2_onion, 1000);
+ EXPECT_EQ(net::error::invalid_tor_address, address);
+
address = net::get_network_address(v3_onion, 1000);
ASSERT_TRUE(bool(address));
EXPECT_EQ(epee::net_utils::address_type::tor, address->get_type_id());
diff --git a/tests/unit_tests/output_distribution.cpp b/tests/unit_tests/output_distribution.cpp
index ab474a7d8..038c19874 100644
--- a/tests/unit_tests/output_distribution.cpp
+++ b/tests/unit_tests/output_distribution.cpp
@@ -30,10 +30,7 @@
#include "gtest/gtest.h"
#include "misc_log_ex.h"
#include "rpc/rpc_handler.h"
-#include "blockchain_db/blockchain_db.h"
#include "cryptonote_core/cryptonote_core.h"
-#include "cryptonote_core/tx_pool.h"
-#include "cryptonote_core/blockchain.h"
#include "blockchain_db/testdb.h"
static const uint64_t test_distribution[32] = {
@@ -77,9 +74,6 @@ public:
bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base)
{
- std::unique_ptr<cryptonote::Blockchain> bc;
- cryptonote::tx_memory_pool txpool(*bc);
- bc.reset(new cryptonote::Blockchain(txpool));
struct get_test_options {
const std::pair<uint8_t, uint64_t> hard_forks[2];
const cryptonote::test_options test_options = {
@@ -87,9 +81,9 @@ bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64
};
get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{}
} opts;
- cryptonote::Blockchain *blockchain = bc.get();
- bool r = blockchain->init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL);
- return r && bc->get_output_distribution(amount, from, to, start_height, distribution, base);
+ cryptonote::BlockchainAndPool bap;
+ bool r = bap.blockchain.init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL);
+ return r && bap.blockchain.get_output_distribution(amount, from, to, start_height, distribution, base);
}
crypto::hash get_block_hash(uint64_t height)
diff --git a/tests/unit_tests/scaling_2021.cpp b/tests/unit_tests/scaling_2021.cpp
index 024a4b4fd..d90f0f9e6 100644
--- a/tests/unit_tests/scaling_2021.cpp
+++ b/tests/unit_tests/scaling_2021.cpp
@@ -50,9 +50,6 @@ public:
}
#define PREFIX_WINDOW(hf_version,window) \
- std::unique_ptr<cryptonote::Blockchain> bc; \
- cryptonote::tx_memory_pool txpool(*bc); \
- bc.reset(new cryptonote::Blockchain(txpool)); \
struct get_test_options { \
const std::pair<uint8_t, uint64_t> hard_forks[3]; \
const cryptonote::test_options test_options = { \
@@ -61,7 +58,9 @@ public:
}; \
get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)1), std::make_pair((uint8_t)0, (uint64_t)0)} {} \
} opts; \
- cryptonote::Blockchain *blockchain = bc.get(); \
+ cryptonote::BlockchainAndPool bap; \
+ cryptonote::Blockchain *blockchain = &bap.blockchain; \
+ cryptonote::Blockchain *bc = blockchain; \
bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \
ASSERT_TRUE(r)
diff --git a/tests/unit_tests/wallet_storage.cpp b/tests/unit_tests/wallet_storage.cpp
new file mode 100644
index 000000000..dacaff960
--- /dev/null
+++ b/tests/unit_tests/wallet_storage.cpp
@@ -0,0 +1,266 @@
+// Copyright (c) 2023, 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.
+
+#include "unit_tests_utils.h"
+#include "gtest/gtest.h"
+
+#include "file_io_utils.h"
+#include "wallet/wallet2.h"
+
+using namespace boost::filesystem;
+using namespace epee::file_io_utils;
+
+static constexpr const char WALLET_00fd416a_PRIMARY_ADDRESS[] =
+ "45p2SngJAPSJbqSiUvYfS3BfhEdxZmv8pDt25oW1LzxrZv9Uq6ARagiFViMGUE3gJk5VPWingCXVf1p2tyAy6SUeSHPhbve";
+
+TEST(wallet_storage, store_to_file2file)
+{
+ const path source_wallet_file = unit_test::data_dir / "wallet_00fd416a";
+ const path interm_wallet_file = unit_test::data_dir / "wallet_00fd416a_copy_file2file";
+ const path target_wallet_file = unit_test::data_dir / "wallet_00fd416a_new_file2file";
+
+ ASSERT_TRUE(is_file_exist(source_wallet_file.string()));
+ ASSERT_TRUE(is_file_exist(source_wallet_file.string() + ".keys"));
+
+ copy_file(source_wallet_file, interm_wallet_file, copy_option::overwrite_if_exists);
+ copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys", copy_option::overwrite_if_exists);
+
+ ASSERT_TRUE(is_file_exist(interm_wallet_file.string()));
+ ASSERT_TRUE(is_file_exist(interm_wallet_file.string() + ".keys"));
+
+ 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"));
+
+ epee::wipeable_string password("beepbeep");
+
+ const auto files_are_expected = [&]()
+ {
+ EXPECT_FALSE(is_file_exist(interm_wallet_file.string()));
+ EXPECT_FALSE(is_file_exist(interm_wallet_file.string() + ".keys"));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+ };
+
+ {
+ tools::wallet2 w;
+ w.load(interm_wallet_file.string(), password);
+ const std::string primary_address = w.get_address_as_str();
+ EXPECT_EQ(WALLET_00fd416a_PRIMARY_ADDRESS, primary_address);
+ w.store_to(target_wallet_file.string(), password);
+ files_are_expected();
+ }
+
+ files_are_expected();
+
+ {
+ tools::wallet2 w;
+ w.load(target_wallet_file.string(), password);
+ const std::string primary_address = w.get_address_as_str();
+ EXPECT_EQ(WALLET_00fd416a_PRIMARY_ADDRESS, primary_address);
+ w.store_to("", "");
+ files_are_expected();
+ }
+
+ files_are_expected();
+}
+
+TEST(wallet_storage, store_to_mem2file)
+{
+ const path target_wallet_file = unit_test::data_dir / "wallet_mem2file";
+
+ 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"));
+
+ epee::wipeable_string password("beepbeep2");
+
+ {
+ tools::wallet2 w;
+ w.generate("", password);
+ w.store_to(target_wallet_file.string(), password);
+
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+ }
+
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+
+ {
+ tools::wallet2 w;
+ w.load(target_wallet_file.string(), password);
+
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+ }
+
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+}
+
+TEST(wallet_storage, change_password_same_file)
+{
+ const path source_wallet_file = unit_test::data_dir / "wallet_00fd416a";
+ const path interm_wallet_file = unit_test::data_dir / "wallet_00fd416a_copy_change_password_same";
+
+ ASSERT_TRUE(is_file_exist(source_wallet_file.string()));
+ ASSERT_TRUE(is_file_exist(source_wallet_file.string() + ".keys"));
+
+ copy_file(source_wallet_file, interm_wallet_file, copy_option::overwrite_if_exists);
+ copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys", copy_option::overwrite_if_exists);
+
+ ASSERT_TRUE(is_file_exist(interm_wallet_file.string()));
+ ASSERT_TRUE(is_file_exist(interm_wallet_file.string() + ".keys"));
+
+ epee::wipeable_string old_password("beepbeep");
+ epee::wipeable_string new_password("meepmeep");
+
+ {
+ tools::wallet2 w;
+ w.load(interm_wallet_file.string(), old_password);
+ const std::string primary_address = w.get_address_as_str();
+ EXPECT_EQ(WALLET_00fd416a_PRIMARY_ADDRESS, primary_address);
+ w.change_password(w.get_wallet_file(), old_password, new_password);
+ }
+
+ {
+ tools::wallet2 w;
+ w.load(interm_wallet_file.string(), new_password);
+ const std::string primary_address = w.get_address_as_str();
+ EXPECT_EQ(WALLET_00fd416a_PRIMARY_ADDRESS, primary_address);
+ }
+
+ {
+ tools::wallet2 w;
+ EXPECT_THROW(w.load(interm_wallet_file.string(), old_password), tools::error::invalid_password);
+ }
+}
+
+TEST(wallet_storage, change_password_different_file)
+{
+ const path source_wallet_file = unit_test::data_dir / "wallet_00fd416a";
+ const path interm_wallet_file = unit_test::data_dir / "wallet_00fd416a_copy_change_password_diff";
+ const path target_wallet_file = unit_test::data_dir / "wallet_00fd416a_new_change_password_diff";
+
+ ASSERT_TRUE(is_file_exist(source_wallet_file.string()));
+ ASSERT_TRUE(is_file_exist(source_wallet_file.string() + ".keys"));
+
+ copy_file(source_wallet_file, interm_wallet_file, copy_option::overwrite_if_exists);
+ copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys", copy_option::overwrite_if_exists);
+
+ ASSERT_TRUE(is_file_exist(interm_wallet_file.string()));
+ ASSERT_TRUE(is_file_exist(interm_wallet_file.string() + ".keys"));
+
+ 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"));
+
+ epee::wipeable_string old_password("beepbeep");
+ epee::wipeable_string new_password("meepmeep");
+
+ {
+ tools::wallet2 w;
+ w.load(interm_wallet_file.string(), old_password);
+ const std::string primary_address = w.get_address_as_str();
+ EXPECT_EQ(WALLET_00fd416a_PRIMARY_ADDRESS, primary_address);
+ w.change_password(target_wallet_file.string(), old_password, new_password);
+ }
+
+ EXPECT_FALSE(is_file_exist(interm_wallet_file.string()));
+ EXPECT_FALSE(is_file_exist(interm_wallet_file.string() + ".keys"));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+
+ {
+ tools::wallet2 w;
+ w.load(target_wallet_file.string(), new_password);
+ const std::string primary_address = w.get_address_as_str();
+ EXPECT_EQ(WALLET_00fd416a_PRIMARY_ADDRESS, primary_address);
+ }
+}
+
+TEST(wallet_storage, change_password_in_memory)
+{
+ const epee::wipeable_string password1("monero");
+ const epee::wipeable_string password2("means money");
+ const epee::wipeable_string password_wrong("is traceable");
+
+ tools::wallet2 w;
+ w.generate("", password1);
+ const std::string primary_address_1 = w.get_address_as_str();
+ w.change_password("", password1, password2);
+ const std::string primary_address_2 = w.get_address_as_str();
+ EXPECT_EQ(primary_address_1, primary_address_2);
+
+ EXPECT_THROW(w.change_password("", password_wrong, password1), tools::error::invalid_password);
+}
+
+TEST(wallet_storage, change_password_mem2file)
+{
+ const path target_wallet_file = unit_test::data_dir / "wallet_change_password_mem2file";
+
+ 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 password1("https://safecurves.cr.yp.to/rigid.html");
+ const epee::wipeable_string password2(
+ "https://csrc.nist.gov/csrc/media/projects/crypto-standards-development-process/documents/dualec_in_x982_and_sp800-90.pdf");
+
+ std::string primary_address_1, primary_address_2;
+ {
+ tools::wallet2 w;
+ w.generate("", password1);
+ primary_address_1 = w.get_address_as_str();
+ w.change_password(target_wallet_file.string(), password1, password2);
+ }
+
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+
+ {
+ tools::wallet2 w;
+ w.load(target_wallet_file.string(), password2);
+ primary_address_2 = w.get_address_as_str();
+ }
+
+ EXPECT_EQ(primary_address_1, primary_address_2);
+}