use drt_sc::types::{ BoxedBytes, RewaOrDcdtTokenIdentifier, RewaOrDcdtTokenPayment, DcdtTokenPayment, ManagedBuffer, TokenIdentifier, }; use drt_sc_scenario::{ api::StaticApi, managed_rewa_token_id, managed_test_util::check_managed_top_encode_decode, managed_token_id, managed_token_id_wrapped, drt_sc, }; #[test] fn test_rewa() { assert!(RewaOrDcdtTokenIdentifier::::rewa().is_rewa()); } #[test] fn test_codec() { check_managed_top_encode_decode( RewaOrDcdtTokenIdentifier::::rewa(), RewaOrDcdtTokenIdentifier::::REWA_REPRESENTATION, ); let expected = BoxedBytes::from_concat(&[ &[0, 0, 0, 4], &RewaOrDcdtTokenIdentifier::::REWA_REPRESENTATION[..], ]); check_managed_top_encode_decode( vec![RewaOrDcdtTokenIdentifier::::rewa()], expected.as_slice(), ); } #[test] #[rustfmt::skip] fn test_is_valid_dcdt_identifier() { // valid identifier assert!(TokenIdentifier::::from("ALC-6258d2").is_valid_dcdt_identifier()); // valid identifier with numbers in ticker assert!(TokenIdentifier::::from("ALC123-6258d2").is_valid_dcdt_identifier()); // valid ticker only numbers assert!(TokenIdentifier::::from("12345-6258d2").is_valid_dcdt_identifier()); // missing dash assert!(!TokenIdentifier::::from("ALC6258d2").is_valid_dcdt_identifier()); // wrong dash position assert!(!TokenIdentifier::::from("AL-C6258d2").is_valid_dcdt_identifier()); // lowercase ticker assert!(!TokenIdentifier::::from("alc-6258d2").is_valid_dcdt_identifier()); // uppercase random chars assert!(!TokenIdentifier::::from("ALC-6258D2").is_valid_dcdt_identifier()); // too many random chars assert!(!TokenIdentifier::::from("ALC-6258d2ff").is_valid_dcdt_identifier()); // ticker too short assert!(!TokenIdentifier::::from("AL-6258d2").is_valid_dcdt_identifier()); // ticker too long assert!(!TokenIdentifier::::from("ALCCCCCCCCC-6258d2").is_valid_dcdt_identifier()); } #[test] #[rustfmt::skip] fn test_ticker() { // valid identifier assert_eq!( TokenIdentifier::::from("ALC-6258d2").ticker(), ManagedBuffer::::from("ALC"), ); // valid identifier with numbers in ticker assert_eq!( TokenIdentifier::::from("ALC123-6258d2").ticker(), ManagedBuffer::::from("ALC123"), ); // valid ticker only numbers assert_eq!( TokenIdentifier::::from("12345-6258d2").ticker(), ManagedBuffer::::from("12345"), ); // missing dash assert_eq!( TokenIdentifier::::from("ALC6258d2").ticker(), ManagedBuffer::::from("AL"), ); // wrong dash position assert_eq!( TokenIdentifier::::from("AL-C6258d2").ticker(), ManagedBuffer::::from("AL-"), ); // lowercase ticker assert_eq!( TokenIdentifier::::from("alc-6258d2").ticker(), ManagedBuffer::::from("alc"), ); // uppercase random chars assert_eq!( TokenIdentifier::::from("ALC-6258D2").ticker(), ManagedBuffer::::from("ALC"), ); // too many random chars assert_eq!( TokenIdentifier::::from("ALC-6258d2ff").ticker(), ManagedBuffer::::from("ALC-6"), ); // ticker too short assert_eq!( TokenIdentifier::::from("AL-6258d2").ticker(), ManagedBuffer::::from("AL"), ); // ticker too long assert_eq!( TokenIdentifier::::from("ALCCCCCCCCC-6258d2").ticker(), ManagedBuffer::::from("ALCCCCCCCCC"), ); } #[test] fn test_is_valid_rewa_or_dcdt() { // rewa is always valid assert!(RewaOrDcdtTokenIdentifier::::rewa().is_valid()); // valid dcdt assert!( RewaOrDcdtTokenIdentifier::::dcdt(TokenIdentifier::from("ALC-6258d2")) .is_valid() ); // invalid dcdt, see above assert!( !RewaOrDcdtTokenIdentifier::::dcdt(TokenIdentifier::from("ALCCCCCCCCC-6258d2")) .is_valid() ); } #[test] fn test_token_identifier_eq() { assert_eq!( TokenIdentifier::::from("DCDT-00000"), TokenIdentifier::::from("DCDT-00000") ); assert_ne!( TokenIdentifier::::from("DCDT-00001"), TokenIdentifier::::from("DCDT-00002") ); assert_eq!( RewaOrDcdtTokenIdentifier::::dcdt(TokenIdentifier::from("DCDT-00003")), TokenIdentifier::::from("DCDT-00003") ); assert_ne!( RewaOrDcdtTokenIdentifier::::rewa(), TokenIdentifier::::from("ANYTHING-1234") ); assert_ne!( RewaOrDcdtTokenIdentifier::::rewa(), TokenIdentifier::::from("REWA") ); } #[test] fn test_payment_eq() { assert_eq!( DcdtTokenPayment::::new("PAY-00000".into(), 0, 1000u32.into()), DcdtTokenPayment::::new("PAY-00000".into(), 0, 1000u32.into()), ); assert_ne!( DcdtTokenPayment::::new("PAY-00001".into(), 0, 1000u32.into()), DcdtTokenPayment::::new("PAY-00002".into(), 0, 1000u32.into()), ); assert_eq!( RewaOrDcdtTokenPayment::::no_payment(), RewaOrDcdtTokenPayment::::no_payment(), ); assert_eq!( RewaOrDcdtTokenPayment::::new( RewaOrDcdtTokenIdentifier::dcdt("DCDTPAY-00000"), 0, 1000u32.into() ), RewaOrDcdtTokenPayment::::new( RewaOrDcdtTokenIdentifier::dcdt("DCDTPAY-00000"), 0, 1000u32.into() ), ); assert_ne!( RewaOrDcdtTokenPayment::::new( RewaOrDcdtTokenIdentifier::dcdt("DCDTPAY-00001"), 0, 1000u32.into() ), RewaOrDcdtTokenPayment::::new( RewaOrDcdtTokenIdentifier::dcdt("DCDTPAY-00002"), 0, 1000u32.into() ), ); assert_ne!( RewaOrDcdtTokenPayment::::new( RewaOrDcdtTokenIdentifier::dcdt("DCDTPAY-00001"), 0, 1000u32.into() ), RewaOrDcdtTokenPayment::::no_payment(), ); } #[test] fn test_managed_token_id_macro() { assert_eq!( managed_rewa_token_id!(), RewaOrDcdtTokenIdentifier::::rewa() ); assert_eq!( managed_token_id!(b"ALC-6258d2"), TokenIdentifier::::from("ALC-6258d2") ); assert_eq!( managed_token_id_wrapped!(b"ALC-6258d2").unwrap_dcdt(), TokenIdentifier::::from("ALC-6258d2") ) }