Skip to content

Commit

Permalink
bugfix - object type should not trim leading zero
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkuo committed May 10, 2023
1 parent 18f149d commit 97e832b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 7 additions & 2 deletions crates/sui-types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use crate::multisig::MultiSigPublicKey;
use crate::object::{Object, Owner};
use crate::parse_sui_struct_tag;
use crate::signature::GenericSignature;
use crate::sui_serde::HexAccountAddress;
use crate::sui_serde::Readable;
use crate::sui_serde::{to_sui_struct_tag_string, HexAccountAddress};
use crate::transaction::Transaction;
use crate::transaction::VerifiedTransaction;
use crate::MOVE_STDLIB_ADDRESS;
Expand All @@ -53,6 +53,7 @@ use move_core_types::language_storage::StructTag;
use move_core_types::language_storage::TypeTag;
use rand::Rng;
use schemars::JsonSchema;
use serde::ser::Error;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use shared_crypto::intent::HashingIntentScope;
Expand Down Expand Up @@ -1181,7 +1182,11 @@ impl From<SuiAddress> for AccountAddress {
impl fmt::Display for MoveObjectType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
let s: StructTag = self.clone().into();
write!(f, "{}", s)
write!(
f,
"{}",
to_sui_struct_tag_string(&s).map_err(fmt::Error::custom)?
)
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/sui-types/src/sui_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ impl SerializeAs<StructTag> for SuiStructTag {
}
}

fn to_sui_struct_tag_string(value: &StructTag) -> Result<String, fmt::Error> {
/// Serialize StructTag as a string, retaining the leading zeros in the address.
pub fn to_sui_struct_tag_string(value: &StructTag) -> Result<String, fmt::Error> {
let mut f = String::new();
write!(
f,
Expand Down
14 changes: 14 additions & 0 deletions crates/sui-types/tests/serde_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use move_core_types::language_storage::StructTag;
use serde::Serialize;
use serde_json::Value;
use serde_with::serde_as;
use std::str::FromStr;
use sui_types::base_types::ObjectType;
use sui_types::parse_sui_struct_tag;
use sui_types::sui_serde::SuiStructTag;

Expand All @@ -23,3 +25,15 @@ fn test_struct_tag_serde() {
let tag2 = parse_sui_struct_tag(&json).unwrap();
assert_eq!(tag, tag2);
}

#[test]
fn test_object_type_to_string() {
let object_type = ObjectType::from_str(
"0x1a1aa18691be519899bf5187f5ce80af629407dd4f68d4175b99f4dc09497c1::custodian::AccountCap",
)
.unwrap();
assert_eq!(
object_type.to_string(),
"0x01a1aa18691be519899bf5187f5ce80af629407dd4f68d4175b99f4dc09497c1::custodian::AccountCap"
);
}

0 comments on commit 97e832b

Please sign in to comment.