Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sui]: Fix address formatting #3838

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading