| 20 | BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup) |
| 21 | |
| 22 | BOOST_AUTO_TEST_CASE(dbwrapper) |
| 23 | { |
| 24 | // Perform tests both obfuscated and non-obfuscated. |
| 25 | for (const bool obfuscate : {false, true}) { |
| 26 | constexpr size_t CACHE_SIZE{1_MiB}; |
| 27 | const fs::path path{m_args.GetDataDirBase() / "dbwrapper"}; |
| 28 | |
| 29 | Obfuscation obfuscation; |
| 30 | std::vector<std::pair<uint8_t, uint256>> key_values{}; |
| 31 | |
| 32 | // Write values |
| 33 | { |
| 34 | CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .wipe_data = true, .obfuscate = obfuscate}}; |
| 35 | BOOST_CHECK_EQUAL(obfuscate, !dbw.IsEmpty()); |
| 36 | |
| 37 | // Ensure that we're doing real obfuscation when obfuscate=true |
| 38 | obfuscation = dbwrapper_private::GetObfuscation(dbw); |
| 39 | BOOST_CHECK_EQUAL(obfuscate, dbwrapper_private::GetObfuscation(dbw)); |
| 40 | |
| 41 | for (uint8_t k{0}; k < 10; ++k) { |
| 42 | uint8_t key{k}; |
| 43 | uint256 value{m_rng.rand256()}; |
| 44 | dbw.Write(key, value); |
| 45 | key_values.emplace_back(key, value); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Verify that the obfuscation key is never obfuscated |
| 50 | { |
| 51 | CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate = false}}; |
| 52 | BOOST_CHECK_EQUAL(obfuscation, dbwrapper_private::GetObfuscation(dbw)); |
| 53 | } |
| 54 | |
| 55 | // Read back the values |
| 56 | { |
| 57 | CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate = obfuscate}}; |
| 58 | |
| 59 | // Ensure obfuscation is read back correctly |
| 60 | BOOST_CHECK_EQUAL(obfuscation, dbwrapper_private::GetObfuscation(dbw)); |
| 61 | BOOST_CHECK_EQUAL(obfuscate, dbwrapper_private::GetObfuscation(dbw)); |
| 62 | |
| 63 | // Verify all written values |
| 64 | for (const auto& [key, expected_value] : key_values) { |
| 65 | uint256 read_value{}; |
| 66 | BOOST_CHECK(dbw.Read(key, read_value)); |
| 67 | BOOST_CHECK_EQUAL(read_value, expected_value); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_CASE(dbwrapper_basic_data) |
| 74 | { |
nothing calls this directly
no test coverage detected