From d33fdeca6dd3ee421129b934a6935d66e6ef4336 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov <39522748+dmitrylavrenov@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:40:39 +0300 Subject: [PATCH] Fix clippy for `runtime-benchmarks` and `try-runtime` features (#1264) Fix clippy --- crates/humanode-runtime/src/benchmarking.rs | 6 +++--- .../src/lib.rs | 2 +- .../src/upgrade_init.rs | 2 +- crates/pallet-bioauth/src/benchmarking.rs | 9 +++++++-- crates/pallet-bioauth/src/mock/benchmarking.rs | 9 ++------- crates/pallet-currency-swap/src/benchmarking.rs | 5 ++++- crates/pallet-evm-accounts-mapping/src/benchmarking.rs | 3 +++ crates/pallet-token-claims/src/benchmarking.rs | 3 +++ crates/pallet-vesting/src/benchmarking.rs | 3 +++ 9 files changed, 27 insertions(+), 15 deletions(-) diff --git a/crates/humanode-runtime/src/benchmarking.rs b/crates/humanode-runtime/src/benchmarking.rs index d1dc5627b..cda08a064 100644 --- a/crates/humanode-runtime/src/benchmarking.rs +++ b/crates/humanode-runtime/src/benchmarking.rs @@ -1,7 +1,7 @@ //! The benchmarking utilities. -// Allow simple integer arithmetic in tests. -#![allow(clippy::integer_arithmetic)] +// Allow integer arithmetic in tests. +#![allow(clippy::arithmetic_side_effects)] use eip712_common::keccak_256; use frame_support::{ @@ -44,7 +44,7 @@ fn ethereum_address_from_secret(secret: &libsecp256k1::SecretKey) -> EthereumAdd } fn eth_ecdsa_sign(secret: &libsecp256k1::SecretKey, msg_hash: &[u8; 32]) -> EcdsaSignature { - let (sig, recovery_id) = libsecp256k1::sign(&libsecp256k1::Message::parse(&msg_hash), secret); + let (sig, recovery_id) = libsecp256k1::sign(&libsecp256k1::Message::parse(msg_hash), secret); let mut ecdsa_signature = [0u8; 65]; ecdsa_signature[0..64].copy_from_slice(&sig.serialize()[..]); ecdsa_signature[64] = recovery_id.serialize(); diff --git a/crates/pallet-balanced-currency-swap-bridges-initializer/src/lib.rs b/crates/pallet-balanced-currency-swap-bridges-initializer/src/lib.rs index 7c57e3100..31e17fcdd 100644 --- a/crates/pallet-balanced-currency-swap-bridges-initializer/src/lib.rs +++ b/crates/pallet-balanced-currency-swap-bridges-initializer/src/lib.rs @@ -155,7 +155,7 @@ pub mod pallet { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { - upgrade_init::pre_upgrade::() + upgrade_init::pre_upgrade() } #[cfg(feature = "try-runtime")] diff --git a/crates/pallet-balanced-currency-swap-bridges-initializer/src/upgrade_init.rs b/crates/pallet-balanced-currency-swap-bridges-initializer/src/upgrade_init.rs index 1ccc6d5d7..0b036c2e4 100644 --- a/crates/pallet-balanced-currency-swap-bridges-initializer/src/upgrade_init.rs +++ b/crates/pallet-balanced-currency-swap-bridges-initializer/src/upgrade_init.rs @@ -38,7 +38,7 @@ pub fn on_runtime_upgrade() -> Weight { /// /// Panics if anything goes wrong. #[cfg(feature = "try-runtime")] -pub fn pre_upgrade() -> Result, &'static str> { +pub fn pre_upgrade() -> Result, &'static str> { // Do nothing. Ok(Vec::new()) } diff --git a/crates/pallet-bioauth/src/benchmarking.rs b/crates/pallet-bioauth/src/benchmarking.rs index 03dcc9879..8db1812e2 100644 --- a/crates/pallet-bioauth/src/benchmarking.rs +++ b/crates/pallet-bioauth/src/benchmarking.rs @@ -1,5 +1,8 @@ //! Benchmark for pallet-bioauth extrinsics. +// Allow integer and float arithmetic in tests. +#![allow(clippy::arithmetic_side_effects, clippy::float_arithmetic)] + use frame_benchmarking::benchmarks; use frame_support::traits::{Get, Hooks}; use frame_system::RawOrigin; @@ -38,6 +41,7 @@ fn make_pubkey(prefix: &str, idx: u32) -> Vec { pubkey } +/// A helper function to make nonce. fn make_nonce(prefix: &str, idx: u32) -> Vec { let mut nonce = Vec::from(prefix); let idx_in_bytes = idx.to_le_bytes(); @@ -67,9 +71,10 @@ fn make_authentications, Moment: Copy>( expires_at: Moment, ) -> Vec> { (0..count) - .into_iter() .map(|i| { - let public_key: [u8; 32] = make_pubkey(prefix, i as u32).try_into().unwrap(); + let public_key: [u8; 32] = make_pubkey(prefix, i.try_into().unwrap()) + .try_into() + .unwrap(); Authentication { public_key: public_key.into(), expires_at, diff --git a/crates/pallet-bioauth/src/mock/benchmarking.rs b/crates/pallet-bioauth/src/mock/benchmarking.rs index 51da75f03..45cf40eae 100644 --- a/crates/pallet-bioauth/src/mock/benchmarking.rs +++ b/crates/pallet-bioauth/src/mock/benchmarking.rs @@ -103,7 +103,6 @@ impl crate::ValidatorSetUpdater for MockValidatorSetUpdater ) where ValidatorPublicKey: 'a, { - () } fn init_validators_set<'a, I: Iterator + 'a>( @@ -111,7 +110,6 @@ impl crate::ValidatorSetUpdater for MockValidatorSetUpdater ) where ValidatorPublicKey: 'a, { - () } } @@ -225,11 +223,8 @@ impl crate::benchmarking::RobonodePublicKeyBuilder for Benchmark { /// Build benchmark externalities from the default genesis. pub fn new_benchmark_ext() -> sp_io::TestExternalities { - // Build externalities with default genesis. - let externalities = new_benchmark_ext_with(Default::default()); - - // Return ready-to-use externalities. - externalities + // Build externalities with default genesis and return ready-to-use externalities. + new_benchmark_ext_with(Default::default()) } /// Build benchmark externalities from the custom genesis. diff --git a/crates/pallet-currency-swap/src/benchmarking.rs b/crates/pallet-currency-swap/src/benchmarking.rs index f00f9058f..45326ea33 100644 --- a/crates/pallet-currency-swap/src/benchmarking.rs +++ b/crates/pallet-currency-swap/src/benchmarking.rs @@ -1,5 +1,8 @@ //! The benchmarks for the pallet. +// Allow integer and float arithmetic in tests. +#![allow(clippy::arithmetic_side_effects, clippy::float_arithmetic)] + use frame_benchmarking::benchmarks; use frame_support::{assert_ok, dispatch::DispatchResult, traits::Currency}; use frame_system::RawOrigin; @@ -91,7 +94,7 @@ impl Interface for crate::mock::Test { swap_ctx.expect().times(1..).return_once(move |_| { Ok( >::NegativeImbalance::new( - Self::to_balance().into(), + Self::to_balance(), ), ) }); diff --git a/crates/pallet-evm-accounts-mapping/src/benchmarking.rs b/crates/pallet-evm-accounts-mapping/src/benchmarking.rs index 98fcd6ff5..3a2777ee8 100644 --- a/crates/pallet-evm-accounts-mapping/src/benchmarking.rs +++ b/crates/pallet-evm-accounts-mapping/src/benchmarking.rs @@ -1,5 +1,8 @@ //! The benchmarks for the pallet. +// Allow float arithmetic in tests. +#![allow(clippy::float_arithmetic)] + use frame_benchmarking::benchmarks; use frame_system::RawOrigin; use primitives_ethereum::{EcdsaSignature, EthereumAddress}; diff --git a/crates/pallet-token-claims/src/benchmarking.rs b/crates/pallet-token-claims/src/benchmarking.rs index e8f87e03e..502955201 100644 --- a/crates/pallet-token-claims/src/benchmarking.rs +++ b/crates/pallet-token-claims/src/benchmarking.rs @@ -1,5 +1,8 @@ //! The benchmarks for the pallet. +// Allow integer and float arithmetic in tests. +#![allow(clippy::arithmetic_side_effects, clippy::float_arithmetic)] + use frame_benchmarking::benchmarks; use frame_support::{assert_ok, dispatch::DispatchResult, traits::Get}; use frame_system::RawOrigin; diff --git a/crates/pallet-vesting/src/benchmarking.rs b/crates/pallet-vesting/src/benchmarking.rs index d639f9f80..658112af6 100644 --- a/crates/pallet-vesting/src/benchmarking.rs +++ b/crates/pallet-vesting/src/benchmarking.rs @@ -1,5 +1,8 @@ //! The benchmarks for the pallet. +// Allow integer and float arithmetic in tests. +#![allow(clippy::arithmetic_side_effects, clippy::float_arithmetic)] + use frame_benchmarking::benchmarks; use frame_support::{ assert_ok,