feat(hashing): write test for merkle_root #146

Signed-off-by: Johns Beharry <johns@peakshift.com>
This commit is contained in:
Johns Beharry 2019-01-11 19:25:13 -04:00
parent f68dff0e52
commit 3411f54c2e
No known key found for this signature in database
GPG Key ID: EC114974742E2178

View File

@ -0,0 +1,29 @@
use types::{Hash256}
use hashing::canonical_hash;
fn merkle_root(values: Vec<>) -> Hash256 {
let o = values.len();
for v in &values {
canonical_hash(v.as_bytes());
}
}
#[cfg(test)]
mod tests {
#[test]
fn calculate_merkle_root() {
let values = vec!['abc', 'lmn', 'xyz', 'o0o'];
let test_leaf_1 = canonical_hash(values[0]);
let test_leaf_2 = canonical_hash(values[1]);
let test_leaf_3 = canonical_hash(values[2]);
let test_leaf_4 = canonical_hash(values[3]);
let test_node_1 = canonical_hash(vec![test_leaf_1, test_leaf_2]);
let test_node_2 = canonical_hash(vec![test_leaf_3, test_leaf_4]);
let test_root = canonical_hash(vec![test_node_1, test_node_2]);
let result = merkle_root(values);
assert_eq!(result, test_root);
}
}