MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/dbwrapper_tests.cpp:22–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup)
21
22BOOST_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
73BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
74{

Callers

nothing calls this directly

Calls 15

existsFunction · 0.85
GetDataDirBaseMethod · 0.80
rand256Method · 0.80
rand32Method · 0.80
randboolMethod · 0.80
randbitsMethod · 0.80
ToStringFunction · 0.50
IsEmptyMethod · 0.45
WriteMethod · 0.45
emplace_backMethod · 0.45
ReadMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected