Skip to content

Commit f94f939

Browse files
committed
test: Remove legacy wallet unit tests
1 parent d9ac9db commit f94f939

File tree

4 files changed

+19
-469
lines changed

4 files changed

+19
-469
lines changed

src/bench/wallet_ismine.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <addresstype.h>
66
#include <bench/bench.h>
7-
#include <bitcoin-build-config.h> // IWYU pragma: keep
87
#include <key.h>
98
#include <key_io.h>
109
#include <script/descriptor.h>
@@ -26,7 +25,7 @@
2625
#include <utility>
2726

2827
namespace wallet {
29-
static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_combo = 0)
28+
static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0)
3029
{
3130
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
3231

@@ -36,16 +35,13 @@ static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_co
3635

3736
// Setup the wallet
3837
// Loading the wallet will also create it
39-
uint64_t create_flags = 0;
40-
if (!legacy_wallet) {
41-
create_flags = WALLET_FLAG_DESCRIPTORS;
42-
}
38+
uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
4339
auto database = CreateMockableWalletDatabase();
4440
auto wallet = TestLoadWallet(std::move(database), context, create_flags);
4541

4642
// For a descriptor wallet, fill with num_combo combo descriptors with random keys
4743
// This benchmarks a non-HD wallet migrated to descriptors
48-
if (!legacy_wallet && num_combo > 0) {
44+
if (num_combo > 0) {
4945
LOCK(wallet->cs_wallet);
5046
for (int i = 0; i < num_combo; ++i) {
5147
CKey key;
@@ -70,13 +66,8 @@ static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_co
7066
TestUnloadWallet(std::move(wallet));
7167
}
7268

73-
#ifdef USE_BDB
74-
static void WalletIsMineLegacy(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/true); }
75-
BENCHMARK(WalletIsMineLegacy, benchmark::PriorityLevel::LOW);
76-
#endif
77-
78-
static void WalletIsMineDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/false); }
79-
static void WalletIsMineMigratedDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/false, /*num_combo=*/2000); }
69+
static void WalletIsMineDescriptors(benchmark::Bench& bench) { WalletIsMine(bench); }
70+
static void WalletIsMineMigratedDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*num_combo=*/2000); }
8071
BENCHMARK(WalletIsMineDescriptors, benchmark::PriorityLevel::LOW);
8172
BENCHMARK(WalletIsMineMigratedDescriptors, benchmark::PriorityLevel::LOW);
8273
} // namespace wallet

src/wallet/test/db_tests.cpp

Lines changed: 8 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <bitcoin-build-config.h> // IWYU pragma: keep
6-
75
#include <boost/test/unit_test.hpp>
86

97
#include <test/util/setup_common.h>
108
#include <util/check.h>
119
#include <util/fs.h>
1210
#include <util/translation.h>
13-
#ifdef USE_BDB
14-
#include <wallet/bdb.h>
15-
#endif
1611
#include <wallet/sqlite.h>
1712
#include <wallet/migrate.h>
1813
#include <wallet/test/util.h>
@@ -60,82 +55,13 @@ static void CheckPrefix(DatabaseBatch& batch, std::span<const std::byte> prefix,
6055

6156
BOOST_FIXTURE_TEST_SUITE(db_tests, BasicTestingSetup)
6257

63-
#ifdef USE_BDB
64-
static std::shared_ptr<BerkeleyEnvironment> GetWalletEnv(const fs::path& path, fs::path& database_filename)
65-
{
66-
fs::path data_file = BDBDataFile(path);
67-
database_filename = data_file.filename();
68-
return GetBerkeleyEnv(data_file.parent_path(), false);
69-
}
70-
71-
BOOST_AUTO_TEST_CASE(getwalletenv_file)
72-
{
73-
fs::path test_name = "test_name.dat";
74-
const fs::path datadir = m_args.GetDataDirNet();
75-
fs::path file_path = datadir / test_name;
76-
std::ofstream f{file_path};
77-
f.close();
78-
79-
fs::path filename;
80-
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename);
81-
BOOST_CHECK_EQUAL(filename, test_name);
82-
BOOST_CHECK_EQUAL(env->Directory(), datadir);
83-
}
84-
85-
BOOST_AUTO_TEST_CASE(getwalletenv_directory)
86-
{
87-
fs::path expected_name = "wallet.dat";
88-
const fs::path datadir = m_args.GetDataDirNet();
89-
90-
fs::path filename;
91-
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(datadir, filename);
92-
BOOST_CHECK_EQUAL(filename, expected_name);
93-
BOOST_CHECK_EQUAL(env->Directory(), datadir);
94-
}
95-
96-
BOOST_AUTO_TEST_CASE(getwalletenv_g_dbenvs_multiple)
97-
{
98-
fs::path datadir = m_args.GetDataDirNet() / "1";
99-
fs::path datadir_2 = m_args.GetDataDirNet() / "2";
100-
fs::path filename;
101-
102-
std::shared_ptr<BerkeleyEnvironment> env_1 = GetWalletEnv(datadir, filename);
103-
std::shared_ptr<BerkeleyEnvironment> env_2 = GetWalletEnv(datadir, filename);
104-
std::shared_ptr<BerkeleyEnvironment> env_3 = GetWalletEnv(datadir_2, filename);
105-
106-
BOOST_CHECK(env_1 == env_2);
107-
BOOST_CHECK(env_2 != env_3);
108-
}
109-
110-
BOOST_AUTO_TEST_CASE(getwalletenv_g_dbenvs_free_instance)
111-
{
112-
fs::path datadir = gArgs.GetDataDirNet() / "1";
113-
fs::path datadir_2 = gArgs.GetDataDirNet() / "2";
114-
fs::path filename;
115-
116-
std::shared_ptr <BerkeleyEnvironment> env_1_a = GetWalletEnv(datadir, filename);
117-
std::shared_ptr <BerkeleyEnvironment> env_2_a = GetWalletEnv(datadir_2, filename);
118-
env_1_a.reset();
119-
120-
std::shared_ptr<BerkeleyEnvironment> env_1_b = GetWalletEnv(datadir, filename);
121-
std::shared_ptr<BerkeleyEnvironment> env_2_b = GetWalletEnv(datadir_2, filename);
122-
123-
BOOST_CHECK(env_1_a != env_1_b);
124-
BOOST_CHECK(env_2_a == env_2_b);
125-
}
126-
#endif
127-
12858
static std::vector<std::unique_ptr<WalletDatabase>> TestDatabases(const fs::path& path_root)
12959
{
13060
std::vector<std::unique_ptr<WalletDatabase>> dbs;
13161
DatabaseOptions options;
13262
DatabaseStatus status;
13363
bilingual_str error;
134-
#ifdef USE_BDB
135-
dbs.emplace_back(MakeBerkeleyDatabase(path_root / "bdb", options, status, error));
136-
// Needs BDB to make the DB to read
137-
dbs.emplace_back(std::make_unique<BerkeleyRODatabase>(BDBDataFile(path_root / "bdb"), /*open=*/false));
138-
#endif
64+
// Unable to test BerkeleyRO since we cannot create a new BDB database to open
13965
dbs.emplace_back(MakeSQLiteDatabase(path_root / "sqlite", options, status, error));
14066
dbs.emplace_back(CreateMockableWalletDatabase());
14167
return dbs;
@@ -148,15 +74,10 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test)
14874
std::vector<std::string> prefixes = {"", "FIRST", "SECOND", "P\xfe\xff", "P\xff\x01", "\xff\xff"};
14975

15076
std::unique_ptr<DatabaseBatch> handler = Assert(database)->MakeBatch();
151-
if (dynamic_cast<BerkeleyRODatabase*>(database.get())) {
152-
// For BerkeleyRO, open the file now. This must happen after BDB has written to the file
153-
database->Open();
154-
} else {
155-
// Write elements to it if not berkeleyro
156-
for (unsigned int i = 0; i < 10; i++) {
157-
for (const auto& prefix : prefixes) {
158-
BOOST_CHECK(handler->Write(std::make_pair(prefix, i), i));
159-
}
77+
// Write elements to it
78+
for (unsigned int i = 0; i < 10; i++) {
79+
for (const auto& prefix : prefixes) {
80+
BOOST_CHECK(handler->Write(std::make_pair(prefix, i), i));
16081
}
16182
}
16283

@@ -206,14 +127,9 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_byte_test)
206127
for (const auto& database : TestDatabases(m_path_root)) {
207128
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch();
208129

209-
if (dynamic_cast<BerkeleyRODatabase*>(database.get())) {
210-
// For BerkeleyRO, open the file now. This must happen after BDB has written to the file
211-
database->Open();
212-
} else {
213-
// Write elements to it if not berkeleyro
214-
for (const auto& [k, v] : {e, p, ps, f, fs, ff, ffs}) {
215-
batch->Write(std::span{k}, std::span{v});
216-
}
130+
// Write elements to it if not berkeleyro
131+
for (const auto& [k, v] : {e, p, ps, f, fs, ff, ffs}) {
132+
batch->Write(std::span{k}, std::span{v});
217133
}
218134

219135
CheckPrefix(*batch, StringBytes(""), {e, p, ps, f, fs, ff, ffs});
@@ -231,10 +147,6 @@ BOOST_AUTO_TEST_CASE(db_availability_after_write_error)
231147
// To simulate the behavior, record overwrites are disallowed, and the test verifies
232148
// that the database remains active after failing to store an existing record.
233149
for (const auto& database : TestDatabases(m_path_root)) {
234-
if (dynamic_cast<BerkeleyRODatabase*>(database.get())) {
235-
// Skip this test if BerkeleyRO
236-
continue;
237-
}
238150
// Write original record
239151
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch();
240152
std::string key = "key";

0 commit comments

Comments
 (0)