14#include <boost/test/unit_test.hpp>
23 for (
const bool obfuscate : {
false,
true}) {
24 constexpr size_t CACHE_SIZE{1_MiB};
25 const fs::path path{m_args.GetDataDirBase() /
"dbwrapper"};
28 std::vector<std::pair<uint8_t, uint256>> key_values{};
32 CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .wipe_data =
true, .obfuscate = obfuscate}};
39 for (uint8_t
k{0};
k < 10; ++
k) {
43 key_values.emplace_back(key, value);
49 CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate =
false}};
55 CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate = obfuscate}};
62 for (
const auto& [key, expected_value] : key_values) {
74 for (
bool obfuscate : {
false,
true}) {
75 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
76 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
false, .wipe_data =
true, .obfuscate = obfuscate});
86 std::string key_block =
"b" + m_rng.rand256().ToString();
88 uint256 in_block = m_rng.rand256();
94 std::string key_file =
strprintf(
"f%04x", m_rng.rand32());
96 uint256 in_file_info = m_rng.rand256();
102 std::string key_transaction =
"t" + m_rng.rand256().ToString();
104 uint256 in_transaction = m_rng.rand256();
105 BOOST_CHECK(dbw.Write(key_transaction, in_transaction));
110 std::string key_utxo =
"c" + m_rng.rand256().ToString();
112 uint256 in_utxo = m_rng.rand256();
118 uint8_t key_last_blockfile_number{
'l'};
119 uint32_t lastblockfilenumber = m_rng.rand32();
120 BOOST_CHECK(dbw.Write(key_last_blockfile_number, lastblockfilenumber));
121 BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32));
125 uint8_t key_IsReindexing{
'R'};
126 bool isInReindexing = m_rng.randbool();
127 BOOST_CHECK(dbw.Write(key_IsReindexing, isInReindexing));
132 uint8_t key_lastblockhash_uxto{
'B'};
133 uint256 lastblock_hash = m_rng.rand256();
134 BOOST_CHECK(dbw.Write(key_lastblockhash_uxto, lastblock_hash));
135 BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res));
139 std::string file_option_tag =
"F";
140 uint8_t filename_length = m_rng.randbits(8);
141 std::string filename =
"randomfilename";
142 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag, filename_length, filename);
144 bool in_file_bool = m_rng.randbool();
145 BOOST_CHECK(dbw.Write(key_file_option, in_file_bool));
155 for (
const bool obfuscate : {
false,
true}) {
156 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_batch_obfuscate_true" :
"dbwrapper_batch_obfuscate_false");
157 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
169 batch.
Write(key, in);
170 batch.
Write(key2, in2);
171 batch.
Write(key3, in3);
191 for (
const bool obfuscate : {
false,
true}) {
192 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
193 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
203 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
211 BOOST_REQUIRE(it->GetKey(key_res));
212 BOOST_REQUIRE(it->GetValue(val_res));
218 BOOST_REQUIRE(it->GetKey(key_res));
219 BOOST_REQUIRE(it->GetValue(val_res));
232 fs::path ph = m_args.GetDataDirBase() /
"existing_data_no_obfuscate";
236 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(
DBParams{.
path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
249 CDBWrapper odbw({.path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
true});
273 fs::path ph = m_args.GetDataDirBase() /
"existing_data_reindex";
277 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(
DBParams{.
path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
290 CDBWrapper odbw({.path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
true, .obfuscate =
true});
308 fs::path ph = m_args.GetDataDirBase() /
"iterator_ordering";
309 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
310 for (
int x=0x00; x<256; ++x) {
312 uint32_t value = x*x;
317 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
319 for (
unsigned int x=0x00; x<256; ++x) {
321 uint32_t value = x*x;
325 for (
const int seek_start : {0x00, 0x80}) {
326 it->Seek((uint8_t)seek_start);
327 for (
unsigned int x=seek_start; x<255; ++x) {
354 template<
typename Stream>
357 for (
size_t i = 0; i <
str.size(); i++) {
358 s << uint8_t(
str[i]);
362 template<
typename Stream>
376 fs::path ph = m_args.GetDataDirBase() /
"iterator_string_ordering";
377 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
378 for (
int x = 0; x < 10; ++x) {
379 for (
int y = 0; y < 10; ++y) {
381 for (
int z = 0; z < y; ++z)
383 uint32_t value = x*x;
388 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
389 for (
const int seek_start : {0, 5}) {
391 for (
unsigned int x = seek_start; x < 10; ++x) {
392 for (
int y = 0; y < 10; ++y) {
394 for (
int z = 0; z < y; ++z)
418 fs::path ph = m_args.GetDataDirBase() /
"test_runner_₿_🏃_20191128_104644";
419 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20});
421 fs::path lockPath = ph /
"LOCK";
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
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 create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
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)