Skip to content

Commit 0103d64

Browse files
committed
Introduce DummyDatabase and use it in the tests
1 parent 8db2334 commit 0103d64

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/wallet/db.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <clientversion.h>
1010
#include <fs.h>
1111
#include <streams.h>
12+
#include <util/memory.h>
1213

1314
#include <atomic>
1415
#include <memory>
@@ -154,4 +155,44 @@ class WalletDatabase
154155
virtual std::unique_ptr<DatabaseBatch> MakeBatch(const char* mode = "r+", bool flush_on_close = true) = 0;
155156
};
156157

158+
/** RAII class that provides access to a DummyDatabase. Never fails. */
159+
class DummyBatch : public DatabaseBatch
160+
{
161+
private:
162+
bool ReadKey(CDataStream&& key, CDataStream& value) override { return true; }
163+
bool WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite=true) override { return true; }
164+
bool EraseKey(CDataStream&& key) override { return true; }
165+
bool HasKey(CDataStream&& key) override { return true; }
166+
167+
public:
168+
void Flush() override {}
169+
void Close() override {}
170+
171+
bool StartCursor() override { return true; }
172+
bool ReadAtCursor(CDataStream& ssKey, CDataStream& ssValue, bool& complete) override { return true; }
173+
void CloseCursor() override {}
174+
bool TxnBegin() override { return true; }
175+
bool TxnCommit() override { return true; }
176+
bool TxnAbort() override { return true; }
177+
};
178+
179+
/** A dummy WalletDatabase that does nothing and never fails. Only used by unit tests.
180+
**/
181+
class DummyDatabase : public WalletDatabase
182+
{
183+
public:
184+
void Open(const char* mode) override {};
185+
void AddRef() override {}
186+
void RemoveRef() override {}
187+
bool Rewrite(const char* pszSkip=nullptr) override { return true; }
188+
bool Backup(const std::string& strDest) const override { return true; }
189+
void Close() override {}
190+
void Flush() override {}
191+
bool PeriodicFlush() override { return true; }
192+
void IncrementUpdateCounter() override { ++nUpdateCounter; }
193+
void ReloadDbEnv() override {}
194+
bool Verify(bilingual_str& errorStr) override { return true; }
195+
std::unique_ptr<DatabaseBatch> MakeBatch(const char* mode = "r+", bool flush_on_close = true) override { return MakeUnique<DummyBatch>(); }
196+
};
197+
157198
#endif // BITCOIN_WALLET_DB_H

src/wallet/walletdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ std::unique_ptr<WalletDatabase> CreateWalletDatabase(const fs::path& path)
10211021
/** Return object for accessing dummy database with no read/write capabilities. */
10221022
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
10231023
{
1024-
return MakeUnique<BerkeleyDatabase>();
1024+
return MakeUnique<DummyDatabase>();
10251025
}
10261026

10271027
/** Return object for accessing temporary in-memory database. */

0 commit comments

Comments
 (0)