diff --git a/src/gtest/test_equihash.cpp b/src/gtest/test_equihash.cpp index c45a6f675..650966f7e 100644 --- a/src/gtest/test_equihash.cpp +++ b/src/gtest/test_equihash.cpp @@ -40,6 +40,32 @@ TEST(equihash_tests, expand_and_contract_arrays) { ParseHex("000007ff000007ff000007ff000007ff000007ff000007ff000007ff000007ff")); } +void TestMinimalSolnRepr(const std::string &scope, size_t cBitLen, + std::vector indices, + std::vector minimal) +{ + SCOPED_TRACE(scope); + + EXPECT_EQ(indices, GetIndicesFromMinimal(minimal, cBitLen)); + EXPECT_EQ(minimal, GetMinimalFromIndices(indices, cBitLen)); +} + +TEST(equihash_tests, minimal_solution_representation) { + TestMinimalSolnRepr("Test 1", 20, + {1, 1, 1, 1, 1, 1, 1, 1}, + ParseHex("000008000040000200001000008000040000200001")); + TestMinimalSolnRepr("Test 2", 20, + {2097151, 2097151, 2097151, 2097151, + 2097151, 2097151, 2097151, 2097151}, + ParseHex("ffffffffffffffffffffffffffffffffffffffffff")); + TestMinimalSolnRepr("Test 3", 20, + {131071, 128, 131071, 128, 131071, 128, 131071, 128}, + ParseHex("0ffff8002003fffe000800ffff8002003fffe00080")); + TestMinimalSolnRepr("Test 4", 20, + {68, 41, 2097151, 1233, 665, 1023, 1, 1048575}, + ParseHex("000220000a7ffffe004d10014c800ffc00002fffff")); +} + TEST(equihash_tests, is_probably_duplicate) { std::shared_ptr p1 (new eh_trunc[4] {0, 1, 2, 3}); std::shared_ptr p2 (new eh_trunc[4] {0, 1, 1, 3});