For the wallet’s unit tests, we currently use either DummyDatabase
or memory-only versions of either BDB or SQLite. The tests that use DummyDatabase
just need a WalletDatabase
so that the CWallet
can be constructed, while the tests using the memory-only databases just need a backing data store. There is also a FailDatabase
that is similar to DummyDatabase
except it fails be default or can have a configured return value. Having all of these different database types can make it difficult to write tests, particularly tests that work when either BDB or SQLite is disabled.
This PR unifies all of these different unit test database classes into a single MockableDatabase
. Like DummyDatabase
, most functions do nothing and just return true. Like FailDatabase
, the return value of some functions can be configured on the fly to test various failure cases. Like the memory-only databases, records can actually be written to the MockableDatabase
and be retrieved later, but all of this is still held in memory. Using MockableDatabase
completely removes the need for having BDB or SQLite backed wallets in the unit tests for the tests that are not actually testing specific database behaviors.
Because MockableDatabase
s can be created by each unit test, we can also control what records are stored in the database. Records can be added and removed externally from the typical database modification functions. This will give us greater ability to test failure conditions, particularly those involving corrupted records.
Possible alternative to #26644