Skip to content

Commit

Permalink
add: tests and update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Oct 19, 2024
1 parent 0a45ca4 commit f30f735
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ classifiers = [
pre-commit = "^3.0.3"
coverage = "^7.2.7"
pyclean = "^3.0.0"
pytest = "^7.2.1"
pytest = "^8.3.3"
black = "^24.1.1"

[build-system]
Expand Down
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> [!WARNING]
> For run tests you need install javascript deps!
46 changes: 46 additions & 0 deletions test/merkle_proof/test_merkle_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,49 @@ def test_verify_merkle(leaf: str):

result = tree.proof(leaf)
assert tree.verify(result, leaf)


def get_data_from_api():
leaves = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
]
tree = MerkleTree(leaves)

leaf = "1"
proof = tree.proof(leaf)
return proof, leaf


def test_verify_merkle_proof_without_leaves():
proof, leaf = get_data_from_api()

root = "3aa22c94ceb510827b04fa792ebdd7346eb2984ebb24e58dac66d7795c2af4e8"

# Test valid proof
result = MerkleTree.verify_proof(proof, leaf, root)
assert result, "Expected proof to be valid"

# Test invalid proof scenario
invalid_leaf = "invalid_leaf_data"
invalid_result = MerkleTree.verify_proof(proof, invalid_leaf, root)
assert not invalid_result, "Expected proof to be invalid for incorrect leaf"

# Test with a different root
different_root = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
different_result = MerkleTree.verify_proof(proof, leaf, different_root)
assert not different_result, "Expected proof to be invalid for different root"

0 comments on commit f30f735

Please sign in to comment.