Skip to content

Commit bc3d3fa

Browse files
MapleLakerfurszy
authored andcommitted
Add testcase to simulate bitcoin schema in leveldb
1 parent 4f15155 commit bc3d3fa

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/test/dbwrapper_tests.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,80 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
3636
}
3737
}
3838

39+
BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
40+
{
41+
fs::path ph = GetDataDir() / "dbwrapper_1";
42+
CDBWrapper dbw(ph, (1 << 20), false, true);
43+
44+
uint256 res;
45+
uint32_t res_uint_32;
46+
bool res_bool;
47+
48+
//Simulate block raw data - "b + block hash"
49+
std::string key_block = "b" + InsecureRand256().ToString();
50+
51+
uint256 in_block = InsecureRand256();
52+
BOOST_CHECK(dbw.Write(key_block, in_block));
53+
BOOST_CHECK(dbw.Read(key_block, res));
54+
BOOST_CHECK_EQUAL(res.ToString(), in_block.ToString());
55+
56+
//Simulate file raw data - "f + file_number"
57+
std::string key_file = strprintf("f%04x", InsecureRand32());
58+
59+
uint256 in_file_info = InsecureRand256();
60+
BOOST_CHECK(dbw.Write(key_file, in_file_info));
61+
BOOST_CHECK(dbw.Read(key_file, res));
62+
BOOST_CHECK_EQUAL(res.ToString(), in_file_info.ToString());
63+
64+
//Simulate transaction raw data - "t + transaction hash"
65+
std::string key_transaction = "t" + InsecureRand256().ToString();
66+
67+
uint256 in_transaction = InsecureRand256();
68+
BOOST_CHECK(dbw.Write(key_transaction, in_transaction));
69+
BOOST_CHECK(dbw.Read(key_transaction, res));
70+
BOOST_CHECK_EQUAL(res.ToString(), in_transaction.ToString());
71+
72+
//Simulate UTXO raw data - "c + transaction hash"
73+
std::string key_utxo = "c" + InsecureRand256().ToString();
74+
75+
uint256 in_utxo = InsecureRand256();
76+
BOOST_CHECK(dbw.Write(key_utxo, in_utxo));
77+
BOOST_CHECK(dbw.Read(key_utxo, res));
78+
BOOST_CHECK_EQUAL(res.ToString(), in_utxo.ToString());
79+
80+
//Simulate last block file number - "l"
81+
char key_last_blockfile_number = 'l';
82+
uint32_t lastblockfilenumber = InsecureRand32();
83+
BOOST_CHECK(dbw.Write(key_last_blockfile_number, lastblockfilenumber));
84+
BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32));
85+
BOOST_CHECK_EQUAL(lastblockfilenumber, res_uint_32);
86+
87+
//Simulate Is Reindexing - "R"
88+
char key_IsReindexing = 'R';
89+
bool isInReindexing = InsecureRandBool();
90+
BOOST_CHECK(dbw.Write(key_IsReindexing, isInReindexing));
91+
BOOST_CHECK(dbw.Read(key_IsReindexing, res_bool));
92+
BOOST_CHECK_EQUAL(isInReindexing, res_bool);
93+
94+
//Simulate last block hash up to which UXTO covers - 'B'
95+
char key_lastblockhash_uxto = 'B';
96+
uint256 lastblock_hash = InsecureRand256();
97+
BOOST_CHECK(dbw.Write(key_lastblockhash_uxto, lastblock_hash));
98+
BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res));
99+
BOOST_CHECK_EQUAL(lastblock_hash, res);
100+
101+
//Simulate file raw data - "F + filename_number + filename"
102+
std::string file_option_tag = "F";
103+
uint8_t filename_length = InsecureRandBits(8);
104+
std::string filename = "randomfilename";
105+
std::string key_file_option = strprintf("%s%01x%s", file_option_tag,filename_length,filename);
106+
107+
bool in_file_bool = InsecureRandBool();
108+
BOOST_CHECK(dbw.Write(key_file_option, in_file_bool));
109+
BOOST_CHECK(dbw.Read(key_file_option, res_bool));
110+
BOOST_CHECK_EQUAL(res_bool, in_file_bool);
111+
}
112+
39113
// Test batch operations
40114
BOOST_AUTO_TEST_CASE(dbwrapper_batch)
41115
{

0 commit comments

Comments
 (0)