diff --git a/test/accelerator/test_accelerator.py b/test/accelerator/test_accelerator.py index 3af0de7..9e39c8d 100644 --- a/test/accelerator/test_accelerator.py +++ b/test/accelerator/test_accelerator.py @@ -7,37 +7,26 @@ from Crypto.Hash import keccak -def hashing(data: str): +def hashing(x: bytes, y: bytes = bytes()) -> bytes: + data: bytes = x + y keccak_256 = keccak.new(digest_bits=256) - keccak_256.update(data.encode()) + keccak_256.update(data) return keccak_256.digest() -def test_merkle_root_rust(): - """ - Instantiated a simple Merkle Tree - """ - leafs = list(map(hashing, ["a", "b", "c", "d"])) - tree = MTreers() - print("PYTHON") - for x in leafs: - print(x.hex()) - - result = tree.make_root(leafs) - assert ( - result.hex() - == "6b403b6dbdd79d6bb882036292bbe89a57e10defabd5c6718e66321c79b96abd" - ), "Rust merkle root" - - -def test_merkle_root_python(): +def test_merkle_root_rust_and_merkle_root_python(): """ Instantiated a simple Merkle Tree """ leafs = ["a", "b", "c", "d"] tree = MerkleTree(leafs) + treers = MTreers() + + bytes_leaves = list(map(lambda x: x.encode(), leafs)) + hash_leaves = list(map(hashing, bytes_leaves)) + assert hash_leaves == tree.leaves + + resultrs = treers.make_root(hash_leaves) + resultpy = tree.make_root(hash_leaves) - result = tree.make_root(leafs) - assert ( - result[0] == "6b403b6dbdd79d6bb882036292bbe89a57e10defabd5c6718e66321c79b96abd" - ), "Rust merkle root" + assert resultrs.hex() == resultpy.hex()