18
18
#ifdef USE_SQLITE
19
19
#include < wallet/sqlite.h>
20
20
#endif
21
+ #include < wallet/migrate.h>
21
22
#include < wallet/test/util.h>
22
23
#include < wallet/walletutil.h> // for WALLET_FLAG_DESCRIPTORS
23
24
@@ -134,6 +135,8 @@ static std::vector<std::unique_ptr<WalletDatabase>> TestDatabases(const fs::path
134
135
bilingual_str error;
135
136
#ifdef USE_BDB
136
137
dbs.emplace_back (MakeBerkeleyDatabase (path_root / " bdb" , options, status, error));
138
+ // Needs BDB to make the DB to read
139
+ dbs.emplace_back (std::make_unique<BerkeleyRODatabase>(BDBDataFile (path_root / " bdb" ), /* open=*/ false ));
137
140
#endif
138
141
#ifdef USE_SQLITE
139
142
dbs.emplace_back (MakeSQLiteDatabase (path_root / " sqlite" , options, status, error));
@@ -148,11 +151,16 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test)
148
151
for (const auto & database : TestDatabases (m_path_root)) {
149
152
std::vector<std::string> prefixes = {" " , " FIRST" , " SECOND" , " P\xfe\xff " , " P\xff\x01 " , " \xff\xff " };
150
153
151
- // Write elements to it
152
154
std::unique_ptr<DatabaseBatch> handler = Assert (database)->MakeBatch ();
153
- for (unsigned int i = 0 ; i < 10 ; i++) {
154
- for (const auto & prefix : prefixes) {
155
- BOOST_CHECK (handler->Write (std::make_pair (prefix, i), i));
155
+ if (dynamic_cast <BerkeleyRODatabase*>(database.get ())) {
156
+ // For BerkeleyRO, open the file now. This must happen after BDB has written to the file
157
+ database->Open ();
158
+ } else {
159
+ // Write elements to it if not berkeleyro
160
+ for (unsigned int i = 0 ; i < 10 ; i++) {
161
+ for (const auto & prefix : prefixes) {
162
+ BOOST_CHECK (handler->Write (std::make_pair (prefix, i), i));
163
+ }
156
164
}
157
165
}
158
166
@@ -180,6 +188,8 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test)
180
188
// Let's now read it once more, it should return DONE
181
189
BOOST_CHECK (cursor->Next (key, value) == DatabaseCursor::Status::DONE);
182
190
}
191
+ handler.reset ();
192
+ database->Close ();
183
193
}
184
194
}
185
195
@@ -199,13 +209,23 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_byte_test)
199
209
ffs{StringData (" \xff\xff suffix" ), StringData (" ffs" )};
200
210
for (const auto & database : TestDatabases (m_path_root)) {
201
211
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch ();
202
- for (const auto & [k, v] : {e, p, ps, f, fs, ff, ffs}) {
203
- batch->Write (Span{k}, Span{v});
212
+
213
+ if (dynamic_cast <BerkeleyRODatabase*>(database.get ())) {
214
+ // For BerkeleyRO, open the file now. This must happen after BDB has written to the file
215
+ database->Open ();
216
+ } else {
217
+ // Write elements to it if not berkeleyro
218
+ for (const auto & [k, v] : {e, p, ps, f, fs, ff, ffs}) {
219
+ batch->Write (Span{k}, Span{v});
220
+ }
204
221
}
222
+
205
223
CheckPrefix (*batch, StringBytes (" " ), {e, p, ps, f, fs, ff, ffs});
206
224
CheckPrefix (*batch, StringBytes (" prefix" ), {p, ps});
207
225
CheckPrefix (*batch, StringBytes (" \xff " ), {f, fs, ff, ffs});
208
226
CheckPrefix (*batch, StringBytes (" \xff\xff " ), {ff, ffs});
227
+ batch.reset ();
228
+ database->Close ();
209
229
}
210
230
}
211
231
@@ -215,6 +235,10 @@ BOOST_AUTO_TEST_CASE(db_availability_after_write_error)
215
235
// To simulate the behavior, record overwrites are disallowed, and the test verifies
216
236
// that the database remains active after failing to store an existing record.
217
237
for (const auto & database : TestDatabases (m_path_root)) {
238
+ if (dynamic_cast <BerkeleyRODatabase*>(database.get ())) {
239
+ // Skip this test if BerkeleyRO
240
+ continue ;
241
+ }
218
242
// Write original record
219
243
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch ();
220
244
std::string key = " key" ;
@@ -243,6 +267,10 @@ BOOST_AUTO_TEST_CASE(erase_prefix)
243
267
auto make_key = [](std::string type, std::string id) { return std::make_pair (type, id); };
244
268
245
269
for (const auto & database : TestDatabases (m_path_root)) {
270
+ if (dynamic_cast <BerkeleyRODatabase*>(database.get ())) {
271
+ // Skip this test if BerkeleyRO
272
+ continue ;
273
+ }
246
274
std::unique_ptr<DatabaseBatch> batch = database->MakeBatch ();
247
275
248
276
// Write two entries with the same key type prefix, a third one with a different prefix
0 commit comments