From 8d5091e47fc5c00d481ff3005ee40decacf1ab73 Mon Sep 17 00:00:00 2001 From: Alexey Chernyshov Date: Tue, 30 Jan 2024 22:20:47 +0300 Subject: [PATCH] chore(gh): fix clippy findings --- pallets/beefy-light-client/src/fixtures.rs | 13 +++------ pallets/beefy-light-client/src/tests.rs | 7 ++--- pallets/data-signer/src/tests.rs | 29 +++++++++--------- pallets/parachain-app/src/tests.rs | 34 +++++----------------- pallets/types/src/difficulty.rs | 6 ++-- 5 files changed, 31 insertions(+), 58 deletions(-) diff --git a/pallets/beefy-light-client/src/fixtures.rs b/pallets/beefy-light-client/src/fixtures.rs index ce5fc4ad..3cec99f1 100644 --- a/pallets/beefy-light-client/src/fixtures.rs +++ b/pallets/beefy-light-client/src/fixtures.rs @@ -118,7 +118,6 @@ impl ValidatorSet { pub fn proofs(&self) -> Vec> { (0..self.addresses.len()) - .into_iter() .map(|i| self.validator_pubkey_proof(i)) .collect() } @@ -132,10 +131,7 @@ impl ValidatorSet { } pub fn root(&self) -> H256 { - let root = beefy_merkle_tree::merkle_root::( - self.addresses.clone(), - ); - root + beefy_merkle_tree::merkle_root::(self.addresses.clone()) } fn authority_set(&self) -> sp_beefy::mmr::BeefyAuthoritySet { @@ -235,11 +231,10 @@ enum MMRNode { impl MMRNode { fn hash(&self) -> H256 { - let hash = match self { + match self { MMRNode::Leaf(leaf) => sp_runtime::traits::Keccak256::hash_of(leaf), MMRNode::Hash(hash) => *hash, - }; - hash + } } } @@ -315,7 +310,7 @@ pub fn generate_fixture(validators: usize, tree_size: u32) -> AnyResult sp_beefy::known_payloads::MMR_ROOT_ID, mmr_root.encode(), ), - block_number: tree_size as u32, + block_number: tree_size, validator_set_id: validator_set.id, }; let signed_commitment = validator_set.sign_commitment(&mut rng, commitment, None); diff --git a/pallets/beefy-light-client/src/tests.rs b/pallets/beefy-light-client/src/tests.rs index 1fb5780c..7c10509c 100644 --- a/pallets/beefy-light-client/src/tests.rs +++ b/pallets/beefy-light-client/src/tests.rs @@ -78,14 +78,13 @@ fn validator_proof( public_key_merkle_proofs.push(fixture.validator_set_proofs[i].clone()); } } - let validator_proof = bridge_common::beefy_types::ValidatorProof { + ValidatorProof { signatures: proof_signatures, positions, public_keys, - public_key_merkle_proofs: public_key_merkle_proofs, + public_key_merkle_proofs, validator_claims_bitfield: initial_bitfield, - }; - validator_proof + } } #[test_case(3, 5; "3 validators, 5 leaves")] diff --git a/pallets/data-signer/src/tests.rs b/pallets/data-signer/src/tests.rs index d2368d44..fa94dee7 100644 --- a/pallets/data-signer/src/tests.rs +++ b/pallets/data-signer/src/tests.rs @@ -504,7 +504,7 @@ fn it_works_finish_add_peer() { assert_ok!(DataSigner::register_network( RuntimeOrigin::root(), network_id, - peers.clone(), + peers, )); let new_peer = test_signer().public(); @@ -533,7 +533,7 @@ fn it_fails_add_peer_no_pending_update() { assert_ok!(DataSigner::register_network( RuntimeOrigin::root(), network_id, - peers.clone(), + peers, )); let new_peer = test_signer().public(); @@ -569,7 +569,7 @@ fn it_works_validate_unsigned() { assert_eq!( ::validate_unsigned( TransactionSource::External, - &call.into(), + &call, ), TransactionValidity::Ok( ValidTransaction::with_tag_prefix("DataSignerApprove") @@ -594,7 +594,7 @@ fn it_fails_validate_unsigned_no_network() { assert_ok!(DataSigner::register_network( RuntimeOrigin::root(), network_id, - peers.clone(), + peers, )); let different_network_id = bridge_types::GenericNetworkId::Sub(SubNetworkId::Kusama); @@ -611,7 +611,7 @@ fn it_fails_validate_unsigned_no_network() { assert_eq!( ::validate_unsigned( TransactionSource::External, - &call.into(), + &call, ), InvalidTransaction::BadSigner.into() ); @@ -628,7 +628,7 @@ fn it_fails_validate_unsigned_bad_proof() { assert_ok!(DataSigner::register_network( RuntimeOrigin::root(), network_id, - peers.clone(), + peers, )); let data = [1u8; 32]; @@ -643,7 +643,7 @@ fn it_fails_validate_unsigned_bad_proof() { assert_eq!( ::validate_unsigned( TransactionSource::External, - &call.into(), + &call, ), InvalidTransaction::BadProof.into() ); @@ -660,7 +660,7 @@ fn it_fails_validate_unsigned_bad_signer() { assert_ok!(DataSigner::register_network( RuntimeOrigin::root(), network_id, - peers.clone(), + peers, )); let data = [1u8; 32]; @@ -675,7 +675,7 @@ fn it_fails_validate_unsigned_bad_signer() { assert_eq!( ::validate_unsigned( TransactionSource::External, - &call.into(), + &call, ), InvalidTransaction::BadSigner.into() ); @@ -692,7 +692,7 @@ fn it_fails_validate_unsigned_transaction_stale() { assert_ok!(DataSigner::register_network( RuntimeOrigin::root(), network_id, - peers.clone(), + peers, )); let data = [1u8; 32]; @@ -716,7 +716,7 @@ fn it_fails_validate_unsigned_transaction_stale() { assert_eq!( ::validate_unsigned( TransactionSource::InBlock, - &call.into(), + &call, ), InvalidTransaction::Stale.into() ); @@ -736,15 +736,12 @@ fn it_fails_validate_unsigned_invalid_call() { peers.clone(), )); - let call = Call::register_network { - network_id, - peers: peers.clone(), - }; + let call = Call::register_network { network_id, peers }; assert_eq!( ::validate_unsigned( TransactionSource::External, - &call.into(), + &call, ), InvalidTransaction::Call.into() ); diff --git a/pallets/parachain-app/src/tests.rs b/pallets/parachain-app/src/tests.rs index 18817ba9..9deec63c 100644 --- a/pallets/parachain-app/src/tests.rs +++ b/pallets/parachain-app/src/tests.rs @@ -143,7 +143,7 @@ fn it_fails_mint_wrong_amount() { let amount = 0; assert_noop!( - ParachainApp::mint(origin_kusama, asset_id, sender, recipient.clone(), amount), + ParachainApp::mint(origin_kusama, asset_id, sender, recipient, amount), Error::::WrongAmount ); }); @@ -264,7 +264,7 @@ fn it_fails_burn_invalid_destination_params() { // XCM destination > X2 not supported assert_noop!( ParachainApp::burn( - origin.clone().into(), + origin.into(), network_id, asset_id, VersionedMultiLocation::V3(MultiLocation::new( @@ -320,7 +320,7 @@ fn it_fails_burn_relaychain_asset_not_registered() { ) .expect("XOR registration failed"); ParachainApp::finalize_asset_registration( - origin_kusama.clone(), + origin_kusama, AssetId::XOR, AssetKind::Thischain, ) @@ -382,7 +382,7 @@ fn it_fails_not_relay_transferable_asset() { assert_noop!( ParachainApp::burn( - origin.clone().into(), + origin.into(), network_id, asset_id, VersionedMultiLocation::V3(MultiLocation::new( @@ -409,7 +409,7 @@ fn it_fails_burn_invalid_destination_parachain() { assert_noop!( ParachainApp::burn( - origin.clone().into(), + origin.into(), network_id, asset_id, VersionedMultiLocation::V3(MultiLocation::new( @@ -448,13 +448,7 @@ fn it_fails_burn_token_not_registered() { let amount = 1_000_000; assert_noop!( - ParachainApp::burn( - origin.clone().into(), - network_id, - AssetId::ETH, - recipient, - amount - ), + ParachainApp::burn(origin.into(), network_id, AssetId::ETH, recipient, amount), Error::::TokenIsNotRegistered ); }); @@ -483,13 +477,7 @@ fn it_fails_burn_unknown_presicion() { crate::AssetKinds::::insert(SubNetworkId::Kusama, asset_id, AssetKind::Thischain); assert_noop!( - ParachainApp::burn( - origin.clone().into(), - network_id, - asset_id, - recipient, - amount - ), + ParachainApp::burn(origin.into(), network_id, asset_id, recipient, amount), Error::::UnknownPrecision ); }); @@ -563,13 +551,7 @@ fn it_fails_burn_outbound_channel_submit() { amount )); assert_noop!( - ParachainApp::burn( - origin.clone().into(), - network_id, - AssetId::XOR, - recipient, - amount - ), + ParachainApp::burn(origin.into(), network_id, AssetId::XOR, recipient, amount), substrate_bridge_channel::outbound::Error::::QueueSizeLimitReached ); }); diff --git a/pallets/types/src/difficulty.rs b/pallets/types/src/difficulty.rs index bd25ff0c..16dbe8a6 100644 --- a/pallets/types/src/difficulty.rs +++ b/pallets/types/src/difficulty.rs @@ -271,7 +271,7 @@ mod tests { if s.starts_with("0x") { u128::from_str_radix(s.trim_start_matches("0x"), 16) } else { - u128::from_str_radix(&s, 10) + str::parse(&s) } }; match maybe_uint { @@ -316,7 +316,7 @@ mod tests { let path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests", "fixtures", fixture] .iter() .collect(); - serde_json::from_reader(File::open(&path).unwrap()).unwrap() + serde_json::from_reader(File::open(path).unwrap()).unwrap() } } @@ -391,7 +391,7 @@ mod tests { let path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests", "fixtures", fixture] .iter() .collect(); - serde_json::from_reader(File::open(&path).unwrap()).unwrap() + serde_json::from_reader(File::open(path).unwrap()).unwrap() } }