2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
- #include < bitcoin-build-config.h> // IWYU pragma: keep
6
-
7
5
#include < boost/test/unit_test.hpp>
8
6
9
7
#include < test/util/setup_common.h>
10
8
#include < util/check.h>
11
9
#include < util/fs.h>
12
10
#include < util/translation.h>
13
- #ifdef USE_BDB
14
- #include < wallet/bdb.h>
15
- #endif
16
11
#include < wallet/sqlite.h>
17
12
#include < wallet/migrate.h>
18
13
#include < wallet/test/util.h>
@@ -60,82 +55,13 @@ static void CheckPrefix(DatabaseBatch& batch, std::span<const std::byte> prefix,
60
55
61
56
BOOST_FIXTURE_TEST_SUITE (db_tests, BasicTestingSetup)
62
57
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
-
128
58
static std::vector<std::unique_ptr<WalletDatabase>> TestDatabases (const fs::path& path_root)
129
59
{
130
60
std::vector<std::unique_ptr<WalletDatabase>> dbs;
131
61
DatabaseOptions options;
132
62
DatabaseStatus status;
133
63
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
139
65
dbs.emplace_back (MakeSQLiteDatabase (path_root / " sqlite" , options, status, error));
140
66
dbs.emplace_back (CreateMockableWalletDatabase ());
141
67
return dbs;
@@ -148,15 +74,10 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test)
148
74
std::vector<std::string> prefixes = {" " , " FIRST" , " SECOND" , " P\xfe\xff " , " P\xff\x01 " , " \xff\xff " };
149
75
150
76
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));
160
81
}
161
82
}
162
83
@@ -206,14 +127,9 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_byte_test)
206
127
for (const auto & database : TestDatabases (m_path_root)) {
207
128
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch ();
208
129
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});
217
133
}
218
134
219
135
CheckPrefix (*batch, StringBytes (" " ), {e, p, ps, f, fs, ff, ffs});
@@ -231,10 +147,6 @@ BOOST_AUTO_TEST_CASE(db_availability_after_write_error)
231
147
// To simulate the behavior, record overwrites are disallowed, and the test verifies
232
148
// that the database remains active after failing to store an existing record.
233
149
for (const auto & database : TestDatabases (m_path_root)) {
234
- if (dynamic_cast <BerkeleyRODatabase*>(database.get ())) {
235
- // Skip this test if BerkeleyRO
236
- continue ;
237
- }
238
150
// Write original record
239
151
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch ();
240
152
std::string key = " key" ;
0 commit comments