24 for (
const bool obfuscate : {
false,
true}) {
25 constexpr size_t CACHE_SIZE{1_MiB};
26 const fs::path path{m_args.GetDataDirBase() /
"dbwrapper"};
29 std::vector<std::pair<uint8_t, uint256>> key_values{};
33 CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .wipe_data =
true, .obfuscate = obfuscate}};
40 for (uint8_t
k{0};
k < 10; ++
k) {
43 dbw.
Write(key, value);
44 key_values.emplace_back(key, value);
50 CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate =
false}};
56 CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate = obfuscate}};
63 for (
const auto& [key, expected_value] : key_values) {
75 for (
bool obfuscate : {
false,
true}) {
76 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_1_obfuscate_true" :
"dbwrapper_1_obfuscate_false");
77 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
false, .wipe_data =
true, .obfuscate = obfuscate});
87 std::string key_block =
"b" + m_rng.rand256().ToString();
89 uint256 in_block = m_rng.rand256();
90 dbw.Write(key_block, in_block);
95 std::string key_file =
strprintf(
"f%04x", m_rng.rand32());
97 uint256 in_file_info = m_rng.rand256();
98 dbw.Write(key_file, in_file_info);
103 std::string key_transaction =
"t" + m_rng.rand256().ToString();
105 uint256 in_transaction = m_rng.rand256();
106 dbw.Write(key_transaction, in_transaction);
111 std::string key_utxo =
"c" + m_rng.rand256().ToString();
113 uint256 in_utxo = m_rng.rand256();
114 dbw.Write(key_utxo, in_utxo);
119 uint8_t key_last_blockfile_number{
'l'};
120 uint32_t lastblockfilenumber = m_rng.rand32();
121 dbw.Write(key_last_blockfile_number, lastblockfilenumber);
122 BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32));
126 uint8_t key_IsReindexing{
'R'};
127 bool isInReindexing = m_rng.randbool();
128 dbw.Write(key_IsReindexing, isInReindexing);
133 uint8_t key_lastblockhash_uxto{
'B'};
134 uint256 lastblock_hash = m_rng.rand256();
135 dbw.Write(key_lastblockhash_uxto, lastblock_hash);
136 BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res));
140 std::string file_option_tag =
"F";
141 uint8_t filename_length = m_rng.randbits(8);
142 std::string filename =
"randomfilename";
143 std::string key_file_option =
strprintf(
"%s%01x%s", file_option_tag, filename_length, filename);
145 bool in_file_bool = m_rng.randbool();
146 dbw.Write(key_file_option, in_file_bool);
192 for (
const bool obfuscate : {
false,
true}) {
193 fs::path ph = m_args.GetDataDirBase() / (obfuscate ?
"dbwrapper_iterator_obfuscate_true" :
"dbwrapper_iterator_obfuscate_false");
194 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate = obfuscate});
202 dbw.Write(key2, in2);
204 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
212 BOOST_REQUIRE(it->GetKey(key_res));
213 BOOST_REQUIRE(it->GetValue(val_res));
219 BOOST_REQUIRE(it->GetKey(key_res));
220 BOOST_REQUIRE(it->GetValue(val_res));
309 fs::path ph = m_args.GetDataDirBase() /
"iterator_ordering";
310 CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only =
true, .wipe_data =
false, .obfuscate =
false});
311 for (
int x=0x00; x<256; ++x) {
313 uint32_t value = x*x;
314 if (!(x & 1)) dbw.Write(key, value);
318 std::unique_ptr<CDBIterator> it(
const_cast<CDBWrapper&
>(dbw).NewIterator());
320 for (
unsigned int x=0x00; x<256; ++x) {
322 uint32_t value = x*x;
323 if (x & 1) dbw.Write(key, value);
326 for (
const int seek_start : {0x00, 0x80}) {
327 it->Seek((uint8_t)seek_start);
328 for (
unsigned int x=seek_start; x<255; ++x) {
StringContentsSerializer()=default
void Unserialize(Stream &s)
void Serialize(Stream &s) const
StringContentsSerializer(const std::string &inp)