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) 2011 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#ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_6#define STORAGE_LEVELDB_UTIL_TESTUTIL_H_8#include "helpers/memenv/memenv.h"9#include "leveldb/env.h"10#include "leveldb/slice.h"11#include "util/random.h"13namespace leveldb {14namespace test {16// Store in *dst a random string of length "len" and return a Slice that17// references the generated data.18Slice RandomString(Random* rnd, int len, std::string* dst);20// Return a random key with the specified length that may contain interesting21// characters (e.g. \x00, \xff, etc.).22std::string RandomKey(Random* rnd, int len);24// Store in *dst a string of length "len" that will compress to25// "N*compressed_fraction" bytes and return a Slice that references26// the generated data.27Slice CompressibleString(Random* rnd, double compressed_fraction, size_t len,28std::string* dst);30// A wrapper that allows injection of errors.31class ErrorEnv : public EnvWrapper {32public:33bool writable_file_error_;34int num_writable_file_errors_;36ErrorEnv()37: EnvWrapper(NewMemEnv(Env::Default())),38writable_file_error_(false),39num_writable_file_errors_(0) {}40~ErrorEnv() override { delete target(); }42Status NewWritableFile(const std::string& fname,43WritableFile** result) override {44if (writable_file_error_) {45++num_writable_file_errors_;46*result = nullptr;47return Status::IOError(fname, "fake error");48}49return target()->NewWritableFile(fname, result);50}52Status NewAppendableFile(const std::string& fname,53WritableFile** result) override {54if (writable_file_error_) {55++num_writable_file_errors_;56*result = nullptr;57return Status::IOError(fname, "fake error");58}59return target()->NewAppendableFile(fname, result);60}61};63} // namespace test64} // namespace leveldb66#endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_
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.