Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Feb 2, 2023
1 parent 10e83e6 commit f7fb1f5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
24 changes: 12 additions & 12 deletions src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ mod tests {
let uusd = Asset::native("uusd", 69u128);
let astro = Asset::cw20(Addr::unchecked("astro_token"), 69u128);

assert_eq!(uluna1 == uluna2, false);
assert_eq!(uluna1 == uusd, false);
assert_eq!(astro == astro.clone(), true);
assert!(uluna1 != uluna2);
assert!(uluna1 != uusd);
assert!(astro == astro.clone());
}

#[test]
Expand All @@ -469,14 +469,14 @@ mod tests {
};
let astro = Asset::cw20(Addr::unchecked("astro_token"), 69u128);

assert_eq!(uluna == uusd_coin, false);
assert_eq!(uusd_coin == uluna, false);
assert_eq!(uusd_1 == uusd_coin, true);
assert_eq!(uusd_coin == uusd_1, true);
assert_eq!(uusd_2 == uusd_coin, false);
assert_eq!(uusd_coin == uusd_2, false);
assert_eq!(astro == uusd_coin, false);
assert_eq!(uusd_coin == astro, false);
assert!(uluna != uusd_coin);
assert!(uusd_coin != uluna);
assert!(uusd_1 == uusd_coin);
assert!(uusd_coin == uusd_1);
assert!(uusd_2 != uusd_coin);
assert!(uusd_coin != uusd_2);
assert!(astro != uusd_coin);
assert!(uusd_coin != astro);
}

#[test]
Expand Down Expand Up @@ -553,7 +553,7 @@ mod tests {
);

let err = AssetUnchecked::from_sdk_string("ngmi");
assert_eq!(err.is_err(), true);
assert!(err.is_err());
}

#[test]
Expand Down
24 changes: 12 additions & 12 deletions src/asset_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl FromStr for AssetInfoUnchecked {
if words.len() != 2 {
return Err(AssetError::InvalidAssetInfoFormat {
received: s.into(),
should_be: format!("native:{{denom}}"),
should_be: "native:{denom}".into(),
});
}
Ok(AssetInfoUnchecked::Native(String::from(words[1])))
Expand All @@ -80,7 +80,7 @@ impl FromStr for AssetInfoUnchecked {
if words.len() != 2 {
return Err(AssetError::InvalidAssetInfoFormat {
received: s.into(),
should_be: format!("cw20:{{contract_addr}}"),
should_be: "cw20:{contract_addr}".into(),
});
}
Ok(AssetInfoUnchecked::Cw20(String::from(words[1])))
Expand Down Expand Up @@ -157,8 +157,8 @@ impl AssetInfoUnchecked {
impl fmt::Display for AssetInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AssetInfo::Cw20(contract_addr) => write!(f, "cw20:{}", contract_addr),
AssetInfo::Native(denom) => write!(f, "native:{}", denom),
AssetInfo::Cw20(contract_addr) => write!(f, "cw20:{contract_addr}"),
AssetInfo::Native(denom) => write!(f, "native:{denom}"),
}
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ impl AssetInfo {
if words.len() != 2 {
return Err(AssetError::InvalidAssetInfoFormat {
received: s.into(),
should_be: format!("native:{{denom}}"),
should_be: "native:{denom}".into(),
});
}
Ok(AssetInfo::Native(String::from(words[1])))
Expand All @@ -220,7 +220,7 @@ impl AssetInfo {
if words.len() != 2 {
return Err(AssetError::InvalidAssetInfoFormat {
received: s.into(),
should_be: format!("cw20:{{contract_addr}}"),
should_be: "cw20:{contract_addr}".into(),
});
}
Ok(AssetInfo::Cw20(Addr::unchecked(words[1])))
Expand Down Expand Up @@ -305,11 +305,11 @@ mod test {
let astro = AssetInfo::cw20(Addr::unchecked("astro_token"));
let mars = AssetInfo::cw20(Addr::unchecked("mars_token"));

assert_eq!(uluna == uusd, false);
assert_eq!(uluna == astro, false);
assert_eq!(astro == mars, false);
assert_eq!(uluna == uluna.clone(), true);
assert_eq!(astro == astro.clone(), true);
assert!(uluna != uusd);
assert!(uluna != astro);
assert!(astro != mars);
assert!(uluna == uluna.clone());
assert!(astro == astro.clone());
}

#[test]
Expand Down Expand Up @@ -483,7 +483,7 @@ mod test {
assert_eq!(items[0], (key2.clone(), 11));

let val1 =
map.load(deps.as_ref().storage, (key1.clone(), key2.clone(), key3.clone())).unwrap();
map.load(deps.as_ref().storage, (key1, key2, key3)).unwrap();
assert_eq!(val1, 42069);
}
}
14 changes: 9 additions & 5 deletions src/asset_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl FromStr for AssetListUnchecked {

s
.split(',')
.map(|s| AssetUnchecked::from_str(s))
.map(AssetUnchecked::from_str)
.collect::<Result<_, _>>()
.map(Self)
}
Expand Down Expand Up @@ -85,10 +85,14 @@ impl fmt::Display for AssetList {
let s = if self.is_empty() {
"[]".to_string()
} else {
self.0.iter().map(|asset| asset.to_string()).collect::<Vec<String>>().join(",")
self.0
.iter()
.map(|asset| asset.to_string())
.collect::<Vec<_>>()
.join(",")
};

write!(f, "{}", s)
write!(f, "{s}")
}
}

Expand Down Expand Up @@ -558,7 +562,7 @@ mod tests {

let checked = mock_list();
let unchecked: AssetListUnchecked = checked.clone().into();
assert_eq!(unchecked.check(&api, None).unwrap(), checked.clone());
assert_eq!(unchecked.check(&api, None).unwrap(), checked);
assert_eq!(unchecked.check(&api, Some(&["uusd", "uluna"])).unwrap(), checked);
assert_eq!(
unchecked.check(&api, Some(&["uatom", "uosmo", "uscrt"])),
Expand Down Expand Up @@ -628,7 +632,7 @@ mod tests {
let mut list = mock_list();
list.add_many(&mock_list()).unwrap();

let expected = mock_list().apply(|a| a.amount = a.amount * Uint128::new(2)).clone();
let expected = mock_list().apply(|a| a.amount *= Uint128::new(2)).clone();
assert_eq!(list, expected);
}

Expand Down
4 changes: 2 additions & 2 deletions src/testing/custom_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Querier for CustomMockQuerier {
Ok(v) => v,
Err(e) => {
return Err(SystemError::InvalidRequest {
error: format!("[mock]: failed to parse query request {}", e),
error: format!("[mock]: failed to parse query request {e}"),
request: bin_request.into(),
})
.into()
Expand All @@ -50,7 +50,7 @@ impl CustomMockQuerier {
return self.cw20_querier.handle_query(&contract_addr, cw20_query);
}

panic!("[mock]: unsupported wasm query {:?}", msg);
panic!("[mock]: unsupported wasm query {msg:?}");
},

_ => self.base.handle_query(request),
Expand Down
7 changes: 3 additions & 4 deletions src/testing/cw20_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ impl Cw20Querier {
None => {
return Err(SystemError::InvalidRequest {
error: format!(
"[mock]: cw20 balances not set for token {:?}",
contract_addr
"[mock]: cw20 balances not set for token {contract_addr:?}",
),
request: Default::default(),
})
Expand All @@ -32,7 +31,7 @@ impl Cw20Querier {
Some(balance) => balance,
None => {
return Err(SystemError::InvalidRequest {
error: format!("[mock]: cw20 balance not set for user {:?}", address),
error: format!("[mock]: cw20 balance not set for user {address:?}"),
request: Default::default(),
})
.into()
Expand All @@ -47,7 +46,7 @@ impl Cw20Querier {
},

query => Err(SystemError::InvalidRequest {
error: format!("[mock]: unsupported cw20 query {:?}", query),
error: format!("[mock]: unsupported cw20 query {query:?}"),
request: Default::default(),
})
.into(),
Expand Down

0 comments on commit f7fb1f5

Please sign in to comment.