Skip to content

Commit

Permalink
update: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Dec 31, 2023
1 parent fcd24fe commit 7b76e2f
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions test/accelerator/test_accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,26 @@
from Crypto.Hash import keccak

Check failure

Code scanning / Bandit

The pyCrypto library and its module keccak are no longer actively maintained and have been deprecated. Consider using pyca/cryptography library. Error test

The pyCrypto library and its module keccak are no longer actively maintained and have been deprecated. Consider using pyca/cryptography library.


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

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

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()

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

0 comments on commit 7b76e2f

Please sign in to comment.