diff --git a/crates/iota-types/src/unit_tests/base_types_tests.rs b/crates/iota-types/src/unit_tests/base_types_tests.rs index 47e449d740e..471ead2e014 100644 --- a/crates/iota-types/src/unit_tests/base_types_tests.rs +++ b/crates/iota-types/src/unit_tests/base_types_tests.rs @@ -119,9 +119,8 @@ fn test_object_id_conversions() {} #[test] fn test_object_id_display() { - let hex = SAMPLE_ADDRESS; - let id = ObjectID::from_str(hex).unwrap(); - assert_eq!(format!("{:?}", id), format!("0x{hex}")); + let id = ObjectID::from_str(SAMPLE_ADDRESS).unwrap(); + assert_eq!(format!("{:?}", id), SAMPLE_ADDRESS); } #[test] @@ -187,10 +186,9 @@ fn test_object_id_deserialize_from_json_value() { #[test] fn test_object_id_serde_json() { - let hex = format!("0x{}", SAMPLE_ADDRESS); - let json_hex = format!("\"0x{}\"", SAMPLE_ADDRESS); + let json_hex = format!("\"{}\"", SAMPLE_ADDRESS); - let obj_id = ObjectID::from_hex_literal(&hex).unwrap(); + let obj_id = ObjectID::from_hex_literal(SAMPLE_ADDRESS).unwrap(); let json = serde_json::to_string(&obj_id).unwrap(); let json_obj_id: ObjectID = serde_json::from_str(&json_hex).unwrap(); @@ -215,7 +213,7 @@ fn test_object_id_serde_with_expected_value() { let json_serialized = serde_json::to_string(&object_id).unwrap(); let bcs_serialized = bcs::to_bytes(&object_id).unwrap(); - let expected_json_address = format!("\"0x{}\"", SAMPLE_ADDRESS); + let expected_json_address = format!("\"{}\"", SAMPLE_ADDRESS); assert_eq!(expected_json_address, json_serialized); assert_eq!(object_id_vec, bcs_serialized); } @@ -241,9 +239,8 @@ fn test_object_id_zero_padding() { #[test] fn test_address_display() { - let hex = SAMPLE_ADDRESS; - let id = IotaAddress::from_str(hex).unwrap(); - assert_eq!(format!("{:?}", id), format!("0x{hex}")); + let id = IotaAddress::from_str(SAMPLE_ADDRESS).unwrap(); + assert_eq!(format!("{:?}", id), SAMPLE_ADDRESS); } #[test] @@ -262,7 +259,7 @@ fn test_address_serde_not_human_readable() { fn test_address_serde_human_readable() { let address = IotaAddress::random_for_testing_only(); let serialized = serde_json::to_string(&address).unwrap(); - assert_eq!(format!("\"0x{}\"", Hex::encode(address)), serialized); + assert_eq!(format!("\"{address}\""), serialized); let deserialized: IotaAddress = serde_json::from_str(&serialized).unwrap(); assert_eq!(deserialized, address); } @@ -273,8 +270,7 @@ fn test_address_serde_with_expected_value() { let json_serialized = serde_json::to_string(&address).unwrap(); let bcs_serialized = bcs::to_bytes(&address).unwrap(); - let expected_json_address = format!("\"0x{}\"", SAMPLE_ADDRESS); - assert_eq!(expected_json_address, json_serialized); + assert_eq!(format!("\"{}\"", SAMPLE_ADDRESS), json_serialized); assert_eq!(SAMPLE_ADDRESS_VEC.to_vec(), bcs_serialized); } @@ -371,11 +367,10 @@ fn test_move_package_size_for_gas_metering() { // A sample address in hex generated by the current address derivation // algorithm. -#[cfg(test)] -const SAMPLE_ADDRESS: &str = "af306e86c74e937552df132b41a6cb3af58559f5342c6e82a98f7d1f7a4a9f30"; +const SAMPLE_ADDRESS: &str = "0xee6283a054cab26620a531d18c49ea3560239cfd8ba83a393bbaa7d7eed2082a"; const SAMPLE_ADDRESS_VEC: [u8; 32] = [ - 175, 48, 110, 134, 199, 78, 147, 117, 82, 223, 19, 43, 65, 166, 203, 58, 245, 133, 89, 245, 52, - 44, 110, 130, 169, 143, 125, 31, 122, 74, 159, 48, + 238, 98, 131, 160, 84, 202, 178, 102, 32, 165, 49, 209, 140, 73, 234, 53, 96, 35, 156, 253, + 139, 168, 58, 57, 59, 186, 167, 215, 238, 210, 8, 42, ]; // Derive a sample address and public key tuple from KeyPair bytes. @@ -396,8 +391,8 @@ fn derive_sample_address() -> (IotaAddress, AccountKeyPair) { fn test_address_backwards_compatibility() { let (address, _) = derive_sample_address(); assert_eq!( - address.to_vec(), - Hex::decode(SAMPLE_ADDRESS).expect("Decoding failed"), + address.to_string(), + SAMPLE_ADDRESS, "If this test broke, then the algorithm for deriving addresses from public keys has \ changed. If this was intentional, please compute a new sample address in hex format \ from `derive_sample_address` and update the SAMPLE_ADDRESS const above with the new \