From d817cb860a4cfa7030d97475b5fcc7ce1500a038 Mon Sep 17 00:00:00 2001 From: Giacomo Pasini Date: Tue, 11 Feb 2025 15:13:15 +0100 Subject: [PATCH] add tests --- emmarin/cl/cl/Cargo.toml | 5 +++++ emmarin/cl/cl/src/cl/indexed.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/emmarin/cl/cl/Cargo.toml b/emmarin/cl/cl/Cargo.toml index 11e567e..4dbfd30 100644 --- a/emmarin/cl/cl/Cargo.toml +++ b/emmarin/cl/cl/Cargo.toml @@ -16,3 +16,8 @@ sha2 = "0.10" lazy_static = "1.5.0" risc0-zkvm = "1.2" itertools = "0.14" + + +[dev-dependencies] +proptest = "1.2.0" +proptest-macro = "0.1" \ No newline at end of file diff --git a/emmarin/cl/cl/src/cl/indexed.rs b/emmarin/cl/cl/src/cl/indexed.rs index bf2a887..9b07e00 100644 --- a/emmarin/cl/cl/src/cl/indexed.rs +++ b/emmarin/cl/cl/src/cl/indexed.rs @@ -524,8 +524,34 @@ fn frontier_root(roots: &[Root]) -> [u8; 32] { #[cfg(test)] mod tests { - use super::*; + use proptest_macro::property_test; + + #[test] + fn test_empty_roots() { + let mut root = [0; 32]; + for i in 0..32 { + assert_eq!(root, EMPTY_ROOTS[i]); + root = merkle::node(root, root); + } + } + + #[property_test] + fn test_frontier_root(elems: Vec<[u8; 32]>) { + let mut mmr = MMR::new(); + for elem in &elems { + mmr.push(elem); + } + assert_eq!( + frontier_root(&mmr.roots), + merkle::root(&merkle::padded_leaves( + &elems + .into_iter() + .map(|array| array.to_vec()) + .collect::>() + )) + ); + } #[test] #[should_panic]