test: cover repeated dbwrapper stream use
What changed, and why it matters
This commit only adds new test cases for the database wrapper code. It checks that a database batch can be reused after being cleared, and that a database iterator can be seeked multiple times and recover from a failed value decode. There are no changes to production code, so this commit does not introduce or fix a security vulnerability by itself.
No security action required; treat as routine test coverage. Monitor the referenced follow-up production commits that will change CDBBatch/CDBIterator scratch stream reuse for actual security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies src/test/dbwrapper_tests.cpp to extend existing unit tests. It adds a batch.Clear() + reuse path in dbwrapper_batch and adds repeated Seek/GetKey/GetValue operations plus a failed oversized value decode followed by a successful decode in dbwrapper_iterator. The commit message explicitly states this is test-only preparation for future production changes to CDBBatch and CDBIterator scratch stream reuse. No production logic is altered.
Changed components
src/test/dbwrapper_tests.cppInspect captured patch +26 / −1
diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp
index a57b77e3..185bf491 100644
--- a/src/test/dbwrapper_tests.cpp
+++ b/src/test/dbwrapper_tests.cpp
@@ -184,6 +184,13 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch)
// key3 should've never been written
BOOST_CHECK(dbw.Read(key3, res) == false);
+
+ batch.Clear();
+ batch.Write(key3, in3);
+ dbw.WriteBatch(batch);
+
+ BOOST_CHECK(dbw.Read(key3, res));
+ BOOST_CHECK_EQUAL(res.ToString(), in3.ToString());
}
}
@@ -212,18 +219,36 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
BOOST_CHECK(!it->GetKey(key_too_large));
uint8_t key_res;
+
+ BOOST_REQUIRE(it->GetKey(key_res));
+ BOOST_CHECK_EQUAL(key_res, key);
+ // A failed value decode must not leave the iterator's scratch stream dirty.
+ std::pair<uint256, uint8_t> value_too_large;
+ BOOST_CHECK(!it->GetValue(value_too_large));
+
uint256 val_res;
+ BOOST_REQUIRE(it->GetValue(val_res));
+ BOOST_CHECK_EQUAL(val_res.ToString(), in.ToString());
+
+ it->Seek(key2);
BOOST_REQUIRE(it->GetKey(key_res));
+ BOOST_CHECK_EQUAL(key_res, key2);
BOOST_REQUIRE(it->GetValue(val_res));
+ BOOST_CHECK_EQUAL(val_res.ToString(), in2.ToString());
+
+ it->Seek(key);
+
+ BOOST_REQUIRE(it->GetKey(key_res));
BOOST_CHECK_EQUAL(key_res, key);
+ BOOST_REQUIRE(it->GetValue(val_res));
BOOST_CHECK_EQUAL(val_res.ToString(), in.ToString());
it->Next();
BOOST_REQUIRE(it->GetKey(key_res));
- BOOST_REQUIRE(it->GetValue(val_res));
BOOST_CHECK_EQUAL(key_res, key2);
+ BOOST_REQUIRE(it->GetValue(val_res));
BOOST_CHECK_EQUAL(val_res.ToString(), in2.ToString());
it->Next();
Why this scored 14/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.