Skip to content

Commit

Permalink
update: move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Dec 31, 2023
1 parent 9788ce4 commit fcd24fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def test_merkle_root_rust():
print(x.hex())

result = tree.make_root(leafs)
assert result.hex() == "6b403b6dbdd79d6bb882036292bbe89a57e10defabd5c6718e66321c79b96abd", "Rust merkle root"
assert (

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.
result.hex()
== "6b403b6dbdd79d6bb882036292bbe89a57e10defabd5c6718e66321c79b96abd"
), "Rust merkle root"


def test_merkle_root_python():
Expand All @@ -36,6 +39,5 @@ def test_merkle_root_python():

result = tree.make_root(leafs)
assert (

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.
result[0]
== "6b403b6dbdd79d6bb882036292bbe89a57e10defabd5c6718e66321c79b96abd"
result[0] == "6b403b6dbdd79d6bb882036292bbe89a57e10defabd5c6718e66321c79b96abd"
), "Rust merkle root"
9 changes: 6 additions & 3 deletions test/merkletreejs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import hashlib


def hashing(data):
return hashlib.sha256(data.encode()).hexdigest()


def hashing2(data: str):
keccak_256 = keccak.new(digest_bits=256)
keccak_256.update(data.encode())
return keccak_256.hexdigest()


class MerkleTree:
def __init__(self, leaves):
self.leaves = [hashing2(leaf) for leaf in leaves]
Expand All @@ -31,12 +34,12 @@ def get_merkle_root(self):
return self.tree[-1][0] if self.tree else None



leaves = ['a', 'b', 'c', 'd']
leaves = ["a", "b", "c", "d"]
tree = MerkleTree(leaves)

root = tree.get_merkle_root()
leafs = tree.leaves

for i in leafs: print(i)
for i in leafs:
print(i)
print(root)

0 comments on commit fcd24fe

Please sign in to comment.