From a4c4c72174a8a0fc710417eeeb13566b1723ac87 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 6 Dec 2023 08:57:16 +0000 Subject: [PATCH] Test `DiversifierIndex::increment` Closes zcash/zip32#8. --- src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fd42eb6..18f8825 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -326,4 +326,33 @@ mod tests { assert!(DiversifierIndex::try_from(0x0100_0000_0000_0000_0000_0000_u128).is_err()); } + + #[test] + fn diversifier_index_increment() { + let mut di = DiversifierIndex::new(); + assert_eq!(di, 0_u32.into()); + + assert_matches!(di.increment(), Ok(_)); + assert_eq!(di, 1_u32.into()); + + assert_matches!(di.increment(), Ok(_)); + assert_eq!(di, 2_u32.into()); + + let mut di = DiversifierIndex::from(0xff_u32); + assert_eq!(di, 0x00ff_u32.into()); + + assert_matches!(di.increment(), Ok(_)); + assert_eq!(di, 0x0100_u32.into()); + + assert_matches!(di.increment(), Ok(_)); + assert_eq!(di, 0x0101_u32.into()); + + let mut di = DiversifierIndex::try_from(0x00ff_ffff_ffff_ffff_ffff_fffe_u128).unwrap(); + assert_eq!(u128::from(di), 0x00ff_ffff_ffff_ffff_ffff_fffe_u128); + + assert_matches!(di.increment(), Ok(_)); + assert_eq!(u128::from(di), 0x00ff_ffff_ffff_ffff_ffff_ffff_u128); + + assert_matches!(di.increment(), Err(_)); + } }