Skip to content

Commit

Permalink
refactor: fix clippy warnings (part 2) (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgorenflo authored Mar 15, 2024
1 parent bf0b304 commit a077279
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 61 deletions.
6 changes: 3 additions & 3 deletions ampd/src/block_height_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ mod tests {
let monitor = BlockHeightMonitor::connect(mock_client)
.await
.unwrap()
.poll_interval(poll_interval.clone());
.poll_interval(poll_interval);
let exit_token = token.clone();

let latest_block_height = monitor.latest_block_height();
let handle = tokio::spawn(async move { monitor.run(exit_token).await });

let mut prev_height = latest_block_height.borrow().clone();
let mut prev_height = *latest_block_height.borrow();
for _ in 1..10 {
time::sleep(poll_interval * 2).await;
let next_height = latest_block_height.borrow().clone();
let next_height = *latest_block_height.borrow();
assert!(next_height > prev_height);
prev_height = next_height;
}
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/broadcaster/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod tests {
let hash = hasher.finalize();

let priv_key = ecdsa::SigningKey::from_bytes(&priv_key_bytes).unwrap();
let (signature, _) = priv_key.sign_prehash_recoverable(&hash.to_vec()).unwrap();
let (signature, _) = priv_key.sign_prehash_recoverable(&hash).unwrap();

Result::<_, Error>::Ok(signature.to_vec())
})
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/evm/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ mod tests {
let mut rpc_client = MockEthereumClient::new();
let mut block = Block::<Hash>::default();
let block_number: U64 = 10.into();
block.number = Some(block_number.clone());
block.number = Some(block_number);

rpc_client
.expect_finalized_block()
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod tests {
rpc_url = 'http://127.0.0.1/'
";

let chain_config: Chain = toml::from_str(&chain_config_toml).unwrap();
let chain_config: Chain = toml::from_str(chain_config_toml).unwrap();
assert_eq!(chain_config.finalization, Finalization::RPCFinalizedBlock);
}
}
20 changes: 9 additions & 11 deletions contracts/aggregate-verifier/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ pub fn make_mock_voting_verifier(app: &mut App) -> Addr {
);
let code_id = app.store_code(Box::new(code));

let contract_address = app
.instantiate_contract(
code_id,
Addr::unchecked("voting_verifier"),
&MockVotingVerifierInstantiateMsg {},
&[],
"Contract",
None,
)
.unwrap();
contract_address
app.instantiate_contract(
code_id,
Addr::unchecked("voting_verifier"),
&MockVotingVerifierInstantiateMsg {},
&[],
"Contract",
None,
)
.unwrap()
}
14 changes: 5 additions & 9 deletions contracts/aggregate-verifier/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use axelar_wasm_std::VerificationStatus;
use connection_router_api::{CrossChainId, Message, ID_SEPARATOR};
use cosmwasm_std::from_json;
use cosmwasm_std::Addr;
use cw_multi_test::{App, Executor};
use cw_multi_test::App;
use integration_tests::contract::Contract;

use crate::mock::{make_mock_voting_verifier, mark_messages_as_verified};
Expand Down Expand Up @@ -46,7 +46,7 @@ fn verify_messages_empty() {
&ExecuteMsg::VerifyMessages { messages: vec![] },
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(res.data.unwrap()).unwrap();
assert_eq!(ret, vec![]);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ fn verify_messages_verified() {
},
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(res.data.unwrap()).unwrap();
assert_eq!(
ret,
messages
Expand Down Expand Up @@ -135,17 +135,13 @@ fn verify_messages_mixed_status() {
},
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(res.data.unwrap()).unwrap();
assert_eq!(
ret,
messages
.iter()
.map(|msg| {
if verified
.iter()
.find(|verified_msg| *verified_msg == msg)
.is_some()
{
if verified.iter().any(|verified_msg| verified_msg == msg) {
(msg.cc_id.clone(), VerificationStatus::SucceededOnChain)
} else {
(msg.cc_id.clone(), VerificationStatus::None)
Expand Down
29 changes: 13 additions & 16 deletions contracts/multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ mod tests {

let res = query_worker_set(&worker_set_1.id(), deps.as_ref());
assert!(res.is_ok());
assert_eq!(worker_set_1, from_json(&res.unwrap()).unwrap());
assert_eq!(worker_set_1, from_json(res.unwrap()).unwrap());

let res = query_worker_set(&worker_set_2.id(), deps.as_ref());
assert!(res.is_ok());
assert_eq!(worker_set_2, from_json(&res.unwrap()).unwrap());
assert_eq!(worker_set_2, from_json(res.unwrap()).unwrap());

for (key_type, _) in [
(KeyType::Ecdsa, worker_set_1_id),
Expand Down Expand Up @@ -406,7 +406,7 @@ mod tests {
assert_eq!(res.data, Some(to_json_binary(&session.id).unwrap()));
assert_eq!(res.events.len(), 1);

let event = res.events.get(0).unwrap();
let event = res.events.first().unwrap();
assert_eq!(event.ty, "signing_started".to_string());
assert_eq!(
get_event_attribute(event, "session_id").unwrap(),
Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {
do_start_signing_session(deps.as_mut(), PROVER, worker_set_id, chain_name.clone())
.unwrap();

let signer = signers.get(0).unwrap().to_owned();
let signer = signers.first().unwrap().to_owned();

let expected_rewards_msg = WasmMsg::Execute {
contract_addr: REWARDS_CONTRACT.to_string(),
Expand All @@ -474,7 +474,7 @@ mod tests {
}
.into();

let res = do_sign(deps.as_mut(), mock_env(), Uint64::from(session_id), &signer);
let res = do_sign(deps.as_mut(), mock_env(), session_id, &signer);

assert!(res.is_ok());

Expand All @@ -498,7 +498,7 @@ mod tests {

assert!(res.messages.iter().any(|m| m.msg == expected_rewards_msg));

let event = res.events.get(0).unwrap();
let event = res.events.first().unwrap();
assert_eq!(event.ty, "signature_submitted".to_string());
assert_eq!(
get_event_attribute(event, "session_id").unwrap(),
Expand Down Expand Up @@ -526,7 +526,7 @@ mod tests {
do_start_signing_session(deps.as_mut(), PROVER, subkey, "mock-chain".parse().unwrap())
.unwrap();

let signer = signers.get(0).unwrap().to_owned();
let signer = signers.first().unwrap().to_owned();
do_sign(deps.as_mut(), mock_env(), session_id, &signer).unwrap();

// second signature
Expand Down Expand Up @@ -580,7 +580,7 @@ mod tests {
{
do_start_signing_session(deps.as_mut(), PROVER, subkey, chain_name.clone()).unwrap();

let signer = signers.get(0).unwrap().to_owned();
let signer = signers.first().unwrap().to_owned();
do_sign(deps.as_mut(), mock_env(), session_id, &signer).unwrap();

// second signature
Expand Down Expand Up @@ -610,10 +610,7 @@ mod tests {

assert_eq!(signatures.len(), 3);
assert!(res.messages.iter().any(|m| m.msg == expected_rewards_msg));
assert!(!res
.events
.iter()
.any(|e| e.ty == "signing_completed".to_string())); // event is not re-emitted
assert!(!res.events.iter().any(|e| e.ty == *"signing_completed")); // event is not re-emitted
}
}

Expand All @@ -628,7 +625,7 @@ mod tests {
do_start_signing_session(deps.as_mut(), PROVER, subkey, "mock-chain".parse().unwrap())
.unwrap();

let signer = signers.get(0).unwrap().to_owned();
let signer = signers.first().unwrap().to_owned();
do_sign(deps.as_mut(), mock_env(), session_id, &signer).unwrap();

// second signature
Expand Down Expand Up @@ -664,7 +661,7 @@ mod tests {
.unwrap();

let invalid_session_id = Uint64::zero();
let signer = ecdsa_test_data::signers().get(0).unwrap().to_owned();
let signer = ecdsa_test_data::signers().first().unwrap().to_owned();
let res = do_sign(deps.as_mut(), mock_env(), invalid_session_id, &signer);

assert_eq!(
Expand All @@ -691,7 +688,7 @@ mod tests {
deps.as_mut(),
mock_env(),
session_id,
signers.get(0).unwrap(),
signers.first().unwrap(),
)
.unwrap();

Expand Down Expand Up @@ -731,7 +728,7 @@ mod tests {
.find(|signer| signer.0.address == worker_set_signer.address)
.unwrap();

assert_eq!(signer.0.weight, Uint256::from(worker_set_signer.weight));
assert_eq!(signer.0.weight, worker_set_signer.weight);
assert_eq!(
signer.0.pub_key,
worker_set.signers.get(address).unwrap().pub_key
Expand Down
14 changes: 7 additions & 7 deletions contracts/multisig/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ mod ecdsa_tests {
.unwrap();
let message = MsgToSign::try_from(ecdsa_test_data::message()).unwrap();
let public_key = PublicKey::try_from((KeyType::Ecdsa, ecdsa_test_data::pub_key())).unwrap();
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert!(result.is_ok(), "{:?}", result)
}

Expand All @@ -409,7 +409,7 @@ mod ecdsa_tests {
let signature: Signature = (KeyType::Ecdsa, invalid_signature).try_into().unwrap();
let message = MsgToSign::try_from(ecdsa_test_data::message()).unwrap();
let public_key = PublicKey::try_from((KeyType::Ecdsa, ecdsa_test_data::pub_key())).unwrap();
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert_eq!(
result.unwrap_err(),
ContractError::SignatureVerificationFailed {
Expand All @@ -428,7 +428,7 @@ mod ecdsa_tests {
let signature: Signature = (KeyType::Ecdsa, invalid_signature).try_into().unwrap();
let message = MsgToSign::try_from(ecdsa_test_data::message()).unwrap();
let public_key = PublicKey::try_from((KeyType::Ecdsa, ecdsa_test_data::pub_key())).unwrap();
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert_eq!(
result.unwrap_err(),
ContractError::SignatureVerificationFailed {
Expand All @@ -449,7 +449,7 @@ mod ecdsa_tests {
.unwrap();
let message = MsgToSign::try_from(ecdsa_test_data::message()).unwrap();
let public_key = PublicKey::try_from((KeyType::Ecdsa, invalid_pub_key)).unwrap();
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert_eq!(
result.unwrap_err(),
ContractError::SignatureVerificationFailed {
Expand Down Expand Up @@ -535,7 +535,7 @@ mod ed25519_tests {
let message = MsgToSign::try_from(ed25519_test_data::message()).unwrap();
let public_key =
PublicKey::try_from((KeyType::Ed25519, ed25519_test_data::pub_key())).unwrap();
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert!(result.is_ok(), "{:?}", result)
}

Expand All @@ -550,7 +550,7 @@ mod ed25519_tests {
let message = MsgToSign::try_from(ed25519_test_data::message()).unwrap();
let public_key =
PublicKey::try_from((KeyType::Ed25519, ed25519_test_data::pub_key())).unwrap();
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert_eq!(
result.unwrap_err(),
ContractError::SignatureVerificationFailed {
Expand All @@ -569,7 +569,7 @@ mod ed25519_tests {
Signature::try_from((KeyType::Ed25519, ed25519_test_data::signature())).unwrap();
let message = MsgToSign::try_from(ed25519_test_data::message()).unwrap();
let public_key = PublicKey::Ed25519(invalid_pub_key);
let result = signature.verify(&message, &public_key);
let result = signature.verify(message, &public_key);
assert_eq!(
result.unwrap_err(),
ContractError::SignatureVerificationFailed {
Expand Down
2 changes: 1 addition & 1 deletion contracts/multisig/src/test/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub mod ed25519_test_data {
}
}

pub fn build_worker_set(key_type: KeyType, signers: &Vec<TestSigner>) -> WorkerSet {
pub fn build_worker_set(key_type: KeyType, signers: &[TestSigner]) -> WorkerSet {
let mut total_weight = Uint256::zero();
let participants = signers
.iter()
Expand Down
Loading

0 comments on commit a077279

Please sign in to comment.