aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt10
-rw-r--r--tests/data/wallet_00fd416abin0 -> 2329810 bytes
-rw-r--r--tests/data/wallet_00fd416a.keysbin0 -> 1679 bytes
-rwxr-xr-xtests/functional_tests/multisig.py129
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/long_term_block_weight.cpp35
-rw-r--r--tests/unit_tests/wallet_storage.cpp266
7 files changed, 349 insertions, 92 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2cabb1ba5..e074ceed6 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -72,14 +72,8 @@ else ()
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest/include")
endif (GTest_FOUND)
-file(COPY
- data/wallet_9svHk1.keys
- data/wallet_9svHk1
- data/outputs
- data/unsigned_monero_tx
- data/signed_monero_tx
- data/sha256sum
- DESTINATION data)
+message(STATUS "Copying test data directory...")
+file(COPY data DESTINATION .) # Copy data directory from source root to build root
if (CMAKE_BUILD_TYPE STREQUAL "fuzz" OR OSSFUZZ)
add_subdirectory(fuzz)
diff --git a/tests/data/wallet_00fd416a b/tests/data/wallet_00fd416a
new file mode 100644
index 000000000..a1b7898e6
--- /dev/null
+++ b/tests/data/wallet_00fd416a
Binary files differ
diff --git a/tests/data/wallet_00fd416a.keys b/tests/data/wallet_00fd416a.keys
new file mode 100644
index 000000000..6908cce1b
--- /dev/null
+++ b/tests/data/wallet_00fd416a.keys
Binary files differ
diff --git a/tests/functional_tests/multisig.py b/tests/functional_tests/multisig.py
index 980adc2df..3da983d69 100755
--- a/tests/functional_tests/multisig.py
+++ b/tests/functional_tests/multisig.py
@@ -37,100 +37,61 @@ import random
from framework.daemon import Daemon
from framework.wallet import Wallet
-MULTISIG_PUB_ADDRS = [
- '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG', # 2/2
- '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i', # 2/3
- '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP', # 3/3
- '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff', # 3/4
- '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U', # 2/4
- '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB' # 1/2
+TEST_CASES = \
+[
+# M N Primary Address
+ [2, 2, '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG'],
+ [2, 3, '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i'],
+ [3, 3, '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP'],
+ [3, 4, '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff'],
+ [2, 4, '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U'],
+ [1, 2, '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB']
]
+PUB_ADDRS = [case[2] for case in TEST_CASES]
+
class MultisigTest():
def run_test(self):
self.reset()
- for pub_addr in MULTISIG_PUB_ADDRS:
- self.mine(pub_addr, 4)
+ for pub_addr in PUB_ADDRS:
+ self.mine(pub_addr, 4)
self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
self.test_states()
- self.fund_addrs_with_normal_wallet(MULTISIG_PUB_ADDRS)
-
- self.create_multisig_wallets(2, 2, '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG')
- self.import_multisig_info([1, 0], 5)
- txid = self.transfer([1, 0])
- self.import_multisig_info([0, 1], 6)
- self.check_transaction(txid)
-
- self.remake_some_multisig_wallets_by_multsig_seed(2)
- self.import_multisig_info([0, 1], 6) # six outputs, same as before
- txid = self.transfer([0, 1])
- self.import_multisig_info([0, 1], 7) # seven outputs b/c we're dest plus change
- self.check_transaction(txid)
-
- self.create_multisig_wallets(2, 3, '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i')
- self.import_multisig_info([0, 2], 5)
- txid = self.transfer([0, 2])
- self.import_multisig_info([0, 1, 2], 6)
- self.check_transaction(txid)
-
- self.remake_some_multisig_wallets_by_multsig_seed(2)
- self.import_multisig_info([0, 2], 6) # six outputs, same as before
- txid = self.transfer([0, 2])
- self.import_multisig_info([0, 1, 2], 7) # seven outputs b/c we're dest plus change
- self.check_transaction(txid)
-
- self.create_multisig_wallets(3, 3, '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP')
- self.import_multisig_info([2, 0, 1], 5)
- txid = self.transfer([2, 1, 0])
- self.import_multisig_info([0, 2, 1], 6)
- self.check_transaction(txid)
-
- self.remake_some_multisig_wallets_by_multsig_seed(3)
- self.import_multisig_info([2, 0, 1], 6) # six outputs, same as before
- txid = self.transfer([2, 1, 0])
- self.import_multisig_info([0, 2, 1], 7) # seven outputs b/c we're dest plus change
- self.check_transaction(txid)
-
- self.create_multisig_wallets(3, 4, '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff')
- self.import_multisig_info([0, 2, 3], 5)
- txid = self.transfer([0, 2, 3])
- self.import_multisig_info([0, 1, 2, 3], 6)
- self.check_transaction(txid)
+ self.fund_addrs_with_normal_wallet(PUB_ADDRS)
- self.remake_some_multisig_wallets_by_multsig_seed(3)
- self.import_multisig_info([0, 2, 3], 6) # six outputs, same as before
- txid = self.transfer([0, 2, 3])
- self.import_multisig_info([0, 1, 2, 3], 7) # seven outputs b/c we're dest plus change
- self.check_transaction(txid)
+ for M, N, pub_addr in TEST_CASES:
+ assert M <= N
+ shuffled_participants = list(range(N))
+ random.shuffle(shuffled_participants)
+ shuffled_signers = shuffled_participants[:M]
- self.create_multisig_wallets(2, 4, '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U')
- self.import_multisig_info([1, 2], 5)
- txid = self.transfer([1, 2])
- self.import_multisig_info([0, 1, 2, 3], 6)
- self.check_transaction(txid)
- txid = self.try_transfer_frozen([2, 3])
- self.import_multisig_info([0, 1, 2, 3], 7)
- self.check_transaction(txid)
+ expected_outputs = 5 # each wallet owns four mined outputs & one transferred output
- self.remake_some_multisig_wallets_by_multsig_seed(2)
- self.import_multisig_info([0, 1, 2, 3], 6) # six outputs, same as before
- txid = self.transfer([2, 3])
- self.import_multisig_info([0, 1, 2, 3], 7) # seven outputs b/c we're dest plus change
- self.check_transaction(txid)
+ # Create multisig wallet and test transferring
+ self.create_multisig_wallets(M, N, pub_addr)
+ self.import_multisig_info(shuffled_signers if M != 1 else shuffled_participants, expected_outputs)
+ txid = self.transfer(shuffled_signers)
+ expected_outputs += 1
+ self.import_multisig_info(shuffled_participants, expected_outputs)
+ self.check_transaction(txid)
- self.create_multisig_wallets(1, 2, '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB')
- self.import_multisig_info([0, 1], 5)
- txid = self.transfer([0])
- self.import_multisig_info([0, 1], 6)
- self.check_transaction(txid)
+ # If more than 1 signer, try to freeze key image of one signer, make tx using that key
+ # image on another signer, then have first signer sign multisg_txset. Should fail
+ if M != 1:
+ txid = self.try_transfer_frozen(shuffled_signers)
+ expected_outputs += 1
+ self.import_multisig_info(shuffled_participants, expected_outputs)
+ self.check_transaction(txid)
- self.remake_some_multisig_wallets_by_multsig_seed(1)
- self.import_multisig_info([0, 1], 6) # six outputs, same as before
- txid = self.transfer([1])
- self.import_multisig_info([0, 1], 7) # seven outputs b/c we're dest plus change
- self.check_transaction(txid)
+ # Recreate wallet from multisig seed and test transferring
+ self.remake_some_multisig_wallets_by_multsig_seed(M)
+ self.import_multisig_info(shuffled_signers if M != 1 else shuffled_participants, expected_outputs)
+ txid = self.transfer(shuffled_signers)
+ expected_outputs += 1
+ self.import_multisig_info(shuffled_participants, expected_outputs)
+ self.check_transaction(txid)
def reset(self):
print('Resetting blockchain')
@@ -262,10 +223,10 @@ class MultisigTest():
def remake_some_multisig_wallets_by_multsig_seed(self, threshold):
N = len(self.wallet)
- signers_to_remake = set()
num_signers_to_remake = random.randint(1, N) # Do at least one
- while len(signers_to_remake) < num_signers_to_remake:
- signers_to_remake.add(random.randint(0, N - 1))
+ signers_to_remake = list(range(N))
+ random.shuffle(signers_to_remake)
+ signers_to_remake = signers_to_remake[:num_signers_to_remake]
for i in signers_to_remake:
print("Remaking {}/{} multsig wallet from multisig seed: #{}".format(threshold, N, i+1))
@@ -501,7 +462,7 @@ class MultisigTest():
print("Attemping to sign with frozen key image. This should fail")
try:
res = self.wallet[signers[1]].sign_multisig(multisig_txset)
- raise ValueError('sign_multisig should not have succeeded w/ fronzen enotes')
+ raise ValueError('sign_multisig should not have succeeded w/ frozen enotes')
except AssertionError:
pass
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 147b38dd4..fec36803e 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -97,6 +97,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 973055097..57740cf9d 100644
--- a/tests/unit_tests/long_term_block_weight.cpp
+++ b/tests/unit_tests/long_term_block_weight.cpp
@@ -407,3 +407,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/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);
+}