Skip to content

Commit

Permalink
Fix clippy lint
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Jun 27, 2023
1 parent d4ca2cc commit 338c2c1
Show file tree
Hide file tree
Showing 71 changed files with 340 additions and 375 deletions.
2 changes: 1 addition & 1 deletion contracts/crypto-verify/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ mod tests {
source: RecoverPubkeyError::UnknownErr { .. },
..
} => {}
err => panic!("Unexpected error: {:?}", err),
err => panic!("Unexpected error: {err:?}"),
}
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/crypto-verify/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ pub fn get_recovery_param_with_chain_id(v: u64, chain_id: u64) -> StdResult<u8>
match recovery {
0 | 1 => Ok(recovery as u8),
_ => Err(StdError::generic_err(format!(
"Calculated recovery parameter must be 0 or 1 but is {}.",
recovery
"Calculated recovery parameter must be 0 or 1 but is {recovery}."
))),
}
}
Expand Down
15 changes: 5 additions & 10 deletions contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
StdError::GenericErr { .. } => {}
err => {
return Err(StdError::generic_err(format!(
"Unexpected error in do_user_errors_in_api_calls: {:?}",
err
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
))
.into())
}
Expand All @@ -202,8 +201,7 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
StdError::GenericErr { .. } => {}
err => {
return Err(StdError::generic_err(format!(
"Unexpected error in do_user_errors_in_api_calls: {:?}",
err
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
))
.into())
}
Expand All @@ -216,8 +214,7 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
StdError::GenericErr { .. } => {}
err => {
return Err(StdError::generic_err(format!(
"Unexpected error in do_user_errors_in_api_calls: {:?}",
err
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
))
.into())
}
Expand All @@ -228,8 +225,7 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
StdError::GenericErr { .. } => {}
err => {
return Err(StdError::generic_err(format!(
"Unexpected error in do_user_errors_in_api_calls: {:?}",
err
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
))
.into())
}
Expand All @@ -240,8 +236,7 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
StdError::GenericErr { .. } => {}
err => {
return Err(StdError::generic_err(format!(
"Unexpected error in do_user_errors_in_api_calls: {:?}",
err
"Unexpected error in do_user_errors_in_api_calls: {err:?}"
))
.into())
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/hackatom/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ fn execute_allocate_large_memory() {
// which we only fix when using rust-optimizer, not integration tests.
assert_approx_eq!(gas_used, 4413600000, "0.2");
let used = deps.memory_pages();
assert_eq!(used, pages_before + 48, "Memory used: {} pages", used);
assert_eq!(used, pages_before + 48, "Memory used: {used} pages");
pages_before += 48;

// Grow by 1600 pages (100 MiB)
Expand All @@ -425,10 +425,10 @@ fn execute_allocate_large_memory() {
// Note: the exact gas usage depends on the Rust version used to compile Wasm,
// which we only fix when using rust-optimizer, not integration tests.
let expected = 4859700000; // +/- 20%
assert!(gas_used > expected * 80 / 100, "Gas used: {}", gas_used);
assert!(gas_used < expected * 120 / 100, "Gas used: {}", gas_used);
assert!(gas_used > expected * 80 / 100, "Gas used: {gas_used}");
assert!(gas_used < expected * 120 / 100, "Gas used: {gas_used}");
let used = deps.memory_pages();
assert_eq!(used, pages_before, "Memory used: {} pages", used);
assert_eq!(used, pages_before, "Memory used: {used} pages");
}

#[test]
Expand Down Expand Up @@ -458,7 +458,7 @@ fn execute_panic() {
);
assert!(msg.contains("contract.rs:"), "Must contain file and line");
}
err => panic!("Unexpected error: {:?}", err),
err => panic!("Unexpected error: {err:?}"),
}
}

Expand Down
15 changes: 6 additions & 9 deletions contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> St
}
if channel.version.as_str() != IBC_APP_VERSION {
return Err(StdError::generic_err(format!(
"Must set version to `{}`",
IBC_APP_VERSION
"Must set version to `{IBC_APP_VERSION}`"
)));
}

if let Some(counter_version) = msg.counterparty_version() {
if counter_version != IBC_APP_VERSION {
return Err(StdError::generic_err(format!(
"Counterparty version must be `{}`",
IBC_APP_VERSION
"Counterparty version must be `{IBC_APP_VERSION}`"
)));
}
}
Expand Down Expand Up @@ -190,8 +188,7 @@ fn acknowledge_balances(
if let Some(old_addr) = acct.remote_addr {
if old_addr != account {
return Err(StdError::generic_err(format!(
"remote account changed from {} to {}",
old_addr, account
"remote account changed from {old_addr} to {account}"
)));
}
}
Expand Down Expand Up @@ -265,7 +262,7 @@ mod tests {
channel_id: packet_channel,
..
}) => assert_eq!(packet_channel.as_str(), channel_id),
o => panic!("Unexpected message: {:?}", o),
o => panic!("Unexpected message: {o:?}"),
};
}

Expand Down Expand Up @@ -362,7 +359,7 @@ mod tests {
msg.original_packet.data = data;
msg
}
o => panic!("Unexpected message: {:?}", o),
o => panic!("Unexpected message: {o:?}"),
};
let res = ibc_packet_ack(deps.as_mut(), mock_env(), msg).unwrap();
// no actions expected, but let's check the events to see it was dispatched properly
Expand Down Expand Up @@ -420,7 +417,7 @@ mod tests {
assert!(timeout.block().is_none());
assert!(timeout.timestamp().is_some());
}
o => panic!("unexpected message: {:?}", o),
o => panic!("unexpected message: {o:?}"),
}
}
}
2 changes: 1 addition & 1 deletion contracts/ibc-reflect-send/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn may_load_account(storage: &dyn Storage, id: &str) -> StdResult<Option<Acc
}

pub fn load_account(storage: &dyn Storage, id: &str) -> StdResult<AccountData> {
may_load_account(storage, id)?.ok_or_else(|| StdError::not_found(format!("account {}", id)))
may_load_account(storage, id)?.ok_or_else(|| StdError::not_found(format!("account {id}")))
}

pub fn save_account(storage: &mut dyn Storage, id: &str, account: &AccountData) -> StdResult<()> {
Expand Down
6 changes: 3 additions & 3 deletions contracts/ibc-reflect-send/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn connect(deps: &mut Instance<MockApi, MockStorage, MockQuerier>, channel_id: &
channel_id: packet_channel,
..
}) => assert_eq!(packet_channel.as_str(), channel_id),
o => panic!("Unexpected message: {:?}", o),
o => panic!("Unexpected message: {o:?}"),
};
}

Expand Down Expand Up @@ -183,7 +183,7 @@ fn dispatch_message_send_and_ack() {
msg.original_packet.data = data;
msg
}
o => panic!("Unexpected message: {:?}", o),
o => panic!("Unexpected message: {o:?}"),
};
let res: IbcBasicResponse = ibc_packet_ack(&mut deps, mock_env(), msg).unwrap();
// no actions expected, but let's check the events to see it was dispatched properly
Expand Down Expand Up @@ -241,6 +241,6 @@ fn send_remote_funds() {
assert!(timeout.block().is_none());
assert!(timeout.timestamp().is_some());
}
o => panic!("unexpected message: {:?}", o),
o => panic!("unexpected message: {o:?}"),
}
}
7 changes: 3 additions & 4 deletions contracts/ibc-reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ pub fn ibc_channel_open(
if let Some(counter_version) = msg.counterparty_version() {
if counter_version != IBC_APP_VERSION {
return Err(StdError::generic_err(format!(
"Counterparty version must be `{}`",
IBC_APP_VERSION
"Counterparty version must be `{IBC_APP_VERSION}`"
)));
}
}
Expand All @@ -164,7 +163,7 @@ pub fn ibc_channel_connect(
code_id: cfg.reflect_code_id,
msg: b"{}".into(),
funds: vec![],
label: format!("ibc-reflect-{}", chan_id),
label: format!("ibc-reflect-{chan_id}"),
};
let msg = SubMsg::reply_on_success(msg, INIT_CALLBACK_ID);

Expand Down Expand Up @@ -255,7 +254,7 @@ pub fn ibc_packet_receive(
.or_else(|e| {
// we try to capture all app-level errors and convert them into
// acknowledgement packets that contain an error code.
let acknowledgement = encode_ibc_error(format!("invalid packet: {}", e));
let acknowledgement = encode_ibc_error(format!("invalid packet: {e}"));
Ok(IbcReceiveResponse::new()
.set_ack(acknowledgement)
.add_event(Event::new("ibc").add_attribute("packet", "receive")))
Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn may_load_account(storage: &dyn Storage, id: &str) -> StdResult<Option<Add
}

pub fn load_account(storage: &dyn Storage, id: &str) -> StdResult<Addr> {
may_load_account(storage, id)?.ok_or_else(|| StdError::not_found(format!("account {}", id)))
may_load_account(storage, id)?.ok_or_else(|| StdError::not_found(format!("account {id}")))
}

pub fn save_account(storage: &mut dyn Storage, id: &str, account: &Addr) -> StdResult<()> {
Expand Down
12 changes: 5 additions & 7 deletions contracts/reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,14 @@ fn query_chain(
request: &QueryRequest<SpecialQuery>,
) -> StdResult<ChainResponse> {
let raw = to_vec(request).map_err(|serialize_err| {
StdError::generic_err(format!("Serializing QueryRequest: {}", serialize_err))
StdError::generic_err(format!("Serializing QueryRequest: {serialize_err}"))
})?;
match deps.querier.raw_query(&raw) {
SystemResult::Err(system_err) => Err(StdError::generic_err(format!(
"Querier system error: {}",
system_err
"Querier system error: {system_err}"
))),
SystemResult::Ok(ContractResult::Err(contract_err)) => Err(StdError::generic_err(format!(
"Querier contract error: {}",
contract_err
"Querier contract error: {contract_err}"
))),
SystemResult::Ok(ContractResult::Ok(value)) => Ok(ChainResponse { data: value }),
}
Expand Down Expand Up @@ -241,7 +239,7 @@ mod tests {
let res = execute(deps.as_mut(), mock_env(), info, msg);
match res.unwrap_err() {
ReflectError::NotCurrentOwner { .. } => {}
err => panic!("Unexpected error: {:?}", err),
err => panic!("Unexpected error: {err:?}"),
}
}

Expand Down Expand Up @@ -355,7 +353,7 @@ mod tests {
ReflectError::Std(StdError::GenericErr { msg, .. }) => {
assert!(msg.contains("human address too short"))
}
e => panic!("Unexpected error: {:?}", e),
e => panic!("Unexpected error: {e:?}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/reflect/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct State {
pub fn load_reply(storage: &dyn Storage, id: u64) -> StdResult<Reply> {
storage
.get(&namespace_with_key(&[RESULT_PREFIX], &id.to_be_bytes()))
.ok_or_else(|| StdError::not_found(format!("reply {}", id)))
.ok_or_else(|| StdError::not_found(format!("reply {id}")))
.and_then(|v| from_slice(&v))
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ mod tests {
assert_eq!(validator.as_str(), DEFAULT_VALIDATOR);
assert_eq!(amount, &coin(1000, "ustake"));
}
_ => panic!("Unexpected message: {:?}", delegate),
_ => panic!("Unexpected message: {delegate:?}"),
}

// bob got 1000 DRV for 1000 stake at a 1.0 ratio
Expand Down Expand Up @@ -666,7 +666,7 @@ mod tests {
StakingError::Std {
original: StdError::GenericErr { msg, .. },
} => assert_eq!(msg, "No ustake tokens sent"),
err => panic!("Unexpected error: {:?}", err),
err => panic!("Unexpected error: {err:?}"),
};
}

Expand Down Expand Up @@ -715,7 +715,7 @@ mod tests {
StakingError::Std {
original: StdError::Overflow { .. },
} => {}
err => panic!("Unexpected error: {:?}", err),
err => panic!("Unexpected error: {err:?}"),
}

// bob unbonds 600 tokens at 10% tax...
Expand All @@ -736,7 +736,7 @@ mod tests {
assert_eq!(validator.as_str(), DEFAULT_VALIDATOR);
assert_eq!(amount, &coin(bobs_claim.u128(), "ustake"));
}
_ => panic!("Unexpected message: {:?}", delegate),
_ => panic!("Unexpected message: {delegate:?}"),
}

// update the querier with new bond, lower balance
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn save_map(

pub fn load_map(storage: &dyn Storage, prefix: &[u8], key: &CanonicalAddr) -> StdResult<Uint128> {
may_load_map(storage, prefix, key)?
.ok_or_else(|| StdError::not_found(format!("map value for {}", key)))
.ok_or_else(|| StdError::not_found(format!("map value for {key}")))
}

/// Investment info is fixed at initialization, and is used to control the function of the contract
Expand Down
4 changes: 2 additions & 2 deletions packages/check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn main() {
.map(|s| s.as_str())
.unwrap_or(DEFAULT_AVAILABLE_CAPABILITIES);
let available_capabilities = capabilities_from_csv(available_capabilities_csv);
println!("Available capabilities: {:?}", available_capabilities);
println!("Available capabilities: {available_capabilities:?}");
println!();

// File
Expand All @@ -58,7 +58,7 @@ pub fn main() {
Ok(_) => println!("{}: {}", p, "pass".green()),
Err(e) => {
println!("{}: {}", p, "failure".red());
println!("{}", e);
println!("{e}");
}
};
result
Expand Down
3 changes: 1 addition & 2 deletions packages/crypto/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ mod tests {
// ed25519_verify() works
assert!(
ed25519_verify(&message, &signature, &public_key).unwrap(),
"verify() failed (test case {})",
i
"verify() failed (test case {i})"
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/crypto/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ mod tests {
{
let expected_x = "F3F8BB913AA68589A2C8C607A877AB05252ADBD963E1BE846DDEB8456942AEDC";
let expected_y = "A2ED51F08CA3EF3DAC0A7504613D54CD539FC1B3CBC92453CD704B6A2D012B2C";
let expected = hex::decode(format!("04{}{}", expected_x, expected_y)).unwrap();
let expected = hex::decode(format!("04{expected_x}{expected_y}")).unwrap();
let r_s = hex!("E30F2E6A0F705F4FB5F8501BA79C7C0D3FAC847F1AD70B873E9797B17B89B39081F1A4457589F30D76AB9F89E748A68C8A94C30FE0BAC8FB5C0B54EA70BF6D2F");
let recovery_param: u8 = 0;
let message_hash =
Expand Down Expand Up @@ -404,24 +404,24 @@ mod tests {
let recovery_param: u8 = 2;
match secp256k1_recover_pubkey(&message_hash, &r_s, recovery_param).unwrap_err() {
CryptoError::InvalidRecoveryParam { .. } => {}
err => panic!("Unexpected error: {}", err),
err => panic!("Unexpected error: {err}"),
}
let recovery_param: u8 = 3;
match secp256k1_recover_pubkey(&message_hash, &r_s, recovery_param).unwrap_err() {
CryptoError::InvalidRecoveryParam { .. } => {}
err => panic!("Unexpected error: {}", err),
err => panic!("Unexpected error: {err}"),
}

// Other values are garbage
let recovery_param: u8 = 4;
match secp256k1_recover_pubkey(&message_hash, &r_s, recovery_param).unwrap_err() {
CryptoError::InvalidRecoveryParam { .. } => {}
err => panic!("Unexpected error: {}", err),
err => panic!("Unexpected error: {err}"),
}
let recovery_param: u8 = 255;
match secp256k1_recover_pubkey(&message_hash, &r_s, recovery_param).unwrap_err() {
CryptoError::InvalidRecoveryParam { .. } => {}
err => panic!("Unexpected error: {}", err),
err => panic!("Unexpected error: {err}"),
}
}
}
Loading

0 comments on commit 338c2c1

Please sign in to comment.