Skip to content

Commit 9c22eed

Browse files
committed
Self-test: calculate 100 hashes instead of just 1
1 parent c0cabc9 commit 9c22eed

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int p2pool_test()
9090
#ifdef WITH_RANDOMX
9191
const char myKey[] = "test key 000";
9292
const char myInput[] = "This is a test";
93-
char hash[RANDOMX_HASH_SIZE];
93+
char hash[RANDOMX_HASH_SIZE] = {};
9494

9595
const randomx_flags flags = randomx_get_flags() | RANDOMX_FLAG_FULL_MEM;
9696
randomx_cache* myCache = randomx_alloc_cache(flags);
@@ -115,14 +115,20 @@ int p2pool_test()
115115
return 1;
116116
}
117117

118-
randomx_calculate_hash(myMachine, &myInput, sizeof(myInput) - 1, hash);
118+
memcpy(hash, myInput, sizeof(myInput));
119+
120+
for (size_t i = 0; i < 100; ++i) {
121+
randomx_calculate_hash(myMachine, &hash, sizeof(hash), hash);
122+
}
119123

120124
char buf[RANDOMX_HASH_SIZE * 2 + 1] = {};
121125
p2pool::log::Stream s(buf);
122-
s << p2pool::log::hex_buf(hash, RANDOMX_HASH_SIZE);
126+
s << p2pool::log::hex_buf(hash, RANDOMX_HASH_SIZE) << '\0';
127+
128+
constexpr char expected_hash[] = "3b5ecc2bb14f467161a04fe476b541194fba82dbbbfc7c320961f922a0294dee";
123129

124-
if (memcmp(buf, "639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f", RANDOMX_HASH_SIZE * 2) != 0) {
125-
printf("Invalid hash calculated\n");
130+
if (memcmp(buf, expected_hash, RANDOMX_HASH_SIZE * 2) != 0) {
131+
printf("Invalid hash calculated: expected %s, got %s\n", expected_hash, buf);
126132
return 1;
127133
}
128134

0 commit comments

Comments
 (0)