src/test/dbwrapper_tests.cpp
BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
{
    // We're going to share this fs::path between two wrappers
    fs::path ph = fs::temp_directory_path() / fs::unique_path();
    create_directories(ph);

    // Set up a non-obfuscated wrapper to write some initial data.
    CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
    char key = 'k';
    uint256 in = InsecureRand256();
    uint256 res;

    BOOST_CHECK(dbw->Write(key, in));
    BOOST_CHECK(dbw->Read(key, res));
    BOOST_CHECK_EQUAL(res.ToString(), in.ToString());

    // Call the destructor to free leveldb LOCK
    delete dbw;

    // Now, set up another wrapper that wants to obfuscate the same directory
    CDBWrapper odbw(ph, (1 << 10), false, false, true);

    // Check that the key/val we wrote with unobfuscated wrapper exists and 
    // is readable.
    uint256 res2;
    BOOST_CHECK(odbw.Read(key, res2));
    BOOST_CHECK_EQUAL(res2.ToString(), in.ToString());

    BOOST_CHECK(!odbw.IsEmpty()); // There should be existing data
    BOOST_CHECK(is_null_key(dbwrapper_private::GetObfuscateKey(odbw))); // The key should be an empty string

    uint256 in2 = InsecureRand256();
    uint256 res3;

    // Check that we can write successfully
    BOOST_CHECK(odbw.Write(key, in2));
    BOOST_CHECK(odbw.Read(key, res3));
    BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString());
}
// Test that we do not obfuscation if there is existing data.
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)
{
    fs::path ph = fs::temp_directory_path() / fs::unique_path();
    create_directories(ph);
    CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
    char key = 'k';
    uint256 in = InsecureRand256();
    uint256 res;
    BOOST_CHECK(dbw->Write(key, in));
    BOOST_CHECK(dbw->Read(key, res));
    BOOST_CHECK_EQUAL(res.ToString(), in.ToString());
    delete dbw;
    CDBWrapper odbw(ph, (1 << 10), false, false, true);
    uint256 res2;
    BOOST_CHECK(odbw.Read(key, res2));
    BOOST_CHECK_EQUAL(res2.ToString(), in.ToString());
    BOOST_CHECK(!odbw.IsEmpty()); 
    BOOST_CHECK(is_null_key(dbwrapper_private::GetObfuscateKey(odbw))); 
    uint256 in2 = InsecureRand256();
    uint256 res3;
    BOOST_CHECK(odbw.Write(key, in2));
    BOOST_CHECK(odbw.Read(key, res3));
    BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString());
}
BOOST_AUTO_TEST_CASE ( existing_data_no_obfuscate ) { fs :: path ph = fs :: temp_directory_path ( ) / fs :: unique_path ( ) ; create_directories ( ph ) ; CDBWrapper * dbw = new CDBWrapper ( ph , ( 1 << 10 ) , false , false , false ) ; char key = ' ' ; uint256 in = InsecureRand256 ( ) ; uint256 res ; BOOST_CHECK ( dbw -> Write ( key , in ) ) ; BOOST_CHECK ( dbw -> Read ( key , res ) ) ; BOOST_CHECK_EQUAL ( res . ToString ( ) , in . ToString ( ) ) ; delete dbw ; CDBWrapper odbw ( ph , ( 1 << 10 ) , false , false , true ) ; uint256 res2 ; BOOST_CHECK ( odbw . Read ( key , res2 ) ) ; BOOST_CHECK_EQUAL ( res2 . ToString ( ) , in . ToString ( ) ) ; BOOST_CHECK ( ! odbw . IsEmpty ( ) ) ; BOOST_CHECK ( is_null_key ( dbwrapper_private :: GetObfuscateKey ( odbw ) ) ) ; uint256 in2 = InsecureRand256 ( ) ; uint256 res3 ; BOOST_CHECK ( odbw . Write ( key , in2 ) ) ; BOOST_CHECK ( odbw . Read ( key , res3 ) ) ; BOOST_CHECK_EQUAL ( res3 . ToString ( ) , in2 . ToString ( ) ) ; }
Test that we do not obfuscation if there is existing data.
Test that we do not obfuscation if there is existing data .
// We're going to share this fs::path between two wrappers // Set up a non-obfuscated wrapper to write some initial data. // Call the destructor to free leveldb LOCK // Now, set up another wrapper that wants to obfuscate the same directory // Check that the key/val we wrote with unobfuscated wrapper exists and  // is readable. // There should be existing data // The key should be an empty string // Check that we can write successfully