Skip to content

Commit 0e2b400

Browse files
committed
test: Add basic Python/C++ Muhash implementation parity unit test
1 parent b85543c commit 0e2b400

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

test/functional/test_framework/muhash.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Native Python MuHash3072 implementation."""
55

66
import hashlib
7+
import unittest
78

89
from .util import modinv
910

@@ -88,3 +89,13 @@ def digest(self):
8889
val = (self.numerator * modinv(self.denominator, self.MODULUS)) % self.MODULUS
8990
bytes384 = val.to_bytes(384, 'little')
9091
return hashlib.sha256(bytes384).digest()
92+
93+
class TestFrameworkMuhash(unittest.TestCase):
94+
def test_muhash(self):
95+
muhash = MuHash3072()
96+
muhash.insert([0]*32)
97+
muhash.insert([1] + [0]*31)
98+
muhash.remove([2] + [0]*31)
99+
finalized = muhash.digest()
100+
# This mirrors the result in the C++ MuHash3072 unit test
101+
self.assertEqual(finalized[::-1].hex(), "a44e16d5e34d259b349af21c06e65d653915d2e208e4e03f389af750dc0bfdc3")

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
TEST_FRAMEWORK_MODULES = [
7070
"address",
7171
"blocktools",
72+
"muhash",
7273
"script",
7374
"util",
7475
]

0 commit comments

Comments
 (0)