account_values.rs (1907B)
1 use radroots_identity::{ 2 AccountId, Error, PublicIdentity, PublicKey, 3 account::{Record, Status}, 4 }; 5 6 const ALICE: &str = "585591529da0bab31b3b1b1f986611cf5f435dca84f978c89ee8a40cca7103df"; 7 const BOB: &str = "e0266e3cfb0d2886f91c73f5f868f3b98273713e5fcd97c081663f5518a4b3af"; 8 9 fn public_identity(value: &str) -> PublicIdentity { 10 PublicIdentity::new(PublicKey::from_hex(value).expect("valid public key")) 11 } 12 13 #[test] 14 fn public_account_values_preserve_identity_and_readiness() { 15 let identity = public_identity(ALICE); 16 let record = Record::new(identity.clone(), Some("primary".into()), 10); 17 let status = Status::Ready { 18 account: record.clone(), 19 }; 20 21 assert_eq!(record.id(), AccountId::from_public_identity(&identity)); 22 assert_eq!(record.public_identity(), &identity); 23 assert_eq!(record.label(), Some("primary")); 24 assert_eq!(status.account(), Some(&record)); 25 assert!(status.is_ready()); 26 } 27 28 #[test] 29 fn decoded_account_parts_cannot_change_identity_or_reverse_time() { 30 let identity = public_identity(ALICE); 31 let wrong_id = AccountId::from_public_identity(&public_identity(BOB)); 32 33 assert!(matches!( 34 Record::try_from_parts(wrong_id, identity.clone(), None, 10, 10), 35 Err(Error::AccountIdMismatch) 36 )); 37 assert!(matches!( 38 Record::try_from_parts( 39 AccountId::from_public_identity(&identity), 40 identity, 41 None, 42 10, 43 9, 44 ), 45 Err(Error::AccountUpdatedBeforeCreated { 46 created_at_unix: 10, 47 updated_at_unix: 9, 48 }) 49 )); 50 } 51 52 #[test] 53 fn public_identity_values_are_send_sync_without_host_state() { 54 fn assert_send_sync<T: Send + Sync>() {} 55 56 assert_send_sync::<AccountId>(); 57 assert_send_sync::<PublicIdentity>(); 58 assert_send_sync::<PublicKey>(); 59 assert_send_sync::<Record>(); 60 assert_send_sync::<Status>(); 61 }