2121 * using BOOST_CHECK_CLOSE to fail.
2222 *
2323 */
24- FastRandomContext local_rand_ctx (true );
25-
2624BOOST_AUTO_TEST_SUITE (cuckoocache_tests);
2725
28-
29- /* * insecure_GetRandHash fills in a uint256 from local_rand_ctx
30- */
31- static void insecure_GetRandHash (uint256& t)
32- {
33- uint32_t * ptr = (uint32_t *)t.begin ();
34- for (uint8_t j = 0 ; j < 8 ; ++j)
35- *(ptr++) = local_rand_ctx.rand32 ();
36- }
37-
38-
39-
4026/* Test that no values not inserted into the cache are read out of it.
4127 *
4228 * There are no repeats in the first 200000 insecure_GetRandHash calls
4329 */
4430BOOST_AUTO_TEST_CASE (test_cuckoocache_no_fakes)
4531{
46- local_rand_ctx = FastRandomContext (true );
32+ SeedInsecureRand (true );
4733 CuckooCache::cache<uint256, SignatureCacheHasher> cc{};
4834 size_t megabytes = 4 ;
4935 cc.setup_bytes (megabytes << 20 );
50- uint256 v;
5136 for (int x = 0 ; x < 100000 ; ++x) {
52- insecure_GetRandHash (v);
53- cc.insert (v);
37+ cc.insert (InsecureRand256 ());
5438 }
5539 for (int x = 0 ; x < 100000 ; ++x) {
56- insecure_GetRandHash (v);
57- BOOST_CHECK (!cc.contains (v, false ));
40+ BOOST_CHECK (!cc.contains (InsecureRand256 (), false ));
5841 }
5942};
6043
@@ -64,7 +47,7 @@ BOOST_AUTO_TEST_CASE(test_cuckoocache_no_fakes)
6447template <typename Cache>
6548static double test_cache (size_t megabytes, double load)
6649{
67- local_rand_ctx = FastRandomContext (true );
50+ SeedInsecureRand (true );
6851 std::vector<uint256> hashes;
6952 Cache set{};
7053 size_t bytes = megabytes * (1 << 20 );
@@ -74,7 +57,7 @@ static double test_cache(size_t megabytes, double load)
7457 for (uint32_t i = 0 ; i < n_insert; ++i) {
7558 uint32_t * ptr = (uint32_t *)hashes[i].begin ();
7659 for (uint8_t j = 0 ; j < 8 ; ++j)
77- *(ptr++) = local_rand_ctx. rand32 ();
60+ *(ptr++) = InsecureRand32 ();
7861 }
7962 /* * We make a copy of the hashes because future optimizations of the
8063 * cuckoocache may overwrite the inserted element, so the test is
@@ -135,7 +118,7 @@ template <typename Cache>
135118static void test_cache_erase (size_t megabytes)
136119{
137120 double load = 1 ;
138- local_rand_ctx = FastRandomContext (true );
121+ SeedInsecureRand (true );
139122 std::vector<uint256> hashes;
140123 Cache set{};
141124 size_t bytes = megabytes * (1 << 20 );
@@ -145,7 +128,7 @@ static void test_cache_erase(size_t megabytes)
145128 for (uint32_t i = 0 ; i < n_insert; ++i) {
146129 uint32_t * ptr = (uint32_t *)hashes[i].begin ();
147130 for (uint8_t j = 0 ; j < 8 ; ++j)
148- *(ptr++) = local_rand_ctx. rand32 ();
131+ *(ptr++) = InsecureRand32 ();
149132 }
150133 /* * We make a copy of the hashes because future optimizations of the
151134 * cuckoocache may overwrite the inserted element, so the test is
@@ -198,7 +181,7 @@ template <typename Cache>
198181static void test_cache_erase_parallel (size_t megabytes)
199182{
200183 double load = 1 ;
201- local_rand_ctx = FastRandomContext (true );
184+ SeedInsecureRand (true );
202185 std::vector<uint256> hashes;
203186 Cache set{};
204187 size_t bytes = megabytes * (1 << 20 );
@@ -208,7 +191,7 @@ static void test_cache_erase_parallel(size_t megabytes)
208191 for (uint32_t i = 0 ; i < n_insert; ++i) {
209192 uint32_t * ptr = (uint32_t *)hashes[i].begin ();
210193 for (uint8_t j = 0 ; j < 8 ; ++j)
211- *(ptr++) = local_rand_ctx. rand32 ();
194+ *(ptr++) = InsecureRand32 ();
212195 }
213196 /* * We make a copy of the hashes because future optimizations of the
214197 * cuckoocache may overwrite the inserted element, so the test is
@@ -300,7 +283,7 @@ static void test_cache_generations()
300283 // iterations with non-deterministic values, so it isn't "overfit" to the
301284 // specific entropy in FastRandomContext(true) and implementation of the
302285 // cache.
303- local_rand_ctx = FastRandomContext (true );
286+ SeedInsecureRand (true );
304287
305288 // block_activity models a chunk of network activity. n_insert elements are
306289 // added to the cache. The first and last n/4 are stored for removal later
@@ -317,7 +300,7 @@ static void test_cache_generations()
317300 for (uint32_t i = 0 ; i < n_insert; ++i) {
318301 uint32_t * ptr = (uint32_t *)inserts[i].begin ();
319302 for (uint8_t j = 0 ; j < 8 ; ++j)
320- *(ptr++) = local_rand_ctx. rand32 ();
303+ *(ptr++) = InsecureRand32 ();
321304 }
322305 for (uint32_t i = 0 ; i < n_insert / 4 ; ++i)
323306 reads.push_back (inserts[i]);
0 commit comments