mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 09:15:04 +02:00
test: cover repeated dbwrapper stream use
The next commits reuse scratch streams on `CDBBatch` and `CDBIterator`. Extend dbwrapper tests to reuse a batch after `Clear()`, seek repeatedly on one iterator, and fail a too-large `CDBIterator::GetValue()` decode before reading the same entry successfully. This locks down the reuse and failed-decode contracts before the production changes.
This commit is contained in:
@@ -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;
|
||||
uint256 val_res;
|
||||
|
||||
BOOST_REQUIRE(it->GetKey(key_res));
|
||||
BOOST_REQUIRE(it->GetValue(val_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();
|
||||
|
||||
Reference in New Issue
Block a user