Skip to content

Commit

Permalink
Fix unique directories usage in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jan 17, 2024
1 parent e591d13 commit bc1a4a4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
1 change: 1 addition & 0 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ TEST (mdb_block_store, bad_path)
try
{
auto path = nano::unique_path ();
path /= "data.ldb";
{
std::ofstream stream (path.c_str ());
}
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4310,7 +4310,7 @@ TEST (node_config, node_id_private_key_persistence)

// create the directory and the file
auto path = nano::unique_path ();
ASSERT_TRUE (std::filesystem::create_directories (path));
ASSERT_TRUE (std::filesystem::exists (path));
auto priv_key_filename = path / "node_id_private.key";

// check that the key generated is random when the key does not exist
Expand Down
38 changes: 19 additions & 19 deletions nano/core_test/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ unsigned constexpr nano::wallet_store::version_current;
TEST (wallet, no_special_keys_accounts)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -36,7 +36,7 @@ TEST (wallet, no_special_keys_accounts)
TEST (wallet, no_key)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -51,7 +51,7 @@ TEST (wallet, no_key)
TEST (wallet, fetch_locked)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -73,7 +73,7 @@ TEST (wallet, fetch_locked)
TEST (wallet, retrieval)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -95,7 +95,7 @@ TEST (wallet, retrieval)
TEST (wallet, empty_iteration)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -109,7 +109,7 @@ TEST (wallet, empty_iteration)
TEST (wallet, one_item_iteration)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -131,7 +131,7 @@ TEST (wallet, one_item_iteration)
TEST (wallet, two_item_iteration)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
nano::keypair key1;
nano::keypair key2;
Expand Down Expand Up @@ -270,7 +270,7 @@ TEST (wallet, spend_no_previous)
TEST (wallet, find_none)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -283,7 +283,7 @@ TEST (wallet, find_none)
TEST (wallet, find_existing)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -302,7 +302,7 @@ TEST (wallet, find_existing)
TEST (wallet, rekey)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -374,7 +374,7 @@ TEST (account, encode_fail)
TEST (wallet, hash_password)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -423,7 +423,7 @@ TEST (fan, change)
TEST (wallet, reopen_default_password)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
auto transaction (env.tx_begin_write ());
ASSERT_FALSE (init);
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -459,7 +459,7 @@ TEST (wallet, reopen_default_password)
TEST (wallet, representative)
{
auto error (false);
nano::store::lmdb::env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -480,7 +480,7 @@ TEST (wallet, representative)
TEST (wallet, serialize_json_empty)
{
auto error (false);
nano::store::lmdb::env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -505,7 +505,7 @@ TEST (wallet, serialize_json_empty)
TEST (wallet, serialize_json_one)
{
auto error (false);
nano::store::lmdb::env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -534,7 +534,7 @@ TEST (wallet, serialize_json_one)
TEST (wallet, serialize_json_password)
{
auto error (false);
nano::store::lmdb::env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -567,7 +567,7 @@ TEST (wallet, serialize_json_password)
TEST (wallet_store, move)
{
auto error (false);
nano::store::lmdb::env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -725,7 +725,7 @@ TEST (wallet, insert_locked)
TEST (wallet, deterministic_keys)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -768,7 +768,7 @@ TEST (wallet, deterministic_keys)
TEST (wallet, reseed)
{
bool init;
nano::store::lmdb::env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path () / "wallet.ldb");
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down
12 changes: 3 additions & 9 deletions nano/secure/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ std::filesystem::path nano::unique_path (nano::networks network)
}

auto result = working_path (network) / random_string;

std::filesystem::create_directories (result);

all_unique_paths.push_back (result);
return result;
}
Expand All @@ -60,15 +63,6 @@ void nano::remove_temporary_directories ()
{
std::cerr << "Could not remove temporary directory: " << ec.message () << std::endl;
}

// lmdb creates a -lock suffixed file for its MDB_NOSUBDIR databases
auto lockfile = path;
lockfile += "-lock";
std::filesystem::remove (lockfile, ec);
if (ec)
{
std::cerr << "Could not remove temporary lock file: " << ec.message () << std::endl;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions nano/store/lmdb/lmdb_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ nano::store::lmdb::env::env (bool & error_a, std::filesystem::path const & path_

void nano::store::lmdb::env::init (bool & error_a, std::filesystem::path const & path_a, nano::store::lmdb::env::options options_a)
{
debug_assert (path_a.extension () == ".ldb", "invalid filename extension for lmdb database file");

boost::system::error_code error_mkdir, error_chmod;
if (path_a.has_parent_path ())
{
Expand Down

0 comments on commit bc1a4a4

Please sign in to comment.