diff --git a/types/src/lib.rs b/types/src/lib.rs index aad79c91..04c27ffe 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -52,11 +52,7 @@ impl Kind { } pub fn to_hex(&self) -> String { - match self { - Self::Seed => hex(&[0]), - Self::Notarization => hex(&[1]), - Self::Finalization => hex(&[2]), - } + hex(&[*self as u8]) } } @@ -157,4 +153,17 @@ mod tests { // Verify finalized assert!(finalized.verify(&schemes[0], &Sequential)); } + + #[test] + fn test_kind_conversion() { + assert_eq!(Kind::from_u8(0), Some(Kind::Seed)); + assert_eq!(Kind::from_u8(1), Some(Kind::Notarization)); + assert_eq!(Kind::from_u8(2), Some(Kind::Finalization)); + assert_eq!(Kind::from_u8(3), None); + assert_eq!(Kind::from_u8(255), None); + + assert_eq!(Kind::Seed.to_hex(), "00"); + assert_eq!(Kind::Notarization.to_hex(), "01"); + assert_eq!(Kind::Finalization.to_hex(), "02"); + } }