Skip to content

Commit e213a86

Browse files
committed
randomness removed from unittest
1 parent 00e3487 commit e213a86

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

test/unittests/test_keccak.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include <gtest/gtest.h>
1010

11-
#include <random>
12-
1311
using namespace ethash;
1412

1513
struct keccak_test_case
@@ -285,6 +283,25 @@ TEST(helpers, to_hash256_empty)
285283
EXPECT_EQ(h, hash256{});
286284
}
287285

286+
static size_t next_data_size_to_load()
287+
{
288+
static size_t next = 1;
289+
static const size_t sizes[216]
290+
= {225, 50, 73, 72, 285, 273, 139, 299, 193, 243, 43, 102, 294, 262, 209, 114, 88, 94, 179, 233, 248,
291+
182, 34, 246, 106, 148, 198, 77, 160, 289, 115, 249, 198, 26, 203, 21, 24, 65, 222, 187, 170, 281,
292+
285, 185, 261, 121, 130, 270, 22, 227, 235, 206, 116, 205, 171, 30, 163, 94, 66, 98, 112, 271, 98,
293+
91, 181, 181, 145, 290, 12, 261, 183, 82, 40, 25, 40, 164, 293, 150, 96, 195, 218, 122, 240, 99, 7,
294+
71, 155, 165, 180, 238, 131, 271, 286, 186, 255, 62, 65, 110, 205, 86, 2, 83, 182, 225, 5, 156, 138,
295+
139, 146, 3, 250, 51, 184, 282, 9, 109, 34, 245, 169, 63, 240, 100, 151, 134, 74, 125, 225, 30, 215,
296+
199, 275, 131, 128, 89, 37, 195, 286, 220, 117, 183, 32, 132, 51, 122, 244, 104, 59, 73, 45, 188, 115,
297+
231, 179, 217, 16, 110, 58, 142, 186, 215, 201, 223, 198, 152, 64, 9, 113, 39, 141, 209, 170, 84, 209,
298+
16, 92, 64, 85, 239, 128, 88, 298, 153, 28, 269, 30, 38, 46, 97, 242, 119, 102, 299, 103, 288, 251, 187,
299+
192, 8, 57, 293, 221, 43, 184, 207, 50, 129, 203, 45, 139, 0, 129, 82, 285, 254, 214, 213};
300+
301+
next = (next + 1) % 216;
302+
return sizes[next];
303+
}
304+
288305
TEST(keccak, iuf_test_simple)
289306
{
290307
const uint8_t* const data = reinterpret_cast<const uint8_t*>(test_text);
@@ -330,11 +347,11 @@ TEST(keccak, iuf_test_simple)
330347
i = 0;
331348
while(i < t.input_size)
332349
{
333-
step = (size_t)arc4random() % 300;
350+
step = next_data_size_to_load();
334351
size_t l = t.input_size - i >= step ? step : t.input_size - i;
335352
keccak256_update(&ctx, &data[i], l);
336353
i = i + step;
337-
}
354+
}
338355
const auto h2563 = keccak256_final(&ctx);
339356
ASSERT_EQ(to_hex(h2563), t.expected_hash256) << t.input_size;
340357
}
@@ -393,7 +410,7 @@ TEST(keccak, iuf_test_simple_2)
393410
size_t step = 0;
394411
while(i < t.input_size)
395412
{
396-
step = (size_t)arc4random() % 300;
413+
step = next_data_size_to_load();
397414
size_t l = t.input_size - i >= step ? step : t.input_size - i;
398415
keccak256_update_2(&ctx, &data[i], l);
399416
i = i + step;

0 commit comments

Comments
 (0)