Changeset View
Changeset View
Standalone View
Standalone View
src/test/dbwrapper_tests.cpp
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
// 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 fs::path between two wrappers | // We're going to share this fs::path between two wrappers | ||||
fs::path ph = fs::temp_directory_path() / fs::unique_path(); | fs::path ph = fs::temp_directory_path() / fs::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); | std::unique_ptr<CDBWrapper> dbw = std::unique_ptr<CDBWrapper>( | ||||
new CDBWrapper(ph, (1 << 10), false, false, false)); | |||||
char key = 'k'; | char key = 'k'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
uint256 res; | uint256 res; | ||||
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()); | ||||
// Call the destructor to free leveldb LOCK | // Call the destructor to free leveldb LOCK | ||||
delete dbw; | dbw.reset(); | ||||
// Now, set up another wrapper that wants to obfuscate the same directory | // Now, set up another wrapper that wants to obfuscate the same directory | ||||
CDBWrapper odbw(ph, (1 << 10), false, false, true); | CDBWrapper odbw(ph, (1 << 10), false, false, true); | ||||
// Check that the key/val we wrote with unobfuscated wrapper exists and | // Check that the key/val we wrote with unobfuscated wrapper exists and | ||||
// is readable. | // is readable. | ||||
uint256 res2; | uint256 res2; | ||||
BOOST_CHECK(odbw.Read(key, res2)); | BOOST_CHECK(odbw.Read(key, res2)); | ||||
Show All 15 Lines | |||||
// 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 fs::path between two wrappers | // We're going to share this fs::path between two wrappers | ||||
fs::path ph = fs::temp_directory_path() / fs::unique_path(); | fs::path ph = fs::temp_directory_path() / fs::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); | std::unique_ptr<CDBWrapper> dbw = std::unique_ptr<CDBWrapper>( | ||||
new CDBWrapper(ph, (1 << 10), false, false, false)); | |||||
char key = 'k'; | char key = 'k'; | ||||
uint256 in = InsecureRand256(); | uint256 in = InsecureRand256(); | ||||
uint256 res; | uint256 res; | ||||
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()); | ||||
// Call the destructor to free leveldb LOCK | // Call the destructor to free leveldb LOCK | ||||
delete dbw; | dbw.reset(); | ||||
// Simulate a -reindex by wiping the existing data store | // Simulate a -reindex by wiping the existing data store | ||||
CDBWrapper odbw(ph, (1 << 10), false, true, true); | CDBWrapper odbw(ph, (1 << 10), false, true, true); | ||||
// Check that the key/val we wrote with unobfuscated wrapper doesn't exist | // Check that the key/val we wrote with unobfuscated wrapper doesn't exist | ||||
uint256 res2; | uint256 res2; | ||||
BOOST_CHECK(!odbw.Read(key, res2)); | BOOST_CHECK(!odbw.Read(key, res2)); | ||||
BOOST_CHECK(!is_null_key(dbwrapper_private::GetObfuscateKey(odbw))); | BOOST_CHECK(!is_null_key(dbwrapper_private::GetObfuscateKey(odbw))); | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |