Skip to content

Commit

Permalink
Change coin constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Oct 4, 2023
1 parent b3650df commit 78bec97
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/std/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub struct Coin {
}

impl Coin {
pub fn new(amount: u128, denom: impl Into<String>) -> Self {
pub fn new(amount: impl Into<Uint128>, denom: impl Into<String>) -> Self {
Coin {
amount: Uint128::new(amount),
amount: amount.into(),
denom: denom.into(),
}
}
Expand Down Expand Up @@ -195,16 +195,16 @@ mod tests {

#[test]
fn parse_coin() {
let expected = Coin::new(123, "ucosm");
let expected = Coin::new(123u128, "ucosm");
assert_eq!("123ucosm".parse::<Coin>().unwrap(), expected);
// leading zeroes should be ignored
assert_eq!("00123ucosm".parse::<Coin>().unwrap(), expected);
// 0 amount parses correctly
assert_eq!("0ucosm".parse::<Coin>().unwrap(), Coin::new(0, "ucosm"));
assert_eq!("0ucosm".parse::<Coin>().unwrap(), Coin::new(0u128, "ucosm"));
// ibc denom should work
let ibc_str = "11111ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2";
let ibc_coin = Coin::new(
11111,
11111u128,
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
);
assert_eq!(ibc_str.parse::<Coin>().unwrap(), ibc_coin);
Expand Down Expand Up @@ -244,7 +244,7 @@ mod tests {

#[test]
fn debug_coin() {
let coin = Coin::new(123, "ucosm");
let coin = Coin::new(123u128, "ucosm");
assert_eq!(format!("{coin:?}"), r#"Coin { 123 "ucosm" }"#);
}
}
2 changes: 1 addition & 1 deletion packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ mod tests {
let msg = IbcMsg::Transfer {
channel_id: "channel-123".to_string(),
to_address: "my-special-addr".into(),
amount: Coin::new(12345678, "uatom"),
amount: Coin::new(12345678u128, "uatom"),
timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)),
};
let encoded = to_string(&msg).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions packages/std/src/query/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ mod tests {

#[test]
fn private_constructor_works() {
let response = AllBalanceResponse::new(vec![Coin::new(1234, "uatom")]);
let response = AllBalanceResponse::new(vec![Coin::new(1234u128, "uatom")]);
assert_eq!(
response,
AllBalanceResponse {
amount: vec![Coin::new(1234, "uatom")]
amount: vec![Coin::new(1234u128, "uatom")]
}
);
}
Expand Down

0 comments on commit 78bec97

Please sign in to comment.