11 #include <boost/test/unit_test.hpp> 14 static 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";
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";
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";
static bool InsecureRandBool()
Batch of changes queued to be written to a CDBWrapper.
void Serialize(Stream &s) const
static bool is_null_key(const std::vector< unsigned char > &key)
static uint32_t InsecureRand32()
StringContentsSerializer()=default
void Unserialize(Stream &s)
BOOST_AUTO_TEST_CASE(dbwrapper)
BOOST_AUTO_TEST_SUITE_END()
void Write(const K &key, const V &value)
StringContentsSerializer & operator+=(const StringContentsSerializer &s)
static uint64_t InsecureRandBits(int bits)
std::string ToString() const
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...
bool IsEmpty()
Return true if the database managed by this class contains no entries.
bool Read(const K &key, V &value) const
const std::vector< unsigned char > & GetObfuscateKey(const CDBWrapper &w)
Work around circular dependency, as well as for testing in dbwrapper_tests.
bool Write(const K &key, const V &value, bool fSync=false)
#define BOOST_CHECK_EQUAL(v1, v2)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
StringContentsSerializer & operator+=(const std::string &s)
static bool exists(const path &p)
static uint256 InsecureRand256()
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
StringContentsSerializer(const std::string &inp)
#define BOOST_CHECK(expr)