Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2013 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5// Test for issue 200: when iterator switches direction from backward6// to forward, the current key can be yielded unexpectedly if a new7// mutation has been added just before the current key.9#include "leveldb/db.h"10#include "util/testharness.h"12namespace leveldb {14class Issue200 {};16TEST(Issue200, Test) {17// Get rid of any state from an old run.18std::string dbpath = test::TmpDir() + "/leveldb_issue200_test";19DestroyDB(dbpath, Options());21DB* db;22Options options;23options.create_if_missing = true;24ASSERT_OK(DB::Open(options, dbpath, &db));26WriteOptions write_options;27ASSERT_OK(db->Put(write_options, "1", "b"));28ASSERT_OK(db->Put(write_options, "2", "c"));29ASSERT_OK(db->Put(write_options, "3", "d"));30ASSERT_OK(db->Put(write_options, "4", "e"));31ASSERT_OK(db->Put(write_options, "5", "f"));33ReadOptions read_options;34Iterator* iter = db->NewIterator(read_options);36// Add an element that should not be reflected in the iterator.37ASSERT_OK(db->Put(write_options, "25", "cd"));39iter->Seek("5");40ASSERT_EQ(iter->key().ToString(), "5");41iter->Prev();42ASSERT_EQ(iter->key().ToString(), "4");43iter->Prev();44ASSERT_EQ(iter->key().ToString(), "3");45iter->Next();46ASSERT_EQ(iter->key().ToString(), "4");47iter->Next();48ASSERT_EQ(iter->key().ToString(), "5");50delete iter;51delete db;52DestroyDB(dbpath, options);53}55} // namespace leveldb57int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.