feat(hashing): write test for merkle_root #146
Signed-off-by: Johns Beharry <johns@peakshift.com>
This commit is contained in:
parent
f68dff0e52
commit
3411f54c2e
29
beacon_chain/utils/hashing/src/merkle_root.rs
Normal file
29
beacon_chain/utils/hashing/src/merkle_root.rs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user