Skip to content

Commit

Permalink
[Sui]: Fix address formatting (#3838)
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan authored May 13, 2024
1 parent 484dc2a commit de287c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion rust/chains/tw_sui/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl FromStr for SuiAddress {

impl fmt::Display for SuiAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0.to_hex_literal())
let prefixed = true;
write!(f, "{}", hex::encode(self.0.as_ref(), prefixed))
}
}

Expand Down Expand Up @@ -86,4 +87,12 @@ mod tests {
"0x259ff8074ab425cbb489f236e18e08f03f1a7856bdf7c7a2877bd64f738b5015"
);
}

/// https://github.com/trustwallet/wallet-core/issues/3837
#[test]
fn test_sui_address_str_with_leading_zero() {
let s = "0x0cf10169225a251113b3198dc81d15ba72286f73353a8212f03bad10bd0f0a99";
let addr = SuiAddress::from_str(s).unwrap();
assert_eq!(addr.to_string(), s);
}
}
2 changes: 1 addition & 1 deletion rust/tw_any_coin/tests/coin_address_derivation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn test_coin_address_derivation() {
CoinType::NativeZetaChain => "zeta14s0vgnj0pjnazu4hsqlksdk7slah9vcfcwctsr",
CoinType::Dydx => "dydx1ten42eesehw0ktddcp0fws7d3ycsqez3kaamq3",
CoinType::Solana => "5sn9QYhDaq61jLXJ8Li5BKqGL4DDMJQvU1rdN8XgVuwC",
CoinType::Sui => "0x1a5c6c1b74cec4fbd12b3e17252b83448136065afcdf24954dc3a9c26df4905",
CoinType::Sui => "0x01a5c6c1b74cec4fbd12b3e17252b83448136065afcdf24954dc3a9c26df4905",
// end_of_coin_address_derivation_tests_marker_do_not_modify
_ => panic!("{:?} must be covered", coin),
};
Expand Down

0 comments on commit de287c8

Please sign in to comment.