3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
#include < boost/test/unit_test.hpp>
5
5
#include " cuckoocache.h"
6
+ #include " script/sigcache.h"
6
7
#include " test/test_bitcoin.h"
7
8
#include " random.h"
8
9
#include < thread>
@@ -36,20 +37,6 @@ void insecure_GetRandHash(uint256& t)
36
37
*(ptr++) = insecure_rand.rand32 ();
37
38
}
38
39
39
- /* * Definition copied from /src/script/sigcache.cpp
40
- */
41
- class uint256Hasher
42
- {
43
- public:
44
- template <uint8_t hash_select>
45
- uint32_t operator ()(const uint256& key) const
46
- {
47
- static_assert (hash_select <8 , " SignatureCacheHasher only has 8 hashes available." );
48
- uint32_t u;
49
- std::memcpy (&u, key.begin () + 4 * hash_select, 4 );
50
- return u;
51
- }
52
- };
53
40
54
41
55
42
/* Test that no values not inserted into the cache are read out of it.
@@ -59,7 +46,7 @@ class uint256Hasher
59
46
BOOST_AUTO_TEST_CASE (test_cuckoocache_no_fakes)
60
47
{
61
48
insecure_rand = FastRandomContext (true );
62
- CuckooCache::cache<uint256, uint256Hasher > cc{};
49
+ CuckooCache::cache<uint256, SignatureCacheHasher > cc{};
63
50
size_t megabytes = 4 ;
64
51
cc.setup_bytes (megabytes << 20 );
65
52
uint256 v;
@@ -138,7 +125,7 @@ BOOST_AUTO_TEST_CASE(cuckoocache_hit_rate_ok)
138
125
double HitRateThresh = 0.98 ;
139
126
size_t megabytes = 4 ;
140
127
for (double load = 0.1 ; load < 2 ; load *= 2 ) {
141
- double hits = test_cache<CuckooCache::cache<uint256, uint256Hasher >>(megabytes, load);
128
+ double hits = test_cache<CuckooCache::cache<uint256, SignatureCacheHasher >>(megabytes, load);
142
129
BOOST_CHECK (normalize_hit_rate (hits, load) > HitRateThresh);
143
130
}
144
131
}
@@ -206,7 +193,7 @@ void test_cache_erase(size_t megabytes)
206
193
BOOST_AUTO_TEST_CASE (cuckoocache_erase_ok)
207
194
{
208
195
size_t megabytes = 4 ;
209
- test_cache_erase<CuckooCache::cache<uint256, uint256Hasher >>(megabytes);
196
+ test_cache_erase<CuckooCache::cache<uint256, SignatureCacheHasher >>(megabytes);
210
197
}
211
198
212
199
template <typename Cache>
@@ -293,7 +280,7 @@ void test_cache_erase_parallel(size_t megabytes)
293
280
BOOST_AUTO_TEST_CASE (cuckoocache_erase_parallel_ok)
294
281
{
295
282
size_t megabytes = 4 ;
296
- test_cache_erase_parallel<CuckooCache::cache<uint256, uint256Hasher >>(megabytes);
283
+ test_cache_erase_parallel<CuckooCache::cache<uint256, SignatureCacheHasher >>(megabytes);
297
284
}
298
285
299
286
@@ -389,7 +376,7 @@ void test_cache_generations()
389
376
}
390
377
BOOST_AUTO_TEST_CASE (cuckoocache_generations)
391
378
{
392
- test_cache_generations<CuckooCache::cache<uint256, uint256Hasher >>();
379
+ test_cache_generations<CuckooCache::cache<uint256, SignatureCacheHasher >>();
393
380
}
394
381
395
382
BOOST_AUTO_TEST_SUITE_END ();
0 commit comments