@@ -42,6 +42,86 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
42
42
}
43
43
}
44
44
45
+ BOOST_AUTO_TEST_CASE (dbwrapper_basic_data)
46
+ {
47
+ // Perform tests both obfuscated and non-obfuscated.
48
+ for (bool obfuscate : {false , true }) {
49
+ fs::path ph = GetDataDir () / (obfuscate ? " dbwrapper_1_obfuscate_true" : " dbwrapper_1_obfuscate_false" );
50
+ CDBWrapper dbw (ph, (1 << 20 ), false , true , obfuscate);
51
+
52
+ uint256 res;
53
+ uint32_t res_uint_32;
54
+ bool res_bool;
55
+
56
+ // Ensure that we're doing real obfuscation when obfuscate=true
57
+ BOOST_CHECK (obfuscate != is_null_key (dbwrapper_private::GetObfuscateKey (dbw)));
58
+
59
+ // Simulate block raw data - "b + block hash"
60
+ std::string key_block = " b" + InsecureRand256 ().ToString ();
61
+
62
+ uint256 in_block = InsecureRand256 ();
63
+ BOOST_CHECK (dbw.Write (key_block, in_block));
64
+ BOOST_CHECK (dbw.Read (key_block, res));
65
+ BOOST_CHECK_EQUAL (res.ToString (), in_block.ToString ());
66
+
67
+ // Simulate file raw data - "f + file_number"
68
+ std::string key_file = strprintf (" f%04x" , InsecureRand32 ());
69
+
70
+ uint256 in_file_info = InsecureRand256 ();
71
+ BOOST_CHECK (dbw.Write (key_file, in_file_info));
72
+ BOOST_CHECK (dbw.Read (key_file, res));
73
+ BOOST_CHECK_EQUAL (res.ToString (), in_file_info.ToString ());
74
+
75
+ // Simulate transaction raw data - "t + transaction hash"
76
+ std::string key_transaction = " t" + InsecureRand256 ().ToString ();
77
+
78
+ uint256 in_transaction = InsecureRand256 ();
79
+ BOOST_CHECK (dbw.Write (key_transaction, in_transaction));
80
+ BOOST_CHECK (dbw.Read (key_transaction, res));
81
+ BOOST_CHECK_EQUAL (res.ToString (), in_transaction.ToString ());
82
+
83
+ // Simulate UTXO raw data - "c + transaction hash"
84
+ std::string key_utxo = " c" + InsecureRand256 ().ToString ();
85
+
86
+ uint256 in_utxo = InsecureRand256 ();
87
+ BOOST_CHECK (dbw.Write (key_utxo, in_utxo));
88
+ BOOST_CHECK (dbw.Read (key_utxo, res));
89
+ BOOST_CHECK_EQUAL (res.ToString (), in_utxo.ToString ());
90
+
91
+ // Simulate last block file number - "l"
92
+ char key_last_blockfile_number = ' l' ;
93
+ uint32_t lastblockfilenumber = InsecureRand32 ();
94
+ BOOST_CHECK (dbw.Write (key_last_blockfile_number, lastblockfilenumber));
95
+ BOOST_CHECK (dbw.Read (key_last_blockfile_number, res_uint_32));
96
+ BOOST_CHECK_EQUAL (lastblockfilenumber, res_uint_32);
97
+
98
+ // Simulate Is Reindexing - "R"
99
+ char key_IsReindexing = ' R' ;
100
+ bool isInReindexing = InsecureRandBool ();
101
+ BOOST_CHECK (dbw.Write (key_IsReindexing, isInReindexing));
102
+ BOOST_CHECK (dbw.Read (key_IsReindexing, res_bool));
103
+ BOOST_CHECK_EQUAL (isInReindexing, res_bool);
104
+
105
+ // Simulate last block hash up to which UXTO covers - 'B'
106
+ char key_lastblockhash_uxto = ' B' ;
107
+ uint256 lastblock_hash = InsecureRand256 ();
108
+ BOOST_CHECK (dbw.Write (key_lastblockhash_uxto, lastblock_hash));
109
+ BOOST_CHECK (dbw.Read (key_lastblockhash_uxto, res));
110
+ BOOST_CHECK_EQUAL (lastblock_hash, res);
111
+
112
+ // Simulate file raw data - "F + filename_number + filename"
113
+ std::string file_option_tag = " F" ;
114
+ uint8_t filename_length = InsecureRandBits (8 );
115
+ std::string filename = " randomfilename" ;
116
+ std::string key_file_option = strprintf (" %s%01x%s" , file_option_tag,filename_length,filename);
117
+
118
+ bool in_file_bool = InsecureRandBool ();
119
+ BOOST_CHECK (dbw.Write (key_file_option, in_file_bool));
120
+ BOOST_CHECK (dbw.Read (key_file_option, res_bool));
121
+ BOOST_CHECK_EQUAL (res_bool, in_file_bool);
122
+ }
123
+ }
124
+
45
125
// Test batch operations
46
126
BOOST_AUTO_TEST_CASE (dbwrapper_batch)
47
127
{
0 commit comments