use elrond_wasm::types::{ BoxedBytes, EgldOrEsdtTokenIdentifier, EgldOrEsdtTokenPayment, EsdtTokenPayment, TokenIdentifier, }; use elrond_wasm_debug::{ check_managed_top_encode_decode, managed_egld_token_id, managed_token_id, managed_token_id_wrapped, DebugApi, }; #[test] fn test_egld() { let _ = DebugApi::dummy(); assert!(EgldOrEsdtTokenIdentifier::::egld().is_egld()); } #[test] fn test_codec() { let api = DebugApi::dummy(); check_managed_top_encode_decode( api.clone(), EgldOrEsdtTokenIdentifier::::egld(), EgldOrEsdtTokenIdentifier::::EGLD_REPRESENTATION, ); let expected = BoxedBytes::from_concat(&[ &[0, 0, 0, 4], &EgldOrEsdtTokenIdentifier::::EGLD_REPRESENTATION[..], ]); check_managed_top_encode_decode( api, vec![EgldOrEsdtTokenIdentifier::::egld()], expected.as_slice(), ); } #[test] #[rustfmt::skip] fn test_is_valid_esdt_identifier() { let _ = DebugApi::dummy(); // valid identifier assert!(TokenIdentifier::::from("ALC-6258d2").is_valid_esdt_identifier()); // valid identifier with numbers in ticker assert!(TokenIdentifier::::from("ALC123-6258d2").is_valid_esdt_identifier()); // valid ticker only numbers assert!(TokenIdentifier::::from("12345-6258d2").is_valid_esdt_identifier()); // missing dash assert!(!TokenIdentifier::::from("ALC6258d2").is_valid_esdt_identifier()); // wrong dash position assert!(!TokenIdentifier::::from("AL-C6258d2").is_valid_esdt_identifier()); // lowercase ticker assert!(!TokenIdentifier::::from("alc-6258d2").is_valid_esdt_identifier()); // uppercase random chars assert!(!TokenIdentifier::::from("ALC-6258D2").is_valid_esdt_identifier()); // too many random chars assert!(!TokenIdentifier::::from("ALC-6258d2ff").is_valid_esdt_identifier()); // ticker too short assert!(!TokenIdentifier::::from("AL-6258d2").is_valid_esdt_identifier()); // ticker too long assert!(!TokenIdentifier::::from("ALCCCCCCCCC-6258d2").is_valid_esdt_identifier()); } #[test] fn test_is_valid_egld_or_esdt() { let _ = DebugApi::dummy(); // egld is always valid assert!(EgldOrEsdtTokenIdentifier::::egld().is_valid()); // valid esdt assert!( EgldOrEsdtTokenIdentifier::::esdt(TokenIdentifier::from("ALC-6258d2")).is_valid() ); // invalid esdt, see above assert!( !EgldOrEsdtTokenIdentifier::::esdt(TokenIdentifier::from("ALCCCCCCCCC-6258d2")) .is_valid() ); } #[test] fn test_token_identifier_eq() { let _ = DebugApi::dummy(); assert_eq!( TokenIdentifier::::from("ESDT-00000"), TokenIdentifier::::from("ESDT-00000") ); assert_ne!( TokenIdentifier::::from("ESDT-00001"), TokenIdentifier::::from("ESDT-00002") ); assert_eq!( EgldOrEsdtTokenIdentifier::::esdt(TokenIdentifier::from("ESDT-00003")), TokenIdentifier::::from("ESDT-00003") ); assert_ne!( EgldOrEsdtTokenIdentifier::::egld(), TokenIdentifier::::from("ANYTHING-1234") ); assert_ne!( EgldOrEsdtTokenIdentifier::::egld(), TokenIdentifier::::from("EGLD") ); } #[test] fn test_payment_eq() { let _ = DebugApi::dummy(); assert_eq!( EsdtTokenPayment::::new("PAY-00000".into(), 0, 1000u32.into()), EsdtTokenPayment::::new("PAY-00000".into(), 0, 1000u32.into()), ); assert_ne!( EsdtTokenPayment::::new("PAY-00001".into(), 0, 1000u32.into()), EsdtTokenPayment::::new("PAY-00002".into(), 0, 1000u32.into()), ); assert_eq!( EgldOrEsdtTokenPayment::::no_payment(), EgldOrEsdtTokenPayment::::no_payment(), ); assert_eq!( EgldOrEsdtTokenPayment::::new( EgldOrEsdtTokenIdentifier::esdt("ESDTPAY-00000"), 0, 1000u32.into() ), EgldOrEsdtTokenPayment::::new( EgldOrEsdtTokenIdentifier::esdt("ESDTPAY-00000"), 0, 1000u32.into() ), ); assert_ne!( EgldOrEsdtTokenPayment::::new( EgldOrEsdtTokenIdentifier::esdt("ESDTPAY-00001"), 0, 1000u32.into() ), EgldOrEsdtTokenPayment::::new( EgldOrEsdtTokenIdentifier::esdt("ESDTPAY-00002"), 0, 1000u32.into() ), ); assert_ne!( EgldOrEsdtTokenPayment::::new( EgldOrEsdtTokenIdentifier::esdt("ESDTPAY-00001"), 0, 1000u32.into() ), EgldOrEsdtTokenPayment::::no_payment(), ); } #[test] fn test_managed_token_id_macro() { let _ = DebugApi::dummy(); assert_eq!( managed_egld_token_id!(), EgldOrEsdtTokenIdentifier::::egld() ); assert_eq!( managed_token_id!(b"ALC-6258d2"), TokenIdentifier::::from("ALC-6258d2") ); assert_eq!( managed_token_id_wrapped!(b"ALC-6258d2").unwrap_esdt(), TokenIdentifier::::from("ALC-6258d2") ) }