From f30f7356eb209e49156c8ff35bae817dc690d51e Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Sat, 19 Oct 2024 03:12:53 -0300 Subject: [PATCH] add: tests and update deps --- pyproject.toml | 2 +- test/README.md | 2 ++ test/merkle_proof/test_merkle_proof.py | 46 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/README.md diff --git a/pyproject.toml b/pyproject.toml index 34beedc..9089ef8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..2217a1a --- /dev/null +++ b/test/README.md @@ -0,0 +1,2 @@ +> [!WARNING] +> For run tests you need install javascript deps! diff --git a/test/merkle_proof/test_merkle_proof.py b/test/merkle_proof/test_merkle_proof.py index b2e6a7a..88471a1 100644 --- a/test/merkle_proof/test_merkle_proof.py +++ b/test/merkle_proof/test_merkle_proof.py @@ -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"