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

Coin uses shorter format for Debug #1704

Merged
merged 4 commits into from
Jun 7, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ and this project adheres to
- cosmwasm-vm: Add `.wasm` extension to stored wasm files ([#1686]).
- cosmwasm-vm: Upgrade Wasmer to version 3.3.0.
- cosmwasm-check: Update clap dependency to version 4 ([#1677])
- cosmwasm-std: Coin uses shorter `Coin { 123 "ucosm" }` format for Debug
([#1704])

[#1511]: https://github.com/CosmWasm/cosmwasm/issues/1511
[#1629]: https://github.com/CosmWasm/cosmwasm/pull/1629
Expand All @@ -42,6 +44,7 @@ and this project adheres to
[#1667]: https://github.com/CosmWasm/cosmwasm/pull/1667
[#1677]: https://github.com/CosmWasm/cosmwasm/pull/1677
[#1686]: https://github.com/CosmWasm/cosmwasm/pull/1686
[#1704]: https://github.com/CosmWasm/cosmwasm/pull/1704

### Deprecated

Expand Down
14 changes: 13 additions & 1 deletion packages/std/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{fmt, str::FromStr};

use crate::{errors::CoinFromStrError, math::Uint128};

#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)]
pub struct Coin {
pub denom: String,
pub amount: Uint128,
Expand All @@ -19,6 +19,12 @@ impl Coin {
}
}

impl fmt::Debug for Coin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Coin {{ {} \"{}\" }}", self.amount, self.denom)
}
}

impl FromStr for Coin {
type Err = CoinFromStrError;

Expand Down Expand Up @@ -235,4 +241,10 @@ mod tests {
"Invalid amount: number too large to fit in target type"
);
}

#[test]
fn debug_coin() {
let coin = Coin::new(123, "ucosm");
assert_eq!(format!("{:?}", coin), r#"Coin { 123 "ucosm" }"#);
}
}