add tests

This commit is contained in:
Giacomo Pasini 2025-02-11 15:13:15 +01:00
parent b48f3016df
commit d817cb860a
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
2 changed files with 32 additions and 1 deletions

View File

@ -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"

View File

@ -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::<Vec<_>>()
))
);
}
#[test]
#[should_panic]