15#include <boost/test/unit_test.hpp>
24 for (
const bool obfuscate : {
false,
true}) {
26 const fs::path path{m_args.GetDataDirBase() /
"dbwrapper"};
29 std::vector<std::pair<uint8_t, uint256>>
key_values{};
43 dbw.Write(key, value);
75 for (
bool obfuscate : {
false,
true}) {
76 fs::path
ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
77 CDBWrapper dbw({.path =
ph, .cache_bytes = 1 << 20, .memory_only =
false, .wipe_data =
true, .obfuscate = obfuscate});
87 std::string
key_block =
"b" + m_rng.rand256().ToString();
111 std::string
key_utxo =
"c" + m_rng.rand256().ToString();
142 std::string filename =
"randomfilename";
156 for (
const bool obfuscate : {
false,
true}) {
157 fs::path
ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_batch_obfuscate_true" :
"dbwrapper_batch_obfuscate_false");
158 CDBWrapper dbw({.path =
ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
170 batch.
Write(key, in);
177 dbw.WriteBatch(batch);
192 for (
const bool obfuscate : {
false,
true}) {
193 fs::path
ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
194 CDBWrapper dbw({.path =
ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
204 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(
dbw).NewIterator());
233 fs::path
ph = m_args.GetDataDirBase() /
"existing_data_no_obfuscate";
234 fs::create_directories(
ph);
237 std::unique_ptr<CDBWrapper>
dbw = std::make_unique<CDBWrapper>(
DBParams{.
path =
ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
250 CDBWrapper odbw({.path =
ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
true});
274 fs::path
ph = m_args.GetDataDirBase() /
"existing_data_reindex";
275 fs::create_directories(
ph);
278 std::unique_ptr<CDBWrapper>
dbw = std::make_unique<CDBWrapper>(
DBParams{.
path =
ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
291 CDBWrapper odbw({.path =
ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
true, .obfuscate =
true});
309 fs::path
ph = m_args.GetDataDirBase() /
"iterator_ordering";
310 CDBWrapper dbw({.path =
ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
311 for (
int x=0x00; x<256; ++x) {
314 if (!(x & 1))
dbw.
Write(key, value);
318 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(
dbw).NewIterator());
320 for (
unsigned int x=0x00; x<256; ++x) {
323 if (x & 1)
dbw.Write(key, value);
355 template<
typename Stream>
358 for (
size_t i = 0; i <
str.size(); i++) {
363 template<
typename Stream>
377 fs::path
ph = m_args.GetDataDirBase() /
"iterator_string_ordering";
378 CDBWrapper dbw({.path =
ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
379 for (
int x = 0; x < 10; ++x) {
380 for (
int y = 0; y < 10; ++y) {
381 std::string key{ToString(x)};
382 for (
int z = 0; z < y; ++z)
389 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(
dbw).NewIterator());
392 for (
unsigned int x =
seek_start; x < 10; ++x) {
393 for (
int y = 0; y < 10; ++y) {
394 std::string
exp_key{ToString(x)};
395 for (
int z = 0; z < y; ++z)
419 fs::path
ph = m_args.GetDataDirBase() /
"test_runner_₿_🏃_20191128_104644";
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
void Write(const K &key, const V &value, bool fSync=false)
std::string ToString() const
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(dbwrapper)
static bool exists(const path &p)
const Obfuscation & GetObfuscation(const CDBWrapper &w)
Work around circular dependency, as well as for testing in dbwrapper_tests.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
Application-specific storage settings.
fs::path path
Location in the filesystem where leveldb data will be stored.
StringContentsSerializer()=default
void Unserialize(Stream &s)
void Serialize(Stream &s) const
StringContentsSerializer(const std::string &inp)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.