|  | @ -1,6 +1,6 @@ | 
														
													
														
															
																|  |  | use super::{
 |  |  | use super::{
 | 
														
													
														
															
																|  |  |     super::{int_to_node, MerkleStore, MerkleTree, NodeIndex, PartialMerkleTree},
 |  |  |  | 
														
													
														
															
																|  |  |     ValuePath, Vec, Word,
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     super::{digests_to_words, int_to_node, MerkleStore, MerkleTree, NodeIndex, PartialMerkleTree},
 | 
														
													
														
															
																|  |  |  |  |  |     RpoDigest, ValuePath, Vec,
 | 
														
													
														
															
																|  |  | };
 |  |  | };
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | // TEST DATA
 |  |  | // TEST DATA
 | 
														
													
												
													
														
															
																|  | @ -18,7 +18,7 @@ const NODE31: NodeIndex = NodeIndex::new_unchecked(3, 1); | 
														
													
														
															
																|  |  | const NODE32: NodeIndex = NodeIndex::new_unchecked(3, 2);
 |  |  | const NODE32: NodeIndex = NodeIndex::new_unchecked(3, 2);
 | 
														
													
														
															
																|  |  | const NODE33: NodeIndex = NodeIndex::new_unchecked(3, 3);
 |  |  | const NODE33: NodeIndex = NodeIndex::new_unchecked(3, 3);
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | const VALUES8: [Word; 8] = [
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  | const VALUES8: [RpoDigest; 8] = [
 | 
														
													
														
															
																|  |  |     int_to_node(30),
 |  |  |     int_to_node(30),
 | 
														
													
														
															
																|  |  |     int_to_node(31),
 |  |  |     int_to_node(31),
 | 
														
													
														
															
																|  |  |     int_to_node(32),
 |  |  |     int_to_node(32),
 | 
														
													
												
													
														
															
																|  | @ -44,22 +44,21 @@ const VALUES8: [Word; 8] = [ | 
														
													
														
															
																|  |  | // (30)  (31)    (32)  (33)    (34)  (35)    (36)  (37)
 |  |  | // (30)  (31)    (32)  (33)    (34)  (35)    (36)  (37)
 | 
														
													
														
															
																|  |  | //
 |  |  | //
 | 
														
													
														
															
																|  |  | // Where node number is a concatenation of its depth and index. For example, node with
 |  |  | // Where node number is a concatenation of its depth and index. For example, node with
 | 
														
													
														
															
																|  |  | // NodeIndex(3, 5) will be labled as `35`. Leaves of the tree are shown as nodes with parenthesis
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  | // NodeIndex(3, 5) will be labeled as `35`. Leaves of the tree are shown as nodes with parenthesis
 | 
														
													
														
															
																|  |  | // (33).
 |  |  | // (33).
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | /// Checks that root returned by `root()` function is equal to the expected one.
 |  |  | /// Checks that root returned by `root()` function is equal to the expected one.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn get_root() {
 |  |  | fn get_root() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
														
															
																|  |  | 
 |  |  |  | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert_eq!(pmt.root(), expected_root.into());
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert_eq!(pmt.root(), expected_root);
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | /// This test checks correctness of the `add_path()` and `get_path()` functions. First it creates a
 |  |  | /// This test checks correctness of the `add_path()` and `get_path()` functions. First it creates a
 | 
														
													
												
													
														
															
																|  | @ -67,7 +66,7 @@ fn get_root() { | 
														
													
														
															
																|  |  | /// it checks that paths returned by `get_path()` function are equal to the expected ones.
 |  |  | /// it checks that paths returned by `get_path()` function are equal to the expected ones.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn add_and_get_paths() {
 |  |  | fn add_and_get_paths() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
												
													
														
															
																|  | @ -76,10 +75,8 @@ fn add_and_get_paths() { | 
														
													
														
															
																|  |  |     let expected_path22 = ms.get_path(expected_root, NODE22).unwrap();
 |  |  |     let expected_path22 = ms.get_path(expected_root, NODE22).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut pmt = PartialMerkleTree::new();
 |  |  |     let mut pmt = PartialMerkleTree::new();
 | 
														
													
														
															
																|  |  |     pmt.add_path(3, expected_path33.value.into(), expected_path33.path.clone())
 |  |  |  | 
														
													
														
															
																|  |  |         .unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |     pmt.add_path(2, expected_path22.value.into(), expected_path22.path.clone())
 |  |  |  | 
														
													
														
															
																|  |  |         .unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     pmt.add_path(3, expected_path33.value, expected_path33.path.clone()).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     pmt.add_path(2, expected_path22.value, expected_path22.path.clone()).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let path33 = pmt.get_path(NODE33).unwrap();
 |  |  |     let path33 = pmt.get_path(NODE33).unwrap();
 | 
														
													
														
															
																|  |  |     let path22 = pmt.get_path(NODE22).unwrap();
 |  |  |     let path22 = pmt.get_path(NODE22).unwrap();
 | 
														
													
												
													
														
															
																|  | @ -87,58 +84,58 @@ fn add_and_get_paths() { | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert_eq!(expected_path33.path, path33);
 |  |  |     assert_eq!(expected_path33.path, path33);
 | 
														
													
														
															
																|  |  |     assert_eq!(expected_path22.path, path22);
 |  |  |     assert_eq!(expected_path22.path, path22);
 | 
														
													
														
															
																|  |  |     assert_eq!(expected_root, *actual_root);
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert_eq!(expected_root, actual_root);
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | /// Checks that function `get_node` used on nodes 10 and 32 returns expected values.
 |  |  | /// Checks that function `get_node` used on nodes 10 and 32 returns expected values.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn get_node() {
 |  |  | fn get_node() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert_eq!(ms.get_node(expected_root, NODE32).unwrap(), *pmt.get_node(NODE32).unwrap());
 |  |  |  | 
														
													
														
															
																|  |  |     assert_eq!(ms.get_node(expected_root, NODE10).unwrap(), *pmt.get_node(NODE10).unwrap());
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert_eq!(ms.get_node(expected_root, NODE32).unwrap(), pmt.get_node(NODE32).unwrap());
 | 
														
													
														
															
																|  |  |  |  |  |     assert_eq!(ms.get_node(expected_root, NODE10).unwrap(), pmt.get_node(NODE10).unwrap());
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | /// Updates leaves of the PMT using `update_leaf()` function and checks that new root of the tree
 |  |  | /// Updates leaves of the PMT using `update_leaf()` function and checks that new root of the tree
 | 
														
													
														
															
																|  |  | /// is equal to the expected one.
 |  |  | /// is equal to the expected one.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn update_leaf() {
 |  |  | fn update_leaf() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let root = mt.root();
 |  |  |     let root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut ms = MerkleStore::from(&mt);
 |  |  |     let mut ms = MerkleStore::from(&mt);
 | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mut pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let new_value32 = int_to_node(132);
 |  |  |     let new_value32 = int_to_node(132);
 | 
														
													
														
															
																|  |  |     let expected_root = ms.set_node(root, NODE32, new_value32).unwrap().root;
 |  |  |     let expected_root = ms.set_node(root, NODE32, new_value32).unwrap().root;
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     pmt.update_leaf(NODE32, new_value32.into()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     pmt.update_leaf(NODE32, new_value32).unwrap();
 | 
														
													
														
															
																|  |  |     let actual_root = pmt.root();
 |  |  |     let actual_root = pmt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert_eq!(expected_root, *actual_root);
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert_eq!(expected_root, actual_root);
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let new_value20 = int_to_node(120);
 |  |  |     let new_value20 = int_to_node(120);
 | 
														
													
														
															
																|  |  |     let expected_root = ms.set_node(expected_root, NODE20, new_value20).unwrap().root;
 |  |  |     let expected_root = ms.set_node(expected_root, NODE20, new_value20).unwrap().root;
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     pmt.update_leaf(NODE20, new_value20.into()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     pmt.update_leaf(NODE20, new_value20).unwrap();
 | 
														
													
														
															
																|  |  |     let actual_root = pmt.root();
 |  |  |     let actual_root = pmt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert_eq!(expected_root, *actual_root);
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert_eq!(expected_root, actual_root);
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | /// Checks that paths of the PMT returned by `paths()` function are equal to the expected ones.
 |  |  | /// Checks that paths of the PMT returned by `paths()` function are equal to the expected ones.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn get_paths() {
 |  |  | fn get_paths() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
												
													
														
															
																|  | @ -147,8 +144,8 @@ fn get_paths() { | 
														
													
														
															
																|  |  |     let path22 = ms.get_path(expected_root, NODE22).unwrap();
 |  |  |     let path22 = ms.get_path(expected_root, NODE22).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut pmt = PartialMerkleTree::new();
 |  |  |     let mut pmt = PartialMerkleTree::new();
 | 
														
													
														
															
																|  |  |     pmt.add_path(3, path33.value.into(), path33.path.clone()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |     pmt.add_path(2, path22.value.into(), path22.path.clone()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     pmt.add_path(3, path33.value, path33.path).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     pmt.add_path(2, path22.value, path22.path).unwrap();
 | 
														
													
														
															
																|  |  |     // After PMT creation with path33 (33; 32, 20, 11) and path22 (22; 23, 10) we will have this
 |  |  |     // After PMT creation with path33 (33; 32, 20, 11) and path22 (22; 23, 10) we will have this
 | 
														
													
														
															
																|  |  |     // tree:
 |  |  |     // tree:
 | 
														
													
														
															
																|  |  |     //
 |  |  |     //
 | 
														
													
												
													
														
															
																|  | @ -170,7 +167,7 @@ fn get_paths() { | 
														
													
														
															
																|  |  |             (
 |  |  |             (
 | 
														
													
														
															
																|  |  |                 leaf,
 |  |  |                 leaf,
 | 
														
													
														
															
																|  |  |                 ValuePath {
 |  |  |                 ValuePath {
 | 
														
													
														
															
																|  |  |                     value: mt.get_node(leaf).unwrap().into(),
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |                     value: mt.get_node(leaf).unwrap(),
 | 
														
													
														
															
																|  |  |                     path: mt.get_path(leaf).unwrap(),
 |  |  |                     path: mt.get_path(leaf).unwrap(),
 | 
														
													
														
															
																|  |  |                 },
 |  |  |                 },
 | 
														
													
														
															
																|  |  |             )
 |  |  |             )
 | 
														
													
												
													
														
															
																|  | @ -185,7 +182,7 @@ fn get_paths() { | 
														
													
														
															
																|  |  | // Checks correctness of leaves determination when using the `leaves()` function.
 |  |  | // Checks correctness of leaves determination when using the `leaves()` function.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn leaves() {
 |  |  | fn leaves() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
												
													
														
															
																|  | @ -193,7 +190,7 @@ fn leaves() { | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  |     let path22 = ms.get_path(expected_root, NODE22).unwrap();
 |  |  |     let path22 = ms.get_path(expected_root, NODE22).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mut pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  |     // After PMT creation with path33 (33; 32, 20, 11) we will have this tree:
 |  |  |     // After PMT creation with path33 (33; 32, 20, 11) we will have this tree:
 | 
														
													
														
															
																|  |  |     //
 |  |  |     //
 | 
														
													
														
															
																|  |  |     //           ______root______
 |  |  |     //           ______root______
 | 
														
													
												
													
														
															
																|  | @ -206,17 +203,17 @@ fn leaves() { | 
														
													
														
															
																|  |  |     //
 |  |  |     //
 | 
														
													
														
															
																|  |  |     // Which have leaf nodes 11, 20, 32 and 33.
 |  |  |     // Which have leaf nodes 11, 20, 32 and 33.
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let value11 = mt.get_node(NODE11).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value20 = mt.get_node(NODE20).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value32 = mt.get_node(NODE32).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value33 = mt.get_node(NODE33).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let value11 = mt.get_node(NODE11).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value20 = mt.get_node(NODE20).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value32 = mt.get_node(NODE32).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value33 = mt.get_node(NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let leaves = vec![(NODE11, value11), (NODE20, value20), (NODE32, value32), (NODE33, value33)];
 |  |  |     let leaves = vec![(NODE11, value11), (NODE20, value20), (NODE32, value32), (NODE33, value33)];
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let expected_leaves = leaves.iter().map(|&tuple| tuple);
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let expected_leaves = leaves.iter().copied();
 | 
														
													
														
															
																|  |  |     assert!(expected_leaves.eq(pmt.leaves()));
 |  |  |     assert!(expected_leaves.eq(pmt.leaves()));
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     pmt.add_path(2, path22.value.into(), path22.path).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     pmt.add_path(2, path22.value, path22.path).unwrap();
 | 
														
													
														
															
																|  |  |     // After adding the path22 (22; 23, 10) to the existing PMT we will have this tree:
 |  |  |     // After adding the path22 (22; 23, 10) to the existing PMT we will have this tree:
 | 
														
													
														
															
																|  |  |     //
 |  |  |     //
 | 
														
													
														
															
																|  |  |     //           ______root______
 |  |  |     //           ______root______
 | 
														
													
												
													
														
															
																|  | @ -229,11 +226,11 @@ fn leaves() { | 
														
													
														
															
																|  |  |     //
 |  |  |     //
 | 
														
													
														
															
																|  |  |     // Which have leaf nodes 20, 22, 23, 32 and 33.
 |  |  |     // Which have leaf nodes 20, 22, 23, 32 and 33.
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let value20 = mt.get_node(NODE20).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value22 = mt.get_node(NODE22).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value23 = mt.get_node(NODE23).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value32 = mt.get_node(NODE32).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |     let value33 = mt.get_node(NODE33).unwrap().into();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let value20 = mt.get_node(NODE20).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value22 = mt.get_node(NODE22).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value23 = mt.get_node(NODE23).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value32 = mt.get_node(NODE32).unwrap();
 | 
														
													
														
															
																|  |  |  |  |  |     let value33 = mt.get_node(NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let leaves = vec![
 |  |  |     let leaves = vec![
 | 
														
													
														
															
																|  |  |         (NODE20, value20),
 |  |  |         (NODE20, value20),
 | 
														
													
												
													
														
															
																|  | @ -243,7 +240,7 @@ fn leaves() { | 
														
													
														
															
																|  |  |         (NODE33, value33),
 |  |  |         (NODE33, value33),
 | 
														
													
														
															
																|  |  |     ];
 |  |  |     ];
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let expected_leaves = leaves.iter().map(|&tuple| tuple);
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let expected_leaves = leaves.iter().copied();
 | 
														
													
														
															
																|  |  |     assert!(expected_leaves.eq(pmt.leaves()));
 |  |  |     assert!(expected_leaves.eq(pmt.leaves()));
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
												
													
														
															
																|  | @ -254,22 +251,22 @@ fn err_add_path() { | 
														
													
														
															
																|  |  |     let path22 = vec![int_to_node(4), int_to_node(5)].into();
 |  |  |     let path22 = vec![int_to_node(4), int_to_node(5)].into();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut pmt = PartialMerkleTree::new();
 |  |  |     let mut pmt = PartialMerkleTree::new();
 | 
														
													
														
															
																|  |  |     pmt.add_path(3, int_to_node(6).into(), path33).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     pmt.add_path(3, int_to_node(6), path33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert!(pmt.add_path(2, int_to_node(7).into(), path22).is_err());
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert!(pmt.add_path(2, int_to_node(7), path22).is_err());
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | /// Checks that the request of the node which is not in the PMT will cause an error.
 |  |  | /// Checks that the request of the node which is not in the PMT will cause an error.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn err_get_node() {
 |  |  | fn err_get_node() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert!(pmt.get_node(NODE22).is_err());
 |  |  |     assert!(pmt.get_node(NODE22).is_err());
 | 
														
													
														
															
																|  |  |     assert!(pmt.get_node(NODE23).is_err());
 |  |  |     assert!(pmt.get_node(NODE23).is_err());
 | 
														
													
												
													
														
															
																|  | @ -280,14 +277,14 @@ fn err_get_node() { | 
														
													
														
															
																|  |  | /// Checks that the request of the path from the leaf which is not in the PMT will cause an error.
 |  |  | /// Checks that the request of the path from the leaf which is not in the PMT will cause an error.
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn err_get_path() {
 |  |  | fn err_get_path() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert!(pmt.get_path(NODE22).is_err());
 |  |  |     assert!(pmt.get_path(NODE22).is_err());
 | 
														
													
														
															
																|  |  |     assert!(pmt.get_path(NODE23).is_err());
 |  |  |     assert!(pmt.get_path(NODE23).is_err());
 | 
														
													
												
													
														
															
																|  | @ -297,17 +294,17 @@ fn err_get_path() { | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  | #[test]
 |  |  | #[test]
 | 
														
													
														
															
																|  |  | fn err_update_leaf() {
 |  |  | fn err_update_leaf() {
 | 
														
													
														
															
																|  |  |     let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
 | 
														
													
														
															
																|  |  |     let expected_root = mt.root();
 |  |  |     let expected_root = mt.root();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let ms = MerkleStore::from(&mt);
 |  |  |     let ms = MerkleStore::from(&mt);
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 |  |  |     let path33 = ms.get_path(expected_root, NODE33).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     let mut pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     let mut pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
 | 
														
													
														
															
																|  |  | 
 |  |  | 
 | 
														
													
														
															
																|  |  |     assert!(pmt.update_leaf(NODE22, int_to_node(22).into()).is_err());
 |  |  |  | 
														
													
														
															
																|  |  |     assert!(pmt.update_leaf(NODE23, int_to_node(23).into()).is_err());
 |  |  |  | 
														
													
														
															
																|  |  |     assert!(pmt.update_leaf(NODE30, int_to_node(30).into()).is_err());
 |  |  |  | 
														
													
														
															
																|  |  |     assert!(pmt.update_leaf(NODE31, int_to_node(31).into()).is_err());
 |  |  |  | 
														
													
														
															
																|  |  |  |  |  |     assert!(pmt.update_leaf(NODE22, int_to_node(22)).is_err());
 | 
														
													
														
															
																|  |  |  |  |  |     assert!(pmt.update_leaf(NODE23, int_to_node(23)).is_err());
 | 
														
													
														
															
																|  |  |  |  |  |     assert!(pmt.update_leaf(NODE30, int_to_node(30)).is_err());
 | 
														
													
														
															
																|  |  |  |  |  |     assert!(pmt.update_leaf(NODE31, int_to_node(31)).is_err());
 | 
														
													
														
															
																|  |  | }
 |  |  | }
 |