13#include <boost/test/unit_test.hpp>
18static bool is_null_key(
const std::vector<unsigned char>& key) {
21 for (
unsigned int i = 0; i < key.size(); i++)
22 isnull &= (key[i] ==
'\x00');
32 for (
const bool obfuscate : {
false,
true}) {
33 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_obfuscate_true" :
"dbwrapper_obfuscate_false");
34 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
51 for (
bool obfuscate : {
false,
true}) {
52 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
53 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
false, .wipe_data =
true, .obfuscate = obfuscate});
63 std::string key_block =
"b" + m_rng.rand256().ToString();
65 uint256 in_block = m_rng.rand256();
71 std::string key_file =
strprintf(
"f%04x", m_rng.rand32());
73 uint256 in_file_info = m_rng.rand256();
79 std::string key_transaction =
"t" + m_rng.rand256().ToString();
81 uint256 in_transaction = m_rng.rand256();
82 BOOST_CHECK(dbw.Write(key_transaction, in_transaction));
87 std::string key_utxo =
"c" + m_rng.rand256().ToString();
89 uint256 in_utxo = m_rng.rand256();
95 uint8_t key_last_blockfile_number{
'l'};
96 uint32_t lastblockfilenumber = m_rng.rand32();
97 BOOST_CHECK(dbw.Write(key_last_blockfile_number, lastblockfilenumber));
98 BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32));
102 uint8_t key_IsReindexing{
'R'};
103 bool isInReindexing = m_rng.randbool();
104 BOOST_CHECK(dbw.Write(key_IsReindexing, isInReindexing));
109 uint8_t key_lastblockhash_uxto{
'B'};
110 uint256 lastblock_hash = m_rng.rand256();
111 BOOST_CHECK(dbw.Write(key_lastblockhash_uxto, lastblock_hash));
112 BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res));
116 std::string file_option_tag =
"F";
117 uint8_t filename_length = m_rng.randbits(8);
118 std::string filename =
"randomfilename";
119 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag,filename_length,filename);
121 bool in_file_bool = m_rng.randbool();
122 BOOST_CHECK(dbw.Write(key_file_option, in_file_bool));
132 for (
const bool obfuscate : {
false,
true}) {
133 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_batch_obfuscate_true" :
"dbwrapper_batch_obfuscate_false");
134 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
146 batch.
Write(key, in);
147 batch.
Write(key2, in2);
148 batch.
Write(key3, in3);
168 for (
const bool obfuscate : {
false,
true}) {
169 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
170 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
180 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
188 BOOST_REQUIRE(it->GetKey(key_res));
189 BOOST_REQUIRE(it->GetValue(val_res));
195 BOOST_REQUIRE(it->GetKey(key_res));
196 BOOST_REQUIRE(it->GetValue(val_res));
209 fs::path ph = m_args.GetDataDirBase() /
"existing_data_no_obfuscate";
213 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(
DBParams{.
path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
226 CDBWrapper odbw({.path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
true});
250 fs::path ph = m_args.GetDataDirBase() /
"existing_data_reindex";
254 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(
DBParams{.
path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
267 CDBWrapper odbw({.path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
true, .obfuscate =
true});
285 fs::path ph = m_args.GetDataDirBase() /
"iterator_ordering";
286 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
287 for (
int x=0x00; x<256; ++x) {
289 uint32_t value = x*x;
294 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
296 for (
unsigned int x=0x00; x<256; ++x) {
298 uint32_t value = x*x;
302 for (
const int seek_start : {0x00, 0x80}) {
303 it->Seek((uint8_t)seek_start);
304 for (
unsigned int x=seek_start; x<255; ++x) {
331 template<
typename Stream>
334 for (
size_t i = 0; i <
str.size(); i++) {
335 s << uint8_t(
str[i]);
339 template<
typename Stream>
353 fs::path ph = m_args.GetDataDirBase() /
"iterator_string_ordering";
354 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
355 for (
int x = 0; x < 10; ++x) {
356 for (
int y = 0; y < 10; ++y) {
358 for (
int z = 0; z < y; ++z)
360 uint32_t value = x*x;
365 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
366 for (
const int seek_start : {0, 5}) {
368 for (
unsigned int x = seek_start; x < 10; ++x) {
369 for (
int y = 0; y < 10; ++y) {
371 for (
int z = 0; z < y; ++z)
395 fs::path ph = m_args.GetDataDirBase() /
"test_runner_₿_🏃_20191128_104644";
396 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20});
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
std::string ToString() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static bool is_null_key(const std::vector< unsigned char > &key)
BOOST_AUTO_TEST_CASE(dbwrapper)
const std::vector< unsigned char > & GetObfuscateKey(const CDBWrapper &w)
Work around circular dependency, as well as for testing in dbwrapper_tests.
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)
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)