Skip to content

Commit

Permalink
merkle tree tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Oct 31, 2024
1 parent 2282a7d commit 5d82720
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/katana/trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,26 @@ where

Ok(bs.root_hash(IDENTIFIER).unwrap())
}

#[cfg(test)]
mod tests {

use katana_primitives::felt;
use starknet_types_core::hash;

use super::*;

// Taken from Pathfinder: https://github.com/eqlabs/pathfinder/blob/29f93d0d6ad8758fdcf5ae3a8bd2faad2a3bc92b/crates/merkle-tree/src/transaction.rs#L70-L88
#[test]
fn test_commitment_merkle_tree() {
let hashes = vec![Felt::from(1), Felt::from(2), Felt::from(3), Felt::from(4)];

// Produced by the cairo-lang Python implementation:
// `hex(asyncio.run(calculate_patricia_root([1, 2, 3, 4], height=64, ffc=ffc))))`
let expected_root_hash =
felt!("0x1a0e579b6b444769e4626331230b5ae39bd880f47e703b73fa56bf77e52e461");
let computed_root_hash = compute_merkle_root::<hash::Pedersen>(&hashes).unwrap();

assert_eq!(expected_root_hash, computed_root_hash);
}
}

0 comments on commit 5d82720

Please sign in to comment.