From de287c8edc1bd5c5c8aec1b1185d38c9fd1f9b5d Mon Sep 17 00:00:00 2001 From: satoshiotomakan <127754187+satoshiotomakan@users.noreply.github.com> Date: Mon, 13 May 2024 11:12:10 +0200 Subject: [PATCH] [Sui]: Fix address formatting (#3838) --- rust/chains/tw_sui/src/address.rs | 11 ++++++++++- .../tw_any_coin/tests/coin_address_derivation_test.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rust/chains/tw_sui/src/address.rs b/rust/chains/tw_sui/src/address.rs index 1ed70526d86..063418906dc 100644 --- a/rust/chains/tw_sui/src/address.rs +++ b/rust/chains/tw_sui/src/address.rs @@ -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)) } } @@ -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); + } } diff --git a/rust/tw_any_coin/tests/coin_address_derivation_test.rs b/rust/tw_any_coin/tests/coin_address_derivation_test.rs index 6be2411064a..2e9c4b0c018 100644 --- a/rust/tw_any_coin/tests/coin_address_derivation_test.rs +++ b/rust/tw_any_coin/tests/coin_address_derivation_test.rs @@ -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), };