diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-08-02 11:35:15 +0200 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-08-26 11:19:52 +0200 |
commit | fa0fe08eca48064b2a42789571fea017e455d820 (patch) | |
tree | 5bde0488dfc6cad7103bfca07a084f3453340f1a /src/test/dbwrapper_tests.cpp | |
parent | fa54cab4734f02422f28fdffc0f11e6d3d51b8f0 (diff) |
scripted-diff: [test] Use g_rng/m_rng directly
-BEGIN VERIFY SCRIPT-
# Use m_rng in unit test files
ren() { sed -i "s:\<$1\>:$2:g" $( git grep -l "$1" src/test/*.cpp src/wallet/test/*.cpp src/test/util/setup_common.cpp ) ; }
ren InsecureRand32 m_rng.rand32
ren InsecureRand256 m_rng.rand256
ren InsecureRandBits m_rng.randbits
ren InsecureRandRange m_rng.randrange
ren InsecureRandBool m_rng.randbool
ren g_insecure_rand_ctx m_rng
ren g_insecure_rand_ctx_temp_path g_rng_temp_path
-END VERIFY SCRIPT-
Diffstat (limited to 'src/test/dbwrapper_tests.cpp')
-rw-r--r-- | src/test/dbwrapper_tests.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 167e4be288..3a86036327 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper) fs::path ph = m_args.GetDataDirBase() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false"); CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only = true, .wipe_data = false, .obfuscate = obfuscate}); uint8_t key{'k'}; - uint256 in = InsecureRand256(); + uint256 in = m_rng.rand256(); uint256 res; // Ensure that we're doing real obfuscation when obfuscate=true @@ -60,65 +60,65 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data) BOOST_CHECK(obfuscate != is_null_key(dbwrapper_private::GetObfuscateKey(dbw))); //Simulate block raw data - "b + block hash" - std::string key_block = "b" + InsecureRand256().ToString(); + std::string key_block = "b" + m_rng.rand256().ToString(); - uint256 in_block = InsecureRand256(); + uint256 in_block = m_rng.rand256(); BOOST_CHECK(dbw.Write(key_block, in_block)); BOOST_CHECK(dbw.Read(key_block, res)); BOOST_CHECK_EQUAL(res.ToString(), in_block.ToString()); //Simulate file raw data - "f + file_number" - std::string key_file = strprintf("f%04x", InsecureRand32()); + std::string key_file = strprintf("f%04x", m_rng.rand32()); - uint256 in_file_info = InsecureRand256(); + uint256 in_file_info = m_rng.rand256(); BOOST_CHECK(dbw.Write(key_file, in_file_info)); BOOST_CHECK(dbw.Read(key_file, res)); BOOST_CHECK_EQUAL(res.ToString(), in_file_info.ToString()); //Simulate transaction raw data - "t + transaction hash" - std::string key_transaction = "t" + InsecureRand256().ToString(); + std::string key_transaction = "t" + m_rng.rand256().ToString(); - uint256 in_transaction = InsecureRand256(); + uint256 in_transaction = m_rng.rand256(); BOOST_CHECK(dbw.Write(key_transaction, in_transaction)); BOOST_CHECK(dbw.Read(key_transaction, res)); BOOST_CHECK_EQUAL(res.ToString(), in_transaction.ToString()); //Simulate UTXO raw data - "c + transaction hash" - std::string key_utxo = "c" + InsecureRand256().ToString(); + std::string key_utxo = "c" + m_rng.rand256().ToString(); - uint256 in_utxo = InsecureRand256(); + uint256 in_utxo = m_rng.rand256(); BOOST_CHECK(dbw.Write(key_utxo, in_utxo)); BOOST_CHECK(dbw.Read(key_utxo, res)); BOOST_CHECK_EQUAL(res.ToString(), in_utxo.ToString()); //Simulate last block file number - "l" uint8_t key_last_blockfile_number{'l'}; - uint32_t lastblockfilenumber = InsecureRand32(); + uint32_t lastblockfilenumber = m_rng.rand32(); BOOST_CHECK(dbw.Write(key_last_blockfile_number, lastblockfilenumber)); BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32)); BOOST_CHECK_EQUAL(lastblockfilenumber, res_uint_32); //Simulate Is Reindexing - "R" uint8_t key_IsReindexing{'R'}; - bool isInReindexing = InsecureRandBool(); + bool isInReindexing = m_rng.randbool(); BOOST_CHECK(dbw.Write(key_IsReindexing, isInReindexing)); BOOST_CHECK(dbw.Read(key_IsReindexing, res_bool)); BOOST_CHECK_EQUAL(isInReindexing, res_bool); //Simulate last block hash up to which UXTO covers - 'B' uint8_t key_lastblockhash_uxto{'B'}; - uint256 lastblock_hash = InsecureRand256(); + uint256 lastblock_hash = m_rng.rand256(); BOOST_CHECK(dbw.Write(key_lastblockhash_uxto, lastblock_hash)); BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res)); BOOST_CHECK_EQUAL(lastblock_hash, res); //Simulate file raw data - "F + filename_number + filename" std::string file_option_tag = "F"; - uint8_t filename_length = InsecureRandBits(8); + uint8_t filename_length = m_rng.randbits(8); std::string filename = "randomfilename"; std::string key_file_option = strprintf("%s%01x%s", file_option_tag,filename_length,filename); - bool in_file_bool = InsecureRandBool(); + bool in_file_bool = m_rng.randbool(); BOOST_CHECK(dbw.Write(key_file_option, in_file_bool)); BOOST_CHECK(dbw.Read(key_file_option, res_bool)); BOOST_CHECK_EQUAL(res_bool, in_file_bool); @@ -134,11 +134,11 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch) CDBWrapper dbw({.path = ph, .cache_bytes = 1 << 20, .memory_only = true, .wipe_data = false, .obfuscate = obfuscate}); uint8_t key{'i'}; - uint256 in = InsecureRand256(); + uint256 in = m_rng.rand256(); uint8_t key2{'j'}; - uint256 in2 = InsecureRand256(); + uint256 in2 = m_rng.rand256(); uint8_t key3{'k'}; - uint256 in3 = InsecureRand256(); + uint256 in3 = m_rng.rand256(); uint256 res; CDBBatch batch(dbw); @@ -171,10 +171,10 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator) // The two keys are intentionally chosen for ordering uint8_t key{'j'}; - uint256 in = InsecureRand256(); + uint256 in = m_rng.rand256(); BOOST_CHECK(dbw.Write(key, in)); uint8_t key2{'k'}; - uint256 in2 = InsecureRand256(); + uint256 in2 = m_rng.rand256(); BOOST_CHECK(dbw.Write(key2, in2)); std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator()); @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) // Set up a non-obfuscated wrapper to write some initial data. std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(DBParams{.path = ph, .cache_bytes = 1 << 10, .memory_only = false, .wipe_data = false, .obfuscate = false}); uint8_t key{'k'}; - uint256 in = InsecureRand256(); + uint256 in = m_rng.rand256(); uint256 res; BOOST_CHECK(dbw->Write(key, in)); @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) 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 in2 = m_rng.rand256(); uint256 res3; // Check that we can write successfully @@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex) // Set up a non-obfuscated wrapper to write some initial data. std::unique_ptr<CDBWrapper> dbw = std::make_unique<CDBWrapper>(DBParams{.path = ph, .cache_bytes = 1 << 10, .memory_only = false, .wipe_data = false, .obfuscate = false}); uint8_t key{'k'}; - uint256 in = InsecureRand256(); + uint256 in = m_rng.rand256(); uint256 res; BOOST_CHECK(dbw->Write(key, in)); @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex) BOOST_CHECK(!odbw.Read(key, res2)); BOOST_CHECK(!is_null_key(dbwrapper_private::GetObfuscateKey(odbw))); - uint256 in2 = InsecureRand256(); + uint256 in2 = m_rng.rand256(); uint256 res3; // Check that we can write successfully |