From 58c867655dc5c11fda75dfc3730f581576c42808 Mon Sep 17 00:00:00 2001 From: Rima <153289003+casks-mutters@users.noreply.github.com> Date: Thu, 11 Dec 2025 03:05:16 -0500 Subject: [PATCH] Test: add unit tests for leaf_commitment and pair_root functions ## Summary Currently, there are no tests for the `leaf_commitment` and `pair_root` functions. Adding tests will help ensure the correctness of these core functions. ## Proposed Changes - Create a new `tests/` directory. - Add unit tests for: - `leaf_commitment`: check that the correct commitment is returned for a given slot, address, and block. - `pair_root`: verify that it correctly computes the root from two leaf values. ## Motivation - Provides confidence that the core cryptographic functions behave as expected. - Helps detect regressions or incorrect changes in the future. --- test_attestation.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test_attestation.py diff --git a/test_attestation.py b/test_attestation.py new file mode 100644 index 0000000..5d26f72 --- /dev/null +++ b/test_attestation.py @@ -0,0 +1,20 @@ +import unittest +from attestation_tool import leaf_commitment, pair_root + +class TestAttestationFunctions(unittest.TestCase): + + def test_leaf_commitment(self): + # Example values for testing + chain_id = 1 + address = "0xYourContractAddress" + slot = 123456 + block_number = 1000 + value = bytes.fromhex("0x" + "00" * 32) # Example empty value + leaf = leaf_commitment(chain_id, address, slot, block_number, value) + self.assertEqual(len(leaf), 32) + + def test_pair_root(self): + leaf_a = bytes.fromhex("0x" + "00" * 32) + leaf_b = bytes.fromhex("0x" + "01" * 32) + root = pair_root(leaf_a, leaf_b) + self.assertEqual(len(root), 66) # Hex string of 32 bytes + 32 bytes