test: add regression test for in-memory SQLiteDatabase reopen
What changed, and why it matters
This commit only adds a new automated test. It checks that Bitcoin Core's in-memory SQLite wallet database correctly refuses to reopen after being closed, because reopening would silently create a fresh empty database and discard any previous wallet data. The actual protective change (making Open() throw) is already in the codebase; this commit just pins the behavior with a regression test so it cannot accidentally break in the future.
No immediate action required. This is a test-only commit. Reviewers may want to confirm the underlying InMemoryWalletDatabase::Open() throw behavior is present and that existing tests pass.
Security signals we found
Regression test for data-loss prevention behavior in wallet database layer
In-memory SQLite database reopen could silently discard wallet data
Open() now throws std::runtime_error instead of returning a fresh connection
Evidence from the diff
The diff adds a single BOOST_AUTO_TEST_CASE in src/wallet/test/db_tests.cpp named in_memory_database_cannot_reopen. It instantiates an InMemoryWalletDatabase, calls Close(), then asserts that a subsequent Open() throws std::runtime_error. The commit message states this is a regression test for behavior already implemented: InMemoryWalletDatabase::Open() throws to prevent silently returning a new empty connection after close, which would discard all data. No production code is modified.
Changed components
src/wallet/test/db_tests.cppwallet SQLite in-memory database layer (test coverage only)Inspect captured patch +9 / −0
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp
index 532bdce3..818b176c 100644
--- a/src/wallet/test/db_tests.cpp
+++ b/src/wallet/test/db_tests.cpp
@@ -297,5 +297,14 @@ BOOST_AUTO_TEST_CASE(concurrent_txn_dont_interfere)
BOOST_CHECK_EQUAL(read_value, value2);
}
+BOOST_AUTO_TEST_CASE(in_memory_database_cannot_reopen)
+{
+ // Reopening an in-memory database would create a fresh empty connection,
+ // silently losing all data. Open() must throw instead.
+ InMemoryWalletDatabase database;
+ database.Close();
+ BOOST_CHECK_THROW(database.Open(), std::runtime_error);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace wallet
Why this scored 24/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.