12 #include <boost/test/unit_test.hpp>
15 static bool is_null_key(
const std::vector<unsigned char>& key) {
18 for (
unsigned int i = 0; i < key.size(); i++)
19 isnull &= (key[i] ==
'\x00');
29 for (
const bool obfuscate : {
false,
true}) {
30 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_obfuscate_true" :
"dbwrapper_obfuscate_false");
31 CDBWrapper dbw(ph, (1 << 20),
true,
false, obfuscate);
48 for (
bool obfuscate : {
false,
true}) {
49 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
50 CDBWrapper dbw(ph, (1 << 20),
false,
true, obfuscate);
92 uint8_t key_last_blockfile_number{
'l'};
99 uint8_t key_IsReindexing{
'R'};
106 uint8_t key_lastblockhash_uxto{
'B'};
113 std::string file_option_tag =
"F";
115 std::string filename =
"randomfilename";
116 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag,filename_length,filename);
129 for (
const bool obfuscate : {
false,
true}) {
130 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_batch_obfuscate_true" :
"dbwrapper_batch_obfuscate_false");
131 CDBWrapper dbw(ph, (1 << 20),
true,
false, obfuscate);
143 batch.
Write(key, in);
144 batch.
Write(key2, in2);
145 batch.
Write(key3, in3);
165 for (
const bool obfuscate : {
false,
true}) {
166 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
167 CDBWrapper dbw(ph, (1 << 20),
true,
false, obfuscate);
177 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
185 BOOST_REQUIRE(it->GetKey(key_res));
186 BOOST_REQUIRE(it->GetValue(val_res));
192 BOOST_REQUIRE(it->GetKey(key_res));
193 BOOST_REQUIRE(it->GetValue(val_res));
206 fs::path ph = m_args.GetDataDirBase() /
"existing_data_no_obfuscate";
210 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(ph, (1 << 10),
false,
false,
false);
223 CDBWrapper odbw(ph, (1 << 10),
false,
false,
true);
247 fs::path ph = m_args.GetDataDirBase() /
"existing_data_reindex";
251 std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(ph, (1 << 10),
false,
false,
false);
264 CDBWrapper odbw(ph, (1 << 10),
false,
true,
true);
282 fs::path ph = m_args.GetDataDirBase() /
"iterator_ordering";
283 CDBWrapper dbw(ph, (1 << 20),
true,
false,
false);
284 for (
int x=0x00; x<256; ++x) {
286 uint32_t value = x*x;
291 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
293 for (
unsigned int x=0x00; x<256; ++x) {
295 uint32_t value = x*x;
299 for (
const int seek_start : {0x00, 0x80}) {
300 it->Seek((uint8_t)seek_start);
301 for (
unsigned int x=seek_start; x<255; ++x) {
328 template<
typename Stream>
331 for (
size_t i = 0; i <
str.size(); i++) {
332 s << uint8_t(
str[i]);
336 template<
typename Stream>
350 fs::path ph = m_args.GetDataDirBase() /
"iterator_string_ordering";
351 CDBWrapper dbw(ph, (1 << 20),
true,
false,
false);
352 for (
int x = 0; x < 10; ++x) {
353 for (
int y = 0; y < 10; ++y) {
355 for (
int z = 0; z < y; ++z)
357 uint32_t value = x*x;
362 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
363 for (
const int seek_start : {0, 5}) {
365 for (
unsigned int x = seek_start; x < 10; ++x) {
366 for (
int y = 0; y < 10; ++y) {
368 for (
int z = 0; z < y; ++z)
392 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 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)
static uint256 InsecureRand256()
static uint64_t InsecureRandBits(int bits)
static uint32_t InsecureRand32()
static bool InsecureRandBool()
std::string ToString(const T &t)
Locale-independent version of std::to_string.
StringContentsSerializer()=default
void Unserialize(Stream &s)
void Serialize(Stream &s) const
StringContentsSerializer(const std::string &inp)