13 #include <boost/test/unit_test.hpp>
16 static bool is_null_key(
const std::vector<unsigned char>& key) {
19 for (
unsigned int i = 0; i < key.size(); i++)
20 isnull &= (key[i] ==
'\x00');
30 for (
const bool obfuscate : {
false,
true}) {
31 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_obfuscate_true" :
"dbwrapper_obfuscate_false");
32 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
49 for (
bool obfuscate : {
false,
true}) {
50 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
51 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
false, .wipe_data =
true, .obfuscate = obfuscate});
80 BOOST_CHECK(dbw.Write(key_transaction, in_transaction));
93 uint8_t key_last_blockfile_number{
'l'};
95 BOOST_CHECK(dbw.Write(key_last_blockfile_number, lastblockfilenumber));
96 BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32));
100 uint8_t key_IsReindexing{
'R'};
102 BOOST_CHECK(dbw.Write(key_IsReindexing, isInReindexing));
107 uint8_t key_lastblockhash_uxto{
'B'};
109 BOOST_CHECK(dbw.Write(key_lastblockhash_uxto, lastblock_hash));
110 BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res));
114 std::string file_option_tag =
"F";
116 std::string filename =
"randomfilename";
117 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag,filename_length,filename);
120 BOOST_CHECK(dbw.Write(key_file_option, in_file_bool));
130 for (
const bool obfuscate : {
false,
true}) {
131 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_batch_obfuscate_true" :
"dbwrapper_batch_obfuscate_false");
132 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
144 batch.
Write(key, in);
145 batch.
Write(key2, in2);
146 batch.
Write(key3, in3);
166 for (
const bool obfuscate : {
false,
true}) {
167 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
168 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
178 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
186 BOOST_REQUIRE(it->GetKey(key_res));
187 BOOST_REQUIRE(it->GetValue(val_res));
193 BOOST_REQUIRE(it->GetKey(key_res));
194 BOOST_REQUIRE(it->GetValue(val_res));
207 fs::path ph = m_args.GetDataDirBase() /
"existing_data_no_obfuscate";
211 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(
DBParams{.
path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
224 CDBWrapper odbw({.path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
true});
248 fs::path ph = m_args.GetDataDirBase() /
"existing_data_reindex";
252 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(
DBParams{.
path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
false, .obfuscate =
false});
265 CDBWrapper odbw({.path = ph, .cache_bytes = 1 << 10, .memory_only =
false, .wipe_data =
true, .obfuscate =
true});
283 fs::path ph = m_args.GetDataDirBase() /
"iterator_ordering";
284 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
285 for (
int x=0x00; x<256; ++x) {
287 uint32_t value = x*x;
292 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
294 for (
unsigned int x=0x00; x<256; ++x) {
296 uint32_t value = x*x;
300 for (
const int seek_start : {0x00, 0x80}) {
301 it->Seek((uint8_t)seek_start);
302 for (
unsigned int x=seek_start; x<255; ++x) {
329 template<
typename Stream>
332 for (
size_t i = 0; i <
str.size(); i++) {
333 s << uint8_t(
str[i]);
337 template<
typename Stream>
351 fs::path ph = m_args.GetDataDirBase() /
"iterator_string_ordering";
352 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
353 for (
int x = 0; x < 10; ++x) {
354 for (
int y = 0; y < 10; ++y) {
356 for (
int z = 0; z < y; ++z)
358 uint32_t value = x*x;
363 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
364 for (
const int seek_start : {0, 5}) {
366 for (
unsigned int x = seek_start; x < 10; ++x) {
367 for (
int y = 0; y < 10; ++y) {
369 for (
int z = 0; z < y; ++z)
393 fs::path ph = m_args.GetDataDirBase() /
"test_runner_₿_🏃_20191128_104644";
394 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_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)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
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)
static uint256 InsecureRand256()
static uint64_t InsecureRandBits(int bits)
static uint32_t InsecureRand32()
static bool InsecureRandBool()