Changeset View
Changeset View
Standalone View
Standalone View
src/test/dbwrapper_tests.cpp
Show All 19 Lines | static bool is_null_key(const std::vector<uint8_t> &key) { | ||||
return isnull; | return isnull; | ||||
} | } | ||||
BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup) | ||||
BOOST_AUTO_TEST_CASE(dbwrapper) { | BOOST_AUTO_TEST_CASE(dbwrapper) { | ||||
// Perform tests both obfuscated and non-obfuscated. | // Perform tests both obfuscated and non-obfuscated. | ||||
for (bool obfuscate : {false, true}) { | for (const bool obfuscate : {false, true}) { | ||||
fs::path ph = SetDataDir( | fs::path ph = SetDataDir( | ||||
std::string("dbwrapper").append(obfuscate ? "_true" : "_false")); | std::string("dbwrapper").append(obfuscate ? "_true" : "_false")); | ||||
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); | CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); | ||||
char key = 'k'; | char key = 'k'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
uint256 res; | uint256 res; | ||||
// Ensure that we're doing real obfuscation when obfuscate=true | // Ensure that we're doing real obfuscation when obfuscate=true | ||||
BOOST_CHECK(obfuscate != | BOOST_CHECK(obfuscate != | ||||
is_null_key(dbwrapper_private::GetObfuscateKey(dbw))); | is_null_key(dbwrapper_private::GetObfuscateKey(dbw))); | ||||
BOOST_CHECK(dbw.Write(key, in)); | BOOST_CHECK(dbw.Write(key, in)); | ||||
BOOST_CHECK(dbw.Read(key, res)); | BOOST_CHECK(dbw.Read(key, res)); | ||||
BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); | BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); | ||||
} | } | ||||
} | } | ||||
// Test batch operations | // Test batch operations | ||||
BOOST_AUTO_TEST_CASE(dbwrapper_batch) { | BOOST_AUTO_TEST_CASE(dbwrapper_batch) { | ||||
// Perform tests both obfuscated and non-obfuscated. | // Perform tests both obfuscated and non-obfuscated. | ||||
for (bool obfuscate : {false, true}) { | for (const bool obfuscate : {false, true}) { | ||||
fs::path ph = SetDataDir(std::string("dbwrapper_batch") | fs::path ph = SetDataDir(std::string("dbwrapper_batch") | ||||
.append(obfuscate ? "_true" : "_false")); | .append(obfuscate ? "_true" : "_false")); | ||||
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); | CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); | ||||
char key = 'i'; | char key = 'i'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
char key2 = 'j'; | char key2 = 'j'; | ||||
uint256 in2 = InsecureRand256(); | uint256 in2 = InsecureRand256(); | ||||
Show All 19 Lines | for (const bool obfuscate : {false, true}) { | ||||
// key3 should've never been written | // key3 should've never been written | ||||
BOOST_CHECK(dbw.Read(key3, res) == false); | BOOST_CHECK(dbw.Read(key3, res) == false); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(dbwrapper_iterator) { | BOOST_AUTO_TEST_CASE(dbwrapper_iterator) { | ||||
// Perform tests both obfuscated and non-obfuscated. | // Perform tests both obfuscated and non-obfuscated. | ||||
for (bool obfuscate : {false, true}) { | for (const bool obfuscate : {false, true}) { | ||||
fs::path ph = SetDataDir(std::string("dbwrapper_iterator") | fs::path ph = SetDataDir(std::string("dbwrapper_iterator") | ||||
.append(obfuscate ? "_true" : "_false")); | .append(obfuscate ? "_true" : "_false")); | ||||
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); | CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); | ||||
// The two keys are intentionally chosen for ordering | // The two keys are intentionally chosen for ordering | ||||
char key = 'j'; | char key = 'j'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
BOOST_CHECK(dbw.Write(key, in)); | BOOST_CHECK(dbw.Write(key, in)); | ||||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | for (int x = 0x00; x < 10; ++x) { | ||||
key += key; | key += key; | ||||
uint32_t value = x * x; | uint32_t value = x * x; | ||||
BOOST_CHECK(dbw.Write(key, value)); | BOOST_CHECK(dbw.Write(key, value)); | ||||
} | } | ||||
} | } | ||||
std::unique_ptr<CDBIterator> it( | std::unique_ptr<CDBIterator> it( | ||||
const_cast<CDBWrapper &>(dbw).NewIterator()); | const_cast<CDBWrapper &>(dbw).NewIterator()); | ||||
for (int seek_start : {0, 5}) { | for (const int seek_start : {0, 5}) { | ||||
snprintf(buf, sizeof(buf), "%d", seek_start); | snprintf(buf, sizeof(buf), "%d", seek_start); | ||||
StringContentsSerializer seek_key(buf); | StringContentsSerializer seek_key(buf); | ||||
it->Seek(seek_key); | it->Seek(seek_key); | ||||
for (unsigned int x = seek_start; x < 10; ++x) { | for (unsigned int x = seek_start; x < 10; ++x) { | ||||
for (int y = 0; y < 10; y++) { | for (int y = 0; y < 10; y++) { | ||||
snprintf(buf, sizeof(buf), "%d", x); | snprintf(buf, sizeof(buf), "%d", x); | ||||
std::string exp_key(buf); | std::string exp_key(buf); | ||||
for (int z = 0; z < y; z++) | for (int z = 0; z < y; z++) | ||||
Show All 19 Lines |