Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Feb 2, 2023
1 parent f7fb1f5 commit 69d9538
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
30 changes: 14 additions & 16 deletions src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_std::{to_binary, Addr, Api, BankMsg, Binary, Coin, CosmosMsg, Uint1
use cw20::Cw20ExecuteMsg;
use cw_address_like::AddressLike;

use crate::{AssetInfo, AssetInfoBase, AssetInfoUnchecked, AssetError};
use crate::{AssetError, AssetInfo, AssetInfoBase, AssetInfoUnchecked};

/// Represents a fungible asset with a known amount
///
Expand Down Expand Up @@ -93,7 +93,7 @@ impl FromStr for AssetUnchecked {
if words.len() != 3 {
return Err(AssetError::InvalidAssetFormat {
received: s.into(),
})
});
}
AssetInfoUnchecked::from_str(&format!("{}:{}", words[0], words[1]))?
},
Expand All @@ -105,10 +105,8 @@ impl FromStr for AssetUnchecked {
};

let amount_str = words[words.len() - 1];
let amount = Uint128::from_str(amount_str).map_err(|_| {
AssetError::InvalidAssetAmount {
amount: amount_str.into(),
}
let amount = Uint128::from_str(amount_str).map_err(|_| AssetError::InvalidAssetAmount {
amount: amount_str.into(),
})?;

Ok(AssetUnchecked {
Expand Down Expand Up @@ -399,7 +397,7 @@ mod tests {
Asset {
info: AssetInfo::Native(String::from("uusd")),
amount: Uint128::new(123456u128)
}
},
);

let asset = Asset::cw20(Addr::unchecked("mock_token"), 123456u128);
Expand All @@ -408,7 +406,7 @@ mod tests {
Asset {
info: AssetInfo::Cw20(Addr::unchecked("mock_token")),
amount: Uint128::new(123456u128)
}
},
);

let asset = Asset::native("uusd", 123456u128);
Expand All @@ -417,7 +415,7 @@ mod tests {
Asset {
info: AssetInfo::Native(String::from("uusd")),
amount: Uint128::new(123456u128)
}
},
)
}

Expand Down Expand Up @@ -514,7 +512,7 @@ mod tests {
);

let s = "native:uusd:12345";
assert_eq!(AssetUnchecked::from_str(s).unwrap(), AssetUnchecked::native("uusd", 12345u128),);
assert_eq!(AssetUnchecked::from_str(s).unwrap(), AssetUnchecked::native("uusd", 12345u128));

let s = "cw20:mock_token:12345";
assert_eq!(
Expand All @@ -537,7 +535,7 @@ mod tests {
AssetUnchecked::native(
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
69420u128
)
),
);

let asset = AssetUnchecked::from_sdk_string(
Expand All @@ -549,7 +547,7 @@ mod tests {
AssetUnchecked::native(
"factory/osmo1z926ax906k0ycsuckele6x5hh66e2m4m6ry7dn",
88888u128
)
),
);

let err = AssetUnchecked::from_sdk_string("ngmi");
Expand Down Expand Up @@ -583,7 +581,7 @@ mod tests {
Err(AssetError::UnacceptedDenom {
denom: "uatom".into(),
whitelist: "uusd|uluna|uosmo".into(),
})
}),
);
}

Expand Down Expand Up @@ -638,7 +636,7 @@ mod tests {
})
.unwrap(),
funds: vec![]
})
}),
);

let msg = coin.transfer_msg("alice").unwrap();
Expand All @@ -647,7 +645,7 @@ mod tests {
CosmosMsg::Bank(BankMsg::Send {
to_address: String::from("alice"),
amount: vec![Coin::new(123456, "uusd")]
})
}),
);

let msg = token.transfer_from_msg("bob", "charlie").unwrap();
Expand All @@ -662,7 +660,7 @@ mod tests {
})
.unwrap(),
funds: vec![]
})
}),
);
let err = coin.transfer_from_msg("bob", "charlie");
assert_eq!(
Expand Down
8 changes: 4 additions & 4 deletions src/asset_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt, str::FromStr, any::type_name};
use std::{any::type_name, fmt, str::FromStr};

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
Expand Down Expand Up @@ -469,7 +469,8 @@ mod test {
let (key1, key2, key3) = mock_keys();
map.save(deps.as_mut().storage, (key1.clone(), key2.clone(), key3.clone()), &42069)
.unwrap();
map.save(deps.as_mut().storage, (key1.clone(), key1.clone(), key2.clone()), &11).unwrap();
map.save(deps.as_mut().storage, (key1.clone(), key1.clone(), key2.clone()), &11)
.unwrap();
map.save(deps.as_mut().storage, (key1.clone(), key1.clone(), key3.clone()), &69420)
.unwrap();

Expand All @@ -482,8 +483,7 @@ mod test {
assert_eq!(items[1], (key3.clone(), 69420));
assert_eq!(items[0], (key2.clone(), 11));

let val1 =
map.load(deps.as_ref().storage, (key1, key2, key3)).unwrap();
let val1 = map.load(deps.as_ref().storage, (key1, key2, key3)).unwrap();
assert_eq!(val1, 42069);
}
}
9 changes: 4 additions & 5 deletions src/asset_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ impl AssetListUnchecked {
api: &dyn Api,
optional_whitelist: Option<&[&str]>,
) -> Result<AssetList, AssetError> {
self
.0
self.0
.iter()
.map(|asset| asset.check(api, optional_whitelist))
.collect::<Result<Vec<_>, _>>()
Expand Down Expand Up @@ -610,7 +609,7 @@ mod tests {
AssetList::from(vec![
Asset::native("uusd", 34710u128),
Asset::new(mock_token(), 44444u128)
])
]),
);
}

Expand Down Expand Up @@ -698,8 +697,8 @@ mod tests {
})
.unwrap(),
funds: vec![]
})
]
}),
],
);
}
}
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{StdError, OverflowError};
use cosmwasm_std::{OverflowError, StdError};
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
Expand Down

0 comments on commit 69d9538

Please sign in to comment.