chore: clean up test code
This commit is contained in:
parent
0e0a3fda4f
commit
049ae32cbf
5 changed files with 66 additions and 170 deletions
|
@ -1,5 +1,5 @@
|
||||||
use super::{
|
use super::{
|
||||||
super::{InnerNodeInfo, Vec, WORD_SIZE},
|
super::{InnerNodeInfo, Vec},
|
||||||
bit::TrueBitPositionIterator,
|
bit::TrueBitPositionIterator,
|
||||||
full::{high_bitmask, leaf_to_corresponding_tree, nodes_in_forest},
|
full::{high_bitmask, leaf_to_corresponding_tree, nodes_in_forest},
|
||||||
Mmr, MmrPeaks, Rpo256,
|
Mmr, MmrPeaks, Rpo256,
|
||||||
|
@ -118,38 +118,14 @@ fn test_mmr_simple() {
|
||||||
let mut postorder = Vec::new();
|
let mut postorder = Vec::new();
|
||||||
postorder.push(LEAVES[0]);
|
postorder.push(LEAVES[0]);
|
||||||
postorder.push(LEAVES[1]);
|
postorder.push(LEAVES[1]);
|
||||||
postorder.push(Rpo256::hash_elements(
|
postorder.push(Rpo256::merge(&[LEAVES[0], LEAVES[1]]));
|
||||||
&[LEAVES[0], LEAVES[1]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
));
|
|
||||||
postorder.push(LEAVES[2]);
|
postorder.push(LEAVES[2]);
|
||||||
postorder.push(LEAVES[3]);
|
postorder.push(LEAVES[3]);
|
||||||
postorder.push(Rpo256::hash_elements(
|
postorder.push(Rpo256::merge(&[LEAVES[2], LEAVES[3]]));
|
||||||
&[LEAVES[2], LEAVES[3]]
|
postorder.push(Rpo256::merge(&[postorder[2], postorder[5]]));
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
));
|
|
||||||
postorder.push(Rpo256::hash_elements(
|
|
||||||
&[postorder[2], postorder[5]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
));
|
|
||||||
postorder.push(LEAVES[4]);
|
postorder.push(LEAVES[4]);
|
||||||
postorder.push(LEAVES[5]);
|
postorder.push(LEAVES[5]);
|
||||||
postorder.push(Rpo256::hash_elements(
|
postorder.push(Rpo256::merge(&[LEAVES[4], LEAVES[5]]));
|
||||||
&[LEAVES[4], LEAVES[5]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
));
|
|
||||||
postorder.push(LEAVES[6]);
|
postorder.push(LEAVES[6]);
|
||||||
|
|
||||||
let mut mmr = Mmr::new();
|
let mut mmr = Mmr::new();
|
||||||
|
@ -223,20 +199,8 @@ fn test_mmr_simple() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mmr_open() {
|
fn test_mmr_open() {
|
||||||
let mmr: Mmr = LEAVES.into();
|
let mmr: Mmr = LEAVES.into();
|
||||||
let h01: RpoDigest = Rpo256::hash_elements(
|
let h01 = Rpo256::merge(&[LEAVES[0], LEAVES[1]]);
|
||||||
&LEAVES[0..2]
|
let h23 = Rpo256::merge(&[LEAVES[2], LEAVES[3]]);
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let h23: RpoDigest = Rpo256::hash_elements(
|
|
||||||
&LEAVES[2..4]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// node at pos 7 is the root
|
// node at pos 7 is the root
|
||||||
assert!(mmr.open(7).is_err(), "Element 7 is not in the tree, result should be None");
|
assert!(mmr.open(7).is_err(), "Element 7 is not in the tree, result should be None");
|
||||||
|
@ -401,34 +365,10 @@ fn test_mmr_inner_nodes() {
|
||||||
let mmr: Mmr = LEAVES.into();
|
let mmr: Mmr = LEAVES.into();
|
||||||
let nodes: Vec<InnerNodeInfo> = mmr.inner_nodes().collect();
|
let nodes: Vec<InnerNodeInfo> = mmr.inner_nodes().collect();
|
||||||
|
|
||||||
let h01 = Rpo256::hash_elements(
|
let h01 = Rpo256::merge(&[LEAVES[0], LEAVES[1]]);
|
||||||
&[LEAVES[0], LEAVES[1]]
|
let h23 = Rpo256::merge(&[LEAVES[2], LEAVES[3]]);
|
||||||
.iter()
|
let h0123 = Rpo256::merge(&[h01, h23]);
|
||||||
.map(|digest| digest.into())
|
let h45 = Rpo256::merge(&[LEAVES[4], LEAVES[5]]);
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let h23 = Rpo256::hash_elements(
|
|
||||||
&[LEAVES[2], LEAVES[3]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let h0123 = Rpo256::hash_elements(
|
|
||||||
&[h01, h23]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let h45 = Rpo256::hash_elements(
|
|
||||||
&[LEAVES[4], LEAVES[5]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let postorder = vec![
|
let postorder = vec![
|
||||||
InnerNodeInfo {
|
InnerNodeInfo {
|
||||||
value: h01,
|
value: h01,
|
||||||
|
@ -461,28 +401,10 @@ fn test_mmr_hash_peaks() {
|
||||||
let peaks = mmr.accumulator();
|
let peaks = mmr.accumulator();
|
||||||
|
|
||||||
let first_peak = Rpo256::merge(&[
|
let first_peak = Rpo256::merge(&[
|
||||||
Rpo256::hash_elements(
|
Rpo256::merge(&[LEAVES[0], LEAVES[1]]),
|
||||||
&[LEAVES[0], LEAVES[1]]
|
Rpo256::merge(&[LEAVES[2], LEAVES[3]]),
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat(),
|
|
||||||
),
|
|
||||||
Rpo256::hash_elements(
|
|
||||||
&[LEAVES[2], LEAVES[3]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat(),
|
|
||||||
),
|
|
||||||
]);
|
]);
|
||||||
let second_peak = Rpo256::hash_elements(
|
let second_peak = Rpo256::merge(&[LEAVES[4], LEAVES[5]]);
|
||||||
&[LEAVES[4], LEAVES[5]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<[Felt; WORD_SIZE]>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let third_peak = LEAVES[6];
|
let third_peak = LEAVES[6];
|
||||||
|
|
||||||
// minimum length is 16
|
// minimum length is 16
|
||||||
|
@ -490,14 +412,7 @@ fn test_mmr_hash_peaks() {
|
||||||
expected_peaks.resize(16, RpoDigest::default());
|
expected_peaks.resize(16, RpoDigest::default());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
peaks.hash_peaks(),
|
peaks.hash_peaks(),
|
||||||
*Rpo256::hash_elements(
|
*Rpo256::hash_elements(&digests_to_elements(&expected_peaks))
|
||||||
&expected_peaks
|
|
||||||
.as_slice()
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,14 +432,7 @@ fn test_mmr_peaks_hash_less_than_16() {
|
||||||
expected_peaks.resize(16, RpoDigest::default());
|
expected_peaks.resize(16, RpoDigest::default());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
accumulator.hash_peaks(),
|
accumulator.hash_peaks(),
|
||||||
*Rpo256::hash_elements(
|
*Rpo256::hash_elements(&digests_to_elements(&expected_peaks))
|
||||||
&expected_peaks
|
|
||||||
.as_slice()
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -543,14 +451,7 @@ fn test_mmr_peaks_hash_odd() {
|
||||||
expected_peaks.resize(18, RpoDigest::default());
|
expected_peaks.resize(18, RpoDigest::default());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
accumulator.hash_peaks(),
|
accumulator.hash_peaks(),
|
||||||
*Rpo256::hash_elements(
|
*Rpo256::hash_elements(&digests_to_elements(&expected_peaks))
|
||||||
&expected_peaks
|
|
||||||
.as_slice()
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,3 +483,10 @@ mod property_tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HELPER FUNCTIONS
|
||||||
|
// ================================================================================================
|
||||||
|
|
||||||
|
fn digests_to_elements(digests: &[RpoDigest]) -> Vec<Felt> {
|
||||||
|
digests.iter().flat_map(|v| Word::from(v)).collect()
|
||||||
|
}
|
||||||
|
|
|
@ -103,6 +103,7 @@ const fn int_to_leaf(value: u64) -> Word {
|
||||||
[Felt::new(value), ZERO, ZERO, ZERO]
|
[Felt::new(value), ZERO, ZERO, ZERO]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn digests_to_words(digests: &[RpoDigest]) -> Vec<Word> {
|
#[cfg(test)]
|
||||||
|
fn digests_to_words(digests: &[RpoDigest]) -> Vec<Word> {
|
||||||
digests.iter().map(|d| d.into()).collect()
|
digests.iter().map(|d| d.into()).collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn build_empty_tree() {
|
||||||
// tree of depth 3
|
// tree of depth 3
|
||||||
let smt = SimpleSmt::new(3).unwrap();
|
let smt = SimpleSmt::new(3).unwrap();
|
||||||
let mt = MerkleTree::new(ZERO_VALUES8.to_vec()).unwrap();
|
let mt = MerkleTree::new(ZERO_VALUES8.to_vec()).unwrap();
|
||||||
assert_eq!(mt.root(), smt.root().into());
|
assert_eq!(mt.root(), smt.root());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -47,10 +47,10 @@ fn build_sparse_tree() {
|
||||||
// insert single value
|
// insert single value
|
||||||
let key = 6;
|
let key = 6;
|
||||||
let new_node = int_to_leaf(7);
|
let new_node = int_to_leaf(7);
|
||||||
values[key as usize] = new_node.into();
|
values[key as usize] = new_node;
|
||||||
let old_value = smt.update_leaf(key, new_node).expect("Failed to update leaf");
|
let old_value = smt.update_leaf(key, new_node).expect("Failed to update leaf");
|
||||||
let mt2 = MerkleTree::new(values.clone()).unwrap();
|
let mt2 = MerkleTree::new(values.clone()).unwrap();
|
||||||
assert_eq!(mt2.root(), smt.root().into());
|
assert_eq!(mt2.root(), smt.root());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
mt2.get_path(NodeIndex::make(3, 6)).unwrap(),
|
mt2.get_path(NodeIndex::make(3, 6)).unwrap(),
|
||||||
smt.get_path(NodeIndex::make(3, 6)).unwrap()
|
smt.get_path(NodeIndex::make(3, 6)).unwrap()
|
||||||
|
@ -63,7 +63,7 @@ fn build_sparse_tree() {
|
||||||
values[key as usize] = new_node;
|
values[key as usize] = new_node;
|
||||||
let old_value = smt.update_leaf(key, new_node).expect("Failed to update leaf");
|
let old_value = smt.update_leaf(key, new_node).expect("Failed to update leaf");
|
||||||
let mt3 = MerkleTree::new(values).unwrap();
|
let mt3 = MerkleTree::new(values).unwrap();
|
||||||
assert_eq!(mt3.root(), smt.root().into());
|
assert_eq!(mt3.root(), smt.root());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
mt3.get_path(NodeIndex::make(3, 2)).unwrap(),
|
mt3.get_path(NodeIndex::make(3, 2)).unwrap(),
|
||||||
smt.get_path(NodeIndex::make(3, 2)).unwrap()
|
smt.get_path(NodeIndex::make(3, 2)).unwrap()
|
||||||
|
@ -90,10 +90,10 @@ fn test_depth2_tree() {
|
||||||
assert_eq!(VALUES4[3], tree.get_node(NodeIndex::make(2, 3)).unwrap());
|
assert_eq!(VALUES4[3], tree.get_node(NodeIndex::make(2, 3)).unwrap());
|
||||||
|
|
||||||
// check get_path(): depth 2
|
// check get_path(): depth 2
|
||||||
assert_eq!(vec![VALUES4[1].into(), node3], *tree.get_path(NodeIndex::make(2, 0)).unwrap());
|
assert_eq!(vec![VALUES4[1], node3], *tree.get_path(NodeIndex::make(2, 0)).unwrap());
|
||||||
assert_eq!(vec![VALUES4[0].into(), node3], *tree.get_path(NodeIndex::make(2, 1)).unwrap());
|
assert_eq!(vec![VALUES4[0], node3], *tree.get_path(NodeIndex::make(2, 1)).unwrap());
|
||||||
assert_eq!(vec![VALUES4[3].into(), node2], *tree.get_path(NodeIndex::make(2, 2)).unwrap());
|
assert_eq!(vec![VALUES4[3], node2], *tree.get_path(NodeIndex::make(2, 2)).unwrap());
|
||||||
assert_eq!(vec![VALUES4[2].into(), node2], *tree.get_path(NodeIndex::make(2, 3)).unwrap());
|
assert_eq!(vec![VALUES4[2], node2], *tree.get_path(NodeIndex::make(2, 3)).unwrap());
|
||||||
|
|
||||||
// check get_path(): depth 1
|
// check get_path(): depth 1
|
||||||
assert_eq!(vec![node3], *tree.get_path(NodeIndex::make(1, 0)).unwrap());
|
assert_eq!(vec![node3], *tree.get_path(NodeIndex::make(1, 0)).unwrap());
|
||||||
|
@ -189,15 +189,15 @@ fn small_tree_opening_is_consistent() {
|
||||||
let c = Word::from(Rpo256::merge(&[b.into(); 2]));
|
let c = Word::from(Rpo256::merge(&[b.into(); 2]));
|
||||||
let d = Word::from(Rpo256::merge(&[c.into(); 2]));
|
let d = Word::from(Rpo256::merge(&[c.into(); 2]));
|
||||||
|
|
||||||
let e = RpoDigest::from(Rpo256::merge(&[a.into(), b.into()]));
|
let e = Rpo256::merge(&[a.into(), b.into()]);
|
||||||
let f = RpoDigest::from(Rpo256::merge(&[z.into(), z.into()]));
|
let f = Rpo256::merge(&[z.into(), z.into()]);
|
||||||
let g = RpoDigest::from(Rpo256::merge(&[c.into(), z.into()]));
|
let g = Rpo256::merge(&[c.into(), z.into()]);
|
||||||
let h = RpoDigest::from(Rpo256::merge(&[z.into(), d.into()]));
|
let h = Rpo256::merge(&[z.into(), d.into()]);
|
||||||
|
|
||||||
let i = RpoDigest::from(Rpo256::merge(&[e.into(), f.into()]));
|
let i = Rpo256::merge(&[e, f]);
|
||||||
let j = RpoDigest::from(Rpo256::merge(&[g.into(), h.into()]));
|
let j = Rpo256::merge(&[g, h]);
|
||||||
|
|
||||||
let k = RpoDigest::from(Rpo256::merge(&[i.into(), j.into()]));
|
let k = Rpo256::merge(&[i, j]);
|
||||||
|
|
||||||
let depth = 3;
|
let depth = 3;
|
||||||
let entries = vec![(0, a), (1, b), (4, c), (7, d)];
|
let entries = vec![(0, a), (1, b), (4, c), (7, d)];
|
||||||
|
@ -255,21 +255,9 @@ fn with_no_duplicates_empty_node() {
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
fn compute_internal_nodes() -> (RpoDigest, RpoDigest, RpoDigest) {
|
fn compute_internal_nodes() -> (RpoDigest, RpoDigest, RpoDigest) {
|
||||||
let node2 = Rpo256::hash_elements(
|
let node2 = Rpo256::merge(&[VALUES4[0], VALUES4[1]]);
|
||||||
&[VALUES4[0], VALUES4[1]]
|
let node3 = Rpo256::merge(&[VALUES4[2], VALUES4[3]]);
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let node3 = Rpo256::hash_elements(
|
|
||||||
&[VALUES4[2], VALUES4[3]]
|
|
||||||
.iter()
|
|
||||||
.map(|digest| digest.into())
|
|
||||||
.collect::<Vec<Word>>()
|
|
||||||
.concat(),
|
|
||||||
);
|
|
||||||
let root = Rpo256::merge(&[node2, node3]);
|
let root = Rpo256::merge(&[node2, node3]);
|
||||||
|
|
||||||
(root.into(), node2.into(), node3.into())
|
(root, node2, node3)
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,7 +485,6 @@ fn wont_open_to_different_depth_root() {
|
||||||
for depth in (1..=63).rev() {
|
for depth in (1..=63).rev() {
|
||||||
root = Rpo256::merge(&[root, empty[depth]]);
|
root = Rpo256::merge(&[root, empty[depth]]);
|
||||||
}
|
}
|
||||||
let root = RpoDigest::from(root);
|
|
||||||
|
|
||||||
// For this example, the depth of the Merkle tree is 1, as we have only two leaves. Here we
|
// For this example, the depth of the Merkle tree is 1, as we have only two leaves. Here we
|
||||||
// attempt to fetch a node on the maximum depth, and it should fail because the root shouldn't
|
// attempt to fetch a node on the maximum depth, and it should fail because the root shouldn't
|
||||||
|
@ -513,16 +512,16 @@ fn store_path_opens_from_leaf() {
|
||||||
let k = Rpo256::merge(&[e.into(), f.into()]);
|
let k = Rpo256::merge(&[e.into(), f.into()]);
|
||||||
let l = Rpo256::merge(&[g.into(), h.into()]);
|
let l = Rpo256::merge(&[g.into(), h.into()]);
|
||||||
|
|
||||||
let m = Rpo256::merge(&[i.into(), j.into()]);
|
let m = Rpo256::merge(&[i, j]);
|
||||||
let n = Rpo256::merge(&[k.into(), l.into()]);
|
let n = Rpo256::merge(&[k, l]);
|
||||||
|
|
||||||
let root = Rpo256::merge(&[m.into(), n.into()]);
|
let root = Rpo256::merge(&[m, n]);
|
||||||
|
|
||||||
let mtree = MerkleTree::new(vec![a, b, c, d, e, f, g, h]).unwrap();
|
let mtree = MerkleTree::new(vec![a, b, c, d, e, f, g, h]).unwrap();
|
||||||
let store = MerkleStore::from(&mtree);
|
let store = MerkleStore::from(&mtree);
|
||||||
let path = store.get_path(root, NodeIndex::make(3, 1)).unwrap().path;
|
let path = store.get_path(root, NodeIndex::make(3, 1)).unwrap().path;
|
||||||
|
|
||||||
let expected = MerklePath::new([a.into(), j.into(), n.into()].to_vec());
|
let expected = MerklePath::new([a.into(), j, n].to_vec());
|
||||||
assert_eq!(path, expected);
|
assert_eq!(path, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn tsmt_insert_one() {
|
||||||
|
|
||||||
smt.insert(key, value);
|
smt.insert(key, value);
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
// make sure the value was inserted, and the node is at the expected index
|
// make sure the value was inserted, and the node is at the expected index
|
||||||
assert_eq!(smt.get_value(key), value);
|
assert_eq!(smt.get_value(key), value);
|
||||||
|
@ -74,16 +74,16 @@ fn tsmt_insert_two_16() {
|
||||||
|
|
||||||
// --- verify that data is consistent between store and tree --------------
|
// --- verify that data is consistent between store and tree --------------
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_a), val_a);
|
assert_eq!(smt.get_value(key_a), val_a);
|
||||||
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_a).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_a).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_b), val_b);
|
assert_eq!(smt.get_value(key_b), val_b);
|
||||||
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_b).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_b).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
||||||
|
|
||||||
// make sure inner nodes match - the store contains more entries because it keeps track of
|
// make sure inner nodes match - the store contains more entries because it keeps track of
|
||||||
|
@ -130,16 +130,16 @@ fn tsmt_insert_two_32() {
|
||||||
|
|
||||||
// --- verify that data is consistent between store and tree --------------
|
// --- verify that data is consistent between store and tree --------------
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_a), val_a);
|
assert_eq!(smt.get_value(key_a), val_a);
|
||||||
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_a).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_a).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_b), val_b);
|
assert_eq!(smt.get_value(key_b), val_b);
|
||||||
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_b).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_b).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
||||||
|
|
||||||
// make sure inner nodes match - the store contains more entries because it keeps track of
|
// make sure inner nodes match - the store contains more entries because it keeps track of
|
||||||
|
@ -193,21 +193,21 @@ fn tsmt_insert_three() {
|
||||||
|
|
||||||
// --- verify that data is consistent between store and tree --------------
|
// --- verify that data is consistent between store and tree --------------
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_a), val_a);
|
assert_eq!(smt.get_value(key_a), val_a);
|
||||||
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_a).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_a).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_b), val_b);
|
assert_eq!(smt.get_value(key_b), val_b);
|
||||||
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_b).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_b).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_c), val_c);
|
assert_eq!(smt.get_value(key_c), val_c);
|
||||||
assert_eq!(smt.get_node(index_c).unwrap(), leaf_node_c);
|
assert_eq!(smt.get_node(index_c).unwrap(), leaf_node_c);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_c).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_c).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_c).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_c).unwrap(), expected_path);
|
||||||
|
|
||||||
// make sure inner nodes match - the store contains more entries because it keeps track of
|
// make sure inner nodes match - the store contains more entries because it keeps track of
|
||||||
|
@ -238,11 +238,11 @@ fn tsmt_update() {
|
||||||
let leaf_node = build_leaf_node(key, value_b, 16);
|
let leaf_node = build_leaf_node(key, value_b, 16);
|
||||||
tree_root = store.set_node(tree_root, index, leaf_node).unwrap().root;
|
tree_root = store.set_node(tree_root, index, leaf_node).unwrap().root;
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key), value_b);
|
assert_eq!(smt.get_value(key), value_b);
|
||||||
assert_eq!(smt.get_node(index).unwrap(), leaf_node);
|
assert_eq!(smt.get_node(index).unwrap(), leaf_node);
|
||||||
let expected_path = store.get_path(tree_root.into(), index).unwrap().path;
|
let expected_path = store.get_path(tree_root, index).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index).unwrap(), expected_path);
|
||||||
|
|
||||||
// make sure inner nodes match - the store contains more entries because it keeps track of
|
// make sure inner nodes match - the store contains more entries because it keeps track of
|
||||||
|
@ -285,13 +285,13 @@ fn tsmt_bottom_tier() {
|
||||||
|
|
||||||
// --- verify that data is consistent between store and tree --------------
|
// --- verify that data is consistent between store and tree --------------
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_a), val_a);
|
assert_eq!(smt.get_value(key_a), val_a);
|
||||||
assert_eq!(smt.get_value(key_b), val_b);
|
assert_eq!(smt.get_value(key_b), val_b);
|
||||||
|
|
||||||
assert_eq!(smt.get_node(index).unwrap(), leaf_node);
|
assert_eq!(smt.get_node(index).unwrap(), leaf_node);
|
||||||
let expected_path = store.get_path(tree_root.into(), index).unwrap().path;
|
let expected_path = store.get_path(tree_root, index).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index).unwrap(), expected_path);
|
||||||
|
|
||||||
// make sure inner nodes match - the store contains more entries because it keeps track of
|
// make sure inner nodes match - the store contains more entries because it keeps track of
|
||||||
|
@ -337,16 +337,16 @@ fn tsmt_bottom_tier_two() {
|
||||||
|
|
||||||
// --- verify that data is consistent between store and tree --------------
|
// --- verify that data is consistent between store and tree --------------
|
||||||
|
|
||||||
assert_eq!(smt.root(), tree_root.into());
|
assert_eq!(smt.root(), tree_root);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_a), val_a);
|
assert_eq!(smt.get_value(key_a), val_a);
|
||||||
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
assert_eq!(smt.get_node(index_a).unwrap(), leaf_node_a);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_a).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_a).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_a).unwrap(), expected_path);
|
||||||
|
|
||||||
assert_eq!(smt.get_value(key_b), val_b);
|
assert_eq!(smt.get_value(key_b), val_b);
|
||||||
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
assert_eq!(smt.get_node(index_b).unwrap(), leaf_node_b);
|
||||||
let expected_path = store.get_path(tree_root.into(), index_b).unwrap().path;
|
let expected_path = store.get_path(tree_root, index_b).unwrap().path;
|
||||||
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
assert_eq!(smt.get_path(index_b).unwrap(), expected_path);
|
||||||
|
|
||||||
// make sure inner nodes match - the store contains more entries because it keeps track of
|
// make sure inner nodes match - the store contains more entries because it keeps track of
|
||||||
|
|
Loading…
Add table
Reference in a new issue