@@ -678,6 +678,7 @@ impl TryFrom<&[u8]> for CatalystId {
678
678
679
679
#[ cfg( test) ]
680
680
mod tests {
681
+ use chrono:: { DateTime , Utc } ;
681
682
use ed25519_dalek:: SigningKey ;
682
683
use rand:: rngs:: OsRng ;
683
684
@@ -699,8 +700,28 @@ mod tests {
699
700
/// Tests that deserialization and re-serialization round trip correctly
700
701
fn test_catalyst_id_from_str ( ) {
701
702
for id_string in CATALYST_ID_TEST_VECTOR {
703
+ let username = id_string. split_once ( '@' ) . map ( |s| s. 0 ) ;
704
+ let ( username, nonce) = username
705
+ . and_then ( |s| s. split_once ( ':' ) . map ( |( u, n) | ( u, Some ( n) ) ) )
706
+ . or_else ( || username. map ( |u| ( u, None ) ) )
707
+ . unzip ( ) ;
708
+
709
+ let nonce = nonce. flatten ( ) ;
710
+ let username = username. map ( String :: from) ;
711
+ let nonce = nonce
712
+ . map ( |n| n. parse :: < i64 > ( ) . unwrap ( ) )
713
+ . map ( |n| DateTime :: < Utc > :: from_timestamp ( n, 0 ) . unwrap ( ) ) ;
714
+
715
+ let encryption =
716
+ id_string. contains ( format ! ( "#{}" , CatalystId :: ENCRYPTION_FRAGMENT ) . as_str ( ) ) ;
717
+
702
718
let id = id_string. parse :: < CatalystId > ( ) . unwrap ( ) ;
719
+
703
720
assert_eq ! ( format!( "{id}" ) , id_string) ;
721
+ assert_eq ! ( username, id. username( ) ) ;
722
+ assert_eq ! ( nonce, id. nonce( ) ) ;
723
+ assert ! ( id. is_signature_key( ) ^ encryption) ;
724
+ assert ! ( id. is_encryption_key( ) ^ !encryption) ;
704
725
}
705
726
}
706
727
0 commit comments