From bed43b088aa3a4af7ff8f4d75afddb8b3b0a439e Mon Sep 17 00:00:00 2001 From: Klaudiusz Dembler Date: Sun, 2 Jun 2024 13:21:32 +0200 Subject: [PATCH] fix clippy warnings --- bin/node/src/chain_spec/argo_bridge_config.rs | 2 - .../argo-bridge/src/benchmarking.rs | 54 +++++++++---------- runtime-modules/argo-bridge/src/lib.rs | 4 +- runtime-modules/argo-bridge/src/tests/mock.rs | 5 +- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/bin/node/src/chain_spec/argo_bridge_config.rs b/bin/node/src/chain_spec/argo_bridge_config.rs index 831a5014b8..38528f60be 100644 --- a/bin/node/src/chain_spec/argo_bridge_config.rs +++ b/bin/node/src/chain_spec/argo_bridge_config.rs @@ -6,7 +6,6 @@ pub fn production_config() -> ArgoBridgeConfig { mint_allowance: 0, bridging_fee: DefaultBridgingFee::get(), thawn_duration: 1, - ..Default::default() } } @@ -16,6 +15,5 @@ pub fn testing_config() -> ArgoBridgeConfig { mint_allowance: 0, bridging_fee: DefaultBridgingFee::get(), thawn_duration: 1, - ..Default::default() } } diff --git a/runtime-modules/argo-bridge/src/benchmarking.rs b/runtime-modules/argo-bridge/src/benchmarking.rs index e557b648b6..b22b7bcd4a 100644 --- a/runtime-modules/argo-bridge/src/benchmarking.rs +++ b/runtime-modules/argo-bridge/src/benchmarking.rs @@ -33,7 +33,7 @@ impl CreateAccountId for u64 { impl CreateAccountId for u32 { fn create_account_id(id: u32) -> Self { - id.into() + id } } @@ -56,7 +56,7 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { fn activate_bridge(pauser_acount: &T::AccountId, operator_acount: &T::AccountId) { let pauser_origin = RawOrigin::Signed(pauser_acount.clone()); - ArgoBridge::::init_unpause_bridge(pauser_origin.clone().into()).unwrap(); + ArgoBridge::::init_unpause_bridge(pauser_origin.into()).unwrap(); System::::set_block_number(3u32.into()); ArgoBridge::::finish_unpause_bridge(RawOrigin::Signed(operator_acount.clone()).into()) .unwrap(); @@ -66,17 +66,17 @@ fn set_bridge_mint_allowance(amount: BalanceOf, fee: BalanceOf) where T::AccountId: CreateAccountId, { - let sender = T::AccountId::create_account_id(1u32.into()); + let sender = T::AccountId::create_account_id(1u32); let _ = Balances::::deposit_creating( &sender, - T::ExistentialDeposit::get() + amount.into() + fee + 10u32.into(), + T::ExistentialDeposit::get() + amount + fee + 10u32.into(), ); let remote_account = RemoteAccount { account: [0; 32], chain_id: MAX_REMOTE_CHAINS - 1, }; ArgoBridge::::request_outbound_transfer( - RawOrigin::Signed(sender.clone()).into(), + RawOrigin::Signed(sender).into(), remote_account, amount + fee, fee, @@ -97,10 +97,10 @@ benchmarks! { let fee: BalanceOf = 10u32.into(); let remote_chains: Vec = (0..MAX_REMOTE_CHAINS).collect(); let pauser_acount = T::AccountId::create_account_id(1); - let operator_account = T::AccountId::create_account_id(1u32.into()); + let operator_account = T::AccountId::create_account_id(1u32); let parameters = BridgeConstraints { operator_account: Some(operator_account.clone()), - pauser_accounts: Some(vec![pauser_acount.clone().into()]), + pauser_accounts: Some(vec![pauser_acount.clone()]), bridging_fee: Some(fee), thawn_duration: Some(1u32.into()), remote_chains: Some(BoundedVec::try_from(remote_chains).unwrap()) @@ -112,8 +112,8 @@ benchmarks! { ).unwrap(); activate_bridge::(&pauser_acount, &operator_account); - let initial_balance: u32 = 1030u32.into(); - let sender = T::AccountId::create_account_id(1u32.into()); + let initial_balance: u32 = 1030u32; + let sender = T::AccountId::create_account_id(1u32); let _ = Balances::::deposit_creating(&sender, T::ExistentialDeposit::get() + initial_balance.into()); let dest_account = RemoteAccount { @@ -125,7 +125,7 @@ benchmarks! { let transfer_amount = 100u32.into(); }: _(origin, dest_account, transfer_amount, fee) verify { - let sender = T::AccountId::create_account_id(1u32.into()); + let sender = T::AccountId::create_account_id(1u32); assert_last_event::( RawEvent::OutboundTransferRequested(transfer_id, sender, dest_account, transfer_amount, fee).into()); } @@ -138,10 +138,10 @@ benchmarks! { let fee: BalanceOf = 10u32.into(); let remote_chains: Vec = (0..MAX_REMOTE_CHAINS).collect(); let pauser_acount = T::AccountId::create_account_id(1); - let operator_account = T::AccountId::create_account_id(1u32.into()); + let operator_account = T::AccountId::create_account_id(1u32); let parameters = BridgeConstraints { operator_account: Some(operator_account.clone()), - pauser_accounts: Some(vec![pauser_acount.clone().into()]), + pauser_accounts: Some(vec![pauser_acount.clone()]), bridging_fee: Some(fee), thawn_duration: Some(1u32.into()), remote_chains: Some(BoundedVec::try_from(remote_chains).unwrap()) @@ -155,8 +155,8 @@ benchmarks! { let transfer_amount = 100u32.into(); set_bridge_mint_allowance::(1030u32.into(), fee); - let operator = T::AccountId::create_account_id(1u32.into()); - let dest_account = T::AccountId::create_account_id(1u32.into()); + let operator = T::AccountId::create_account_id(1u32); + let dest_account = T::AccountId::create_account_id(1u32); let remote_transfer = RemoteTransfer { id: 0, chain_id: MAX_REMOTE_CHAINS - 1 }; }: _(RawOrigin::Signed(operator), remote_transfer.clone(), dest_account.clone(), transfer_amount) verify { @@ -169,9 +169,9 @@ benchmarks! { // - using the last pauser account pause_bridge{ let pauser_accounts: Vec = (0..T::MaxPauserAccounts::get()) - .map(|i| T::AccountId::create_account_id(i)) + .map(T::AccountId::create_account_id) .collect(); - let operator_account = T::AccountId::create_account_id(1u32.into()); + let operator_account = T::AccountId::create_account_id(1u32); let parameters = BridgeConstraints { operator_account: Some(operator_account.clone()), pauser_accounts: Some(pauser_accounts.clone()), @@ -185,12 +185,12 @@ benchmarks! { ).unwrap(); activate_bridge::(&pauser_accounts[0], &operator_account); - let pauser_acount = T::AccountId::create_account_id((T::MaxPauserAccounts::get() - 1).into()); + let pauser_acount = T::AccountId::create_account_id(T::MaxPauserAccounts::get() - 1); }: _(RawOrigin::Signed(pauser_acount.clone())) verify { assert_eq!(ArgoBridge::::status(), BridgeStatus::Paused); assert_last_event::( - RawEvent::BridgePaused(pauser_acount.clone()).into()); + RawEvent::BridgePaused(pauser_acount).into()); } // Worst case scenario: @@ -198,9 +198,9 @@ benchmarks! { // - using the last pauser account init_unpause_bridge{ let pauser_accounts: Vec = (0..T::MaxPauserAccounts::get()) - .map(|i| T::AccountId::create_account_id(i)) + .map(T::AccountId::create_account_id) .collect(); - let operator_account = T::AccountId::create_account_id(1u32.into()); + let operator_account = T::AccountId::create_account_id(1u32); let parameters = BridgeConstraints { operator_account: Some(operator_account.clone()), pauser_accounts: Some(pauser_accounts.clone()), @@ -214,7 +214,7 @@ benchmarks! { ).unwrap(); activate_bridge::(&pauser_accounts[0], &operator_account); - let pauser_acount = T::AccountId::create_account_id((T::MaxPauserAccounts::get() - 1) .into()); + let pauser_acount = T::AccountId::create_account_id(T::MaxPauserAccounts::get() - 1); ArgoBridge::::pause_bridge(RawOrigin::Signed(pauser_acount.clone()).into()).unwrap(); }: _(RawOrigin::Signed(pauser_acount.clone())) verify { @@ -228,9 +228,9 @@ benchmarks! { // - using the last pauser account finish_unpause_bridge{ let pauser_accounts: Vec = (0..T::MaxPauserAccounts::get()) - .map(|i| T::AccountId::create_account_id(i)) + .map(T::AccountId::create_account_id) .collect(); - let operator_account = T::AccountId::create_account_id(1u32.into()); + let operator_account = T::AccountId::create_account_id(1u32); let parameters = BridgeConstraints { operator_account: Some(operator_account.clone()), pauser_accounts: Some(pauser_accounts.clone()), @@ -244,8 +244,8 @@ benchmarks! { ).unwrap(); activate_bridge::(&pauser_accounts[0], &operator_account); - let pauser_acount = T::AccountId::create_account_id((T::MaxPauserAccounts::get() - 1) .into()); - let origin = RawOrigin::Signed(pauser_acount.clone()); + let pauser_acount = T::AccountId::create_account_id(T::MaxPauserAccounts::get() - 1); + let origin = RawOrigin::Signed(pauser_acount); ArgoBridge::::pause_bridge(origin.clone().into()).unwrap(); ArgoBridge::::init_unpause_bridge(origin.into()).unwrap(); System::::set_block_number(System::::block_number() + 3u32.into()); @@ -261,9 +261,9 @@ benchmarks! { update_bridge_constrains{ let fee: BalanceOf = 10u32.into(); let pauser_accounts: Vec = (0..T::MaxPauserAccounts::get()) - .map(|i| T::AccountId::create_account_id(i)) + .map(T::AccountId::create_account_id) .collect(); - let operator_account = T::AccountId::create_account_id(1u32.into()); + let operator_account = T::AccountId::create_account_id(1u32); let remote_chains: Vec = (0..MAX_REMOTE_CHAINS).collect(); let parameters = BridgeConstraints { diff --git a/runtime-modules/argo-bridge/src/lib.rs b/runtime-modules/argo-bridge/src/lib.rs index 3627b33d56..bd8622950a 100644 --- a/runtime-modules/argo-bridge/src/lib.rs +++ b/runtime-modules/argo-bridge/src/lib.rs @@ -117,7 +117,7 @@ decl_module! { #[weight = WeightInfoArgo::::finalize_inbound_transfer()] pub fn finalize_inbound_transfer(origin, remote_transfer: RemoteTransfer, dest_account: T::AccountId, amount: BalanceOf) -> DispatchResult { - ensure!(!Self::operator_account().is_none(), Error::::OperatorAccountNotSet); + ensure!(Self::operator_account().is_some(), Error::::OperatorAccountNotSet); let caller = ensure_signed(origin)?; ensure!(caller == Self::operator_account().unwrap(), Error::::NotOperatorAccount); @@ -165,7 +165,7 @@ decl_module! { #[weight = WeightInfoArgo::::finish_unpause_bridge()] pub fn finish_unpause_bridge(origin) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(!Self::operator_account().is_none(), Error::::OperatorAccountNotSet); + ensure!(Self::operator_account().is_some(), Error::::OperatorAccountNotSet); ensure!(caller == Self::operator_account().unwrap(), Error::::NotOperatorAccount); let current_block = >::block_number(); diff --git a/runtime-modules/argo-bridge/src/tests/mock.rs b/runtime-modules/argo-bridge/src/tests/mock.rs index 1c56db7b6a..09e3bc8001 100644 --- a/runtime-modules/argo-bridge/src/tests/mock.rs +++ b/runtime-modules/argo-bridge/src/tests/mock.rs @@ -8,10 +8,7 @@ use frame_support::{ traits::{OnFinalize, OnInitialize}, }; -use frame_support::{ - traits::{ConstU16, ConstU32, ConstU64}, - PalletId, -}; +use frame_support::traits::{ConstU16, ConstU32, ConstU64}; use sp_runtime::testing::{Header, H256}; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use sp_std::convert::{TryFrom, TryInto};