@@ -114,6 +114,10 @@ pub fn node_indices_added_by_append(old_leaf_count: u64) -> Vec<u64> {
114114
115115/// Get the node indices of the authentication path starting from the specified
116116/// leaf, to its peak.
117+ ///
118+ /// # Panics
119+ ///
120+ /// Panics if the leaf index is out-of-bounds.
117121pub fn auth_path_node_indices ( num_leafs : u64 , leaf_index : u64 ) -> Vec < u64 > {
118122 assert ! (
119123 leaf_index < num_leafs,
@@ -274,11 +278,14 @@ pub fn node_index_to_leaf_index(node_index: u64) -> Option<u64> {
274278
275279#[ cfg( test) ]
276280mod mmr_test {
281+ use proptest:: prelude:: Just ;
277282 use proptest:: prop_assert_eq;
278283 use rand:: RngCore ;
279284 use test_strategy:: proptest;
280285
281286 use super :: * ;
287+ use crate :: prelude:: Digest ;
288+ use crate :: prelude:: MmrMembershipProof ;
282289
283290 #[ test]
284291 fn leaf_index_to_node_index_test ( ) {
@@ -540,6 +547,24 @@ mod mmr_test {
540547 }
541548 }
542549
550+ #[ test]
551+ #[ should_panic( expected = "Leaf index out-of-bounds: 5/5" ) ]
552+ fn auth_path_indices_out_of_bounds_unit_test ( ) {
553+ auth_path_node_indices ( 5 , 5 ) ;
554+ }
555+
556+ #[ proptest]
557+ fn auth_path_indices_prop (
558+ #[ strategy( 0u64 ..( u64 :: MAX >>1 ) ) ] _num_leafs : u64 ,
559+ #[ strategy( 0u64 ..( #_num_leafs) ) ] leaf_index : u64 ,
560+ #[ strategy( Just ( auth_path_node_indices( #_num_leafs, #leaf_index) ) ) ] node_indices : Vec < u64 > ,
561+ ) {
562+ let mp = MmrMembershipProof {
563+ authentication_path : vec ! [ Digest :: default ( ) ; node_indices. len( ) ] ,
564+ } ;
565+ prop_assert_eq ! ( mp. get_node_indices( leaf_index) , node_indices) ;
566+ }
567+
543568 #[ test]
544569 fn auth_path_indices_unit_test ( ) {
545570 assert_eq ! ( vec![ 2 , 6 , 14 , 30 ] , auth_path_node_indices( 16 , 0 ) ) ;
0 commit comments