Changeset View
Changeset View
Standalone View
Standalone View
src/test/dbwrapper_tests.cpp
Show All 21 Lines | |||||
} | } | ||||
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 (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
bool obfuscate = (bool)i; | bool obfuscate = (bool)i; | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
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 (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
bool obfuscate = (bool)i; | bool obfuscate = (bool)i; | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
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(); | ||||
char key3 = 'k'; | char key3 = 'k'; | ||||
uint256 in3 = InsecureRand256(); | uint256 in3 = InsecureRand256(); | ||||
Show All 19 Lines | for (int i = 0; i < 2; i++) { | ||||
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 (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
bool obfuscate = (bool)i; | bool obfuscate = (bool)i; | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
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)); | ||||
char key2 = 'k'; | char key2 = 'k'; | ||||
uint256 in2 = InsecureRand256(); | uint256 in2 = InsecureRand256(); | ||||
Show All 22 Lines | for (int i = 0; i < 2; i++) { | ||||
it->Next(); | it->Next(); | ||||
BOOST_CHECK_EQUAL(it->Valid(), false); | BOOST_CHECK_EQUAL(it->Valid(), false); | ||||
} | } | ||||
} | } | ||||
// Test that we do not obfuscation if there is existing data. | // Test that we do not obfuscation if there is existing data. | ||||
BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) { | BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) { | ||||
// We're going to share this boost::filesystem::path between two wrappers | // We're going to share this fs::path between two wrappers | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
create_directories(ph); | create_directories(ph); | ||||
// Set up a non-obfuscated wrapper to write some initial data. | // Set up a non-obfuscated wrapper to write some initial data. | ||||
CDBWrapper *dbw = new CDBWrapper(ph, (1 << 10), false, false, false); | CDBWrapper *dbw = new CDBWrapper(ph, (1 << 10), false, false, false); | ||||
char key = 'k'; | char key = 'k'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
uint256 res; | uint256 res; | ||||
Show All 24 Lines | BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) { | ||||
// Check that we can write successfully | // Check that we can write successfully | ||||
BOOST_CHECK(odbw.Write(key, in2)); | BOOST_CHECK(odbw.Write(key, in2)); | ||||
BOOST_CHECK(odbw.Read(key, res3)); | BOOST_CHECK(odbw.Read(key, res3)); | ||||
BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); | BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); | ||||
} | } | ||||
// Ensure that we start obfuscating during a reindex. | // Ensure that we start obfuscating during a reindex. | ||||
BOOST_AUTO_TEST_CASE(existing_data_reindex) { | BOOST_AUTO_TEST_CASE(existing_data_reindex) { | ||||
// We're going to share this boost::filesystem::path between two wrappers | // We're going to share this fs::path between two wrappers | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
create_directories(ph); | create_directories(ph); | ||||
// Set up a non-obfuscated wrapper to write some initial data. | // Set up a non-obfuscated wrapper to write some initial data. | ||||
CDBWrapper *dbw = new CDBWrapper(ph, (1 << 10), false, false, false); | CDBWrapper *dbw = new CDBWrapper(ph, (1 << 10), false, false, false); | ||||
char key = 'k'; | char key = 'k'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
uint256 res; | uint256 res; | ||||
Show All 17 Lines | BOOST_AUTO_TEST_CASE(existing_data_reindex) { | ||||
// Check that we can write successfully | // Check that we can write successfully | ||||
BOOST_CHECK(odbw.Write(key, in2)); | BOOST_CHECK(odbw.Write(key, in2)); | ||||
BOOST_CHECK(odbw.Read(key, res3)); | BOOST_CHECK(odbw.Read(key, res3)); | ||||
BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); | BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(iterator_ordering) { | BOOST_AUTO_TEST_CASE(iterator_ordering) { | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
CDBWrapper dbw(ph, (1 << 20), true, false, false); | CDBWrapper dbw(ph, (1 << 20), true, false, false); | ||||
for (int x = 0x00; x < 256; ++x) { | for (int x = 0x00; x < 256; ++x) { | ||||
uint8_t key = x; | uint8_t key = x; | ||||
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( | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(str[i]); | READWRITE(str[i]); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
BOOST_AUTO_TEST_CASE(iterator_string_ordering) { | BOOST_AUTO_TEST_CASE(iterator_string_ordering) { | ||||
char buf[10]; | char buf[10]; | ||||
boost::filesystem::path ph = boost::filesystem::temp_directory_path() / | fs::path ph = fs::temp_directory_path() / fs::unique_path(); | ||||
boost::filesystem::unique_path(); | |||||
CDBWrapper dbw(ph, (1 << 20), true, false, false); | CDBWrapper dbw(ph, (1 << 20), true, false, false); | ||||
for (int x = 0x00; x < 10; ++x) { | for (int x = 0x00; x < 10; ++x) { | ||||
for (int y = 0; y < 10; y++) { | for (int y = 0; y < 10; y++) { | ||||
sprintf(buf, "%d", x); | sprintf(buf, "%d", x); | ||||
StringContentsSerializer key(buf); | StringContentsSerializer key(buf); | ||||
for (int z = 0; z < y; z++) | for (int z = 0; z < y; z++) | ||||
key += key; | key += key; | ||||
uint32_t value = x * x; | uint32_t value = x * x; | ||||
Show All 39 Lines |