11#include <boost/test/unit_test.hpp>
14static bool is_null_key(
const std::vector<unsigned char>& key) {
17 for (
unsigned int i = 0; i < key.size(); i++)
18 isnull &= (key[i] ==
'\x00');
28 for (
const bool obfuscate : {
false,
true}) {
29 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_obfuscate_true" :
"dbwrapper_obfuscate_false");
30 CDBWrapper dbw(ph, (1 << 20),
true,
false, obfuscate);
47 for (
bool obfuscate : {
false,
true}) {
48 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
49 CDBWrapper dbw(ph, (1 << 20),
false,
true, obfuscate);
91 uint8_t key_last_blockfile_number{
'l'};
98 uint8_t key_IsReindexing{
'R'};
105 uint8_t key_lastblockhash_uxto{
'B'};
112 std::string file_option_tag =
"F";
114 std::string filename =
"randomfilename";
115 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag,filename_length,filename);
128 for (
const bool obfuscate : {
false,
true}) {
129 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_batch_obfuscate_true" :
"dbwrapper_batch_obfuscate_false");
130 CDBWrapper dbw(ph, (1 << 20),
true,
false, obfuscate);
142 batch.
Write(key, in);
143 batch.
Write(key2, in2);
144 batch.
Write(key3, in3);
164 for (
const bool obfuscate : {
false,
true}) {
165 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
166 CDBWrapper dbw(ph, (1 << 20),
true,
false, obfuscate);
176 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
184 BOOST_REQUIRE(it->GetKey(key_res));
185 BOOST_REQUIRE(it->GetValue(val_res));
191 BOOST_REQUIRE(it->GetKey(key_res));
192 BOOST_REQUIRE(it->GetValue(val_res));
205 fs::path ph = m_args.GetDataDirBase() /
"existing_data_no_obfuscate";
206 create_directories(ph);
209 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(ph, (1 << 10),
false,
false,
false);
222 CDBWrapper odbw(ph, (1 << 10),
false,
false,
true);
246 fs::path ph = m_args.GetDataDirBase() /
"existing_data_reindex";
247 create_directories(ph);
250 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(ph, (1 << 10),
false,
false,
false);
263 CDBWrapper odbw(ph, (1 << 10),
false,
true,
true);
281 fs::path ph = m_args.GetDataDirBase() /
"iterator_ordering";
282 CDBWrapper dbw(ph, (1 << 20),
true,
false,
false);
283 for (
int x=0x00; x<256; ++x) {
285 uint32_t value = x*x;
290 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
292 for (
unsigned int x=0x00; x<256; ++x) {
294 uint32_t value = x*x;
298 for (
const int seek_start : {0x00, 0x80}) {
299 it->Seek((uint8_t)seek_start);
300 for (
unsigned int x=seek_start; x<255; ++x) {
333 template<
typename Stream>
336 for (
size_t i = 0; i <
str.size(); i++) {
337 s << uint8_t(
str[i]);
341 template<
typename Stream>
350 }
catch (
const std::ios_base::failure&) {
361 fs::path ph = m_args.GetDataDirBase() /
"iterator_string_ordering";
362 CDBWrapper dbw(ph, (1 << 20),
true,
false,
false);
363 for (
int x=0x00; x<10; ++x) {
364 for (
int y = 0; y < 10; y++) {
365 snprintf(buf,
sizeof(buf),
"%d", x);
367 for (
int z = 0; z < y; z++)
369 uint32_t value = x*x;
374 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
375 for (
const int seek_start : {0, 5}) {
376 snprintf(buf,
sizeof(buf),
"%d", seek_start);
379 for (
unsigned int x=seek_start; x<10; ++x) {
380 for (
int y = 0; y < 10; y++) {
381 snprintf(buf,
sizeof(buf),
"%d", x);
382 std::string exp_key(buf);
383 for (
int z = 0; z < y; z++)
407 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)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
bool Read(const K &key, V &value) const
bool Write(const K &key, const V &value, bool fSync=false)
bool IsEmpty()
Return true if the database managed by this class contains no entries.
std::string ToString() const
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
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 exists(const path &p)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static uint256 InsecureRand256()
static uint64_t InsecureRandBits(int bits)
static uint32_t InsecureRand32()
static bool InsecureRandBool()
void Unserialize(Stream &s)
void Serialize(Stream &s) const
StringContentsSerializer(const std::string &inp)
StringContentsSerializer()
StringContentsSerializer & operator+=(const StringContentsSerializer &s)
StringContentsSerializer & operator+=(const std::string &s)