diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index a57b77e3aeb..185bf491e57 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; - 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 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();