From 28d35e5f40bc61d0081aab43a19871d87521f043 Mon Sep 17 00:00:00 2001 From: siddharthteli12 Date: Sat, 14 Oct 2023 13:28:46 +0530 Subject: [PATCH 1/2] Refactor: Cleanup with clippy --- node/src/chain_spec.rs | 2 +- node/src/command.rs | 17 +++-- node/src/rpc.rs | 10 +-- pallets/evm-accounts/src/mock.rs | 7 +- pallets/evm-utility/macro/src/lib.rs | 4 +- pallets/xc-asset-config/src/lib.rs | 12 ++-- pallets/xc-asset-config/src/tests.rs | 98 ++++++++++++------------- precompiles/assets-erc20/src/mock.rs | 7 +- precompiles/assets-erc20/src/tests.rs | 100 +++++++++++++------------- precompiles/utils/macro/src/lib.rs | 4 +- precompiles/utils/src/lib.rs | 2 +- precompiles/utils/src/testing.rs | 2 +- precompiles/utils/src/tests.rs | 12 ++-- 13 files changed, 135 insertions(+), 142 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index ce9552d..dc16e6a 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -17,7 +17,7 @@ const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) + TPublic::Pair::from_string(&format!("//{seed}"), None) .expect("static values are valid; qed") .public() } diff --git a/node/src/command.rs b/node/src/command.rs index dfb38fc..f9c2f4d 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -164,7 +164,7 @@ pub fn run() -> Result<()> { &polkadot_cli, config.tokio_handle.clone(), ) - .map_err(|err| format!("Relay chain argument error: {}", err))?; + .map_err(|err| format!("Relay chain argument error: {err}"))?; cmd.run(config, polkadot_config) }) @@ -208,12 +208,11 @@ pub fn run() -> Result<()> { }), #[cfg(not(feature = "runtime-benchmarks"))] BenchmarkCmd::Storage(_) => - return Err(sc_cli::Error::Input( + Err(sc_cli::Error::Input( "Compile with --features=runtime-benchmarks \ to enable storage benchmarks." .into(), - ) - .into()), + )), #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let partials = new_partial(&config)?; @@ -271,14 +270,14 @@ pub fn run() -> Result<()> { let hwbench = (!cli.no_hardware_benchmarks).then_some( config.database.path().map(|database_path| { - let _ = std::fs::create_dir_all(&database_path); + let _ = std::fs::create_dir_all(database_path); sc_sysinfo::gather_hwbench(Some(database_path)) }) ).flatten(); let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) - .ok_or_else(|| "Could not find parachain ID in chain-spec.")?; + .ok_or("Could not find parachain ID in chain-spec.")?; let polkadot_cli = RelayChainCli::new( &config, @@ -294,13 +293,13 @@ pub fn run() -> Result<()> { let state_version = Cli::native_runtime_version(&config.chain_spec).state_version(); let block: Block = generate_genesis_block(&*config.chain_spec, state_version) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode())); let tokio_handle = config.tokio_handle.clone(); let polkadot_config = SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) - .map_err(|err| format!("Relay chain argument error: {}", err))?; + .map_err(|err| format!("Relay chain argument error: {err}"))?; info!("Parachain id: {:?}", id); info!("Parachain Account: {}", parachain_account); @@ -314,7 +313,7 @@ pub fn run() -> Result<()> { } ); - if collator_options.relay_chain_rpc_urls.is_empty() && cli.relay_chain_args.len() > 0 { + if collator_options.relay_chain_rpc_urls.is_empty() && !cli.relay_chain_args.is_empty() { warn!("Detected relay chain node arguments together with --relay-chain-rpc-url. This command starts a minimal Polkadot node that only uses a network-related subset of all relay chain CLI options." ); diff --git a/node/src/rpc.rs b/node/src/rpc.rs index f535c92..0acf1d1 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -104,12 +104,12 @@ where module.merge( Eth::<_, _, _, fp_rpc::NoTransactionConverter, _, _, _>::new( client.clone(), - pool.clone(), + pool, graph, no_tx_converter, - sync.clone(), + sync, signers, - overrides.clone(), + overrides, backend.clone(), is_authority, block_data_cache.clone(), @@ -136,8 +136,8 @@ where module.merge( Net::new( - client.clone(), - network.clone(), + client, + network, // Whether to format the `peer_count` response as Hex (default) or not. true, ) diff --git a/pallets/evm-accounts/src/mock.rs b/pallets/evm-accounts/src/mock.rs index 82a3922..168ae88 100644 --- a/pallets/evm-accounts/src/mock.rs +++ b/pallets/evm-accounts/src/mock.rs @@ -97,13 +97,10 @@ construct_runtime!( } ); +#[derive(Default)] pub struct ExtBuilder(); -impl Default for ExtBuilder { - fn default() -> Self { - Self() - } -} + impl ExtBuilder { pub fn build(self) -> sp_io::TestExternalities { diff --git a/pallets/evm-utility/macro/src/lib.rs b/pallets/evm-utility/macro/src/lib.rs index 644adf3..c9b94b8 100644 --- a/pallets/evm-utility/macro/src/lib.rs +++ b/pallets/evm-utility/macro/src/lib.rs @@ -42,10 +42,10 @@ pub fn generate_function_selector(_: TokenStream, input: TokenStream) -> TokenSt attrs: Default::default(), })); } else { - panic!("Not method string: `{:?}`", lit); + panic!("Not method string: `{lit:?}`"); } } else { - panic!("Not enum: `{:?}`", variant); + panic!("Not enum: `{variant:?}`"); } } diff --git a/pallets/xc-asset-config/src/lib.rs b/pallets/xc-asset-config/src/lib.rs index c7ff842..e4a4991 100644 --- a/pallets/xc-asset-config/src/lib.rs +++ b/pallets/xc-asset-config/src/lib.rs @@ -213,7 +213,7 @@ pub mod pallet { // Ensure such an assetId does not exist ensure!( - !AssetIdToLocation::::contains_key(&asset_id), + !AssetIdToLocation::::contains_key(asset_id), Error::::AssetAlreadyRegistered ); @@ -221,7 +221,7 @@ pub mod pallet { .map_err(|_| Error::::MultiLocationNotSupported)?; let asset_location = VersionedMultiLocation::V3(v3_asset_loc); - AssetIdToLocation::::insert(&asset_id, asset_location.clone()); + AssetIdToLocation::::insert(asset_id, asset_location.clone()); AssetLocationToId::::insert(&asset_location, asset_id); T::XcAssetChanged::xc_asset_registered(asset_id); @@ -278,10 +278,10 @@ pub mod pallet { let new_asset_location = VersionedMultiLocation::V3(v3_asset_loc); let previous_asset_location = - AssetIdToLocation::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + AssetIdToLocation::::get(asset_id).ok_or(Error::::AssetDoesNotExist)?; // Insert new asset type info - AssetIdToLocation::::insert(&asset_id, new_asset_location.clone()); + AssetIdToLocation::::insert(asset_id, new_asset_location.clone()); AssetLocationToId::::insert(&new_asset_location, asset_id); // Remove previous asset type info @@ -331,9 +331,9 @@ pub mod pallet { T::ManagerOrigin::ensure_origin(origin)?; let asset_location = - AssetIdToLocation::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + AssetIdToLocation::::get(asset_id).ok_or(Error::::AssetDoesNotExist)?; - AssetIdToLocation::::remove(&asset_id); + AssetIdToLocation::::remove(asset_id); AssetLocationToId::::remove(&asset_location); AssetLocationUnitsPerSecond::::remove(&asset_location); T::XcAssetChanged::xc_asset_unregistered(asset_id); diff --git a/pallets/xc-asset-config/src/tests.rs b/pallets/xc-asset-config/src/tests.rs index 7e58c4d..c7e733d 100644 --- a/pallets/xc-asset-config/src/tests.rs +++ b/pallets/xc-asset-config/src/tests.rs @@ -42,7 +42,7 @@ fn only_root_as_origin() { assert_noop!( XcAssetConfig::remove_payment_asset( RuntimeOrigin::signed(1), - Box::new(asset_location.clone()), + Box::new(asset_location), ), BadOrigin ); @@ -67,40 +67,40 @@ fn register_asset_location_and_units_per_sec_is_ok() { // Register asset and ensure it's ok assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id )); System::assert_last_event(mock::RuntimeEvent::XcAssetConfig(Event::AssetRegistered { - asset_location: asset_location.clone().into_versioned(), - asset_id: asset_id, + asset_location: asset_location.into_versioned(), + asset_id, })); // Assert storage state after registering asset assert_eq!( - AssetIdToLocation::::get(&asset_id).unwrap(), - asset_location.clone().into_versioned() + AssetIdToLocation::::get(asset_id).unwrap(), + asset_location.into_versioned() ); assert_eq!( - AssetLocationToId::::get(asset_location.clone().into_versioned()).unwrap(), + AssetLocationToId::::get(asset_location.into_versioned()).unwrap(), asset_id ); assert!(!AssetLocationUnitsPerSecond::::contains_key( - asset_location.clone().into_versioned() + asset_location.into_versioned() )); // Register unit per second rate and verify storage let units: u128 = 7 * 11 * 13 * 17 * 29; assert_ok!(XcAssetConfig::set_asset_units_per_second( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), units )); System::assert_last_event(mock::RuntimeEvent::XcAssetConfig(Event::UnitsPerSecondChanged { - asset_location: asset_location.clone().into_versioned(), + asset_location: asset_location.into_versioned(), units_per_second: units, })); assert_eq!( - AssetLocationUnitsPerSecond::::get(&asset_location.clone().into_versioned()) + AssetLocationUnitsPerSecond::::get(asset_location.into_versioned()) .unwrap(), units ); @@ -120,7 +120,7 @@ fn asset_is_already_registered() { // Register asset and ensure it's ok assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id )); @@ -128,7 +128,7 @@ fn asset_is_already_registered() { assert_noop!( XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id ), Error::::AssetAlreadyRegistered @@ -147,12 +147,12 @@ fn change_asset_location_is_ok() { // Register asset and ups assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id )); assert_ok!(XcAssetConfig::set_asset_units_per_second( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), units )); @@ -162,31 +162,31 @@ fn change_asset_location_is_ok() { assert_ok!(XcAssetConfig::change_existing_asset_location( RuntimeOrigin::root(), - Box::new(new_asset_location.clone().into_versioned()), + Box::new(new_asset_location.into_versioned()), asset_id )); System::assert_last_event(mock::RuntimeEvent::XcAssetConfig(Event::AssetLocationChanged { - previous_asset_location: asset_location.clone().into_versioned(), - asset_id: asset_id, - new_asset_location: new_asset_location.clone().into_versioned(), + previous_asset_location: asset_location.into_versioned(), + asset_id, + new_asset_location: new_asset_location.into_versioned(), })); // Assert storage state assert_eq!( - AssetIdToLocation::::get(&asset_id).unwrap(), - new_asset_location.clone().into_versioned() + AssetIdToLocation::::get(asset_id).unwrap(), + new_asset_location.into_versioned() ); assert_eq!( - AssetLocationToId::::get(new_asset_location.clone().into_versioned()).unwrap(), + AssetLocationToId::::get(new_asset_location.into_versioned()).unwrap(), asset_id ); // This should have been deleted assert!(!AssetLocationUnitsPerSecond::::contains_key( - asset_location.clone().into_versioned() + asset_location.into_versioned() )); assert_eq!( - AssetLocationUnitsPerSecond::::get(new_asset_location.clone().into_versioned()) + AssetLocationUnitsPerSecond::::get(new_asset_location.into_versioned()) .unwrap(), units ); @@ -204,31 +204,31 @@ fn remove_payment_asset_is_ok() { // Register asset and ups assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id )); assert_ok!(XcAssetConfig::set_asset_units_per_second( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), units )); // Now we remove supported asset assert_ok!(XcAssetConfig::remove_payment_asset( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), )); System::assert_last_event(mock::RuntimeEvent::XcAssetConfig(Event::SupportedAssetRemoved { - asset_location: asset_location.clone().into_versioned(), + asset_location: asset_location.into_versioned(), })); assert!(!AssetLocationUnitsPerSecond::::contains_key( - asset_location.clone().into_versioned() + asset_location.into_versioned() )); // Repeated calls don't do anything assert_ok!(XcAssetConfig::remove_payment_asset( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), )); }) } @@ -244,29 +244,29 @@ fn remove_asset_is_ok() { // Register asset and ups assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id )); assert_ok!(XcAssetConfig::set_asset_units_per_second( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), units )); // Remove asset entirely and assert op is ok assert_ok!(XcAssetConfig::remove_asset(RuntimeOrigin::root(), asset_id,)); System::assert_last_event(mock::RuntimeEvent::XcAssetConfig(Event::AssetRemoved { - asset_location: asset_location.clone().into_versioned(), - asset_id: asset_id, + asset_location: asset_location.into_versioned(), + asset_id, })); // Assert that storage is empty after successful removal assert!(!AssetIdToLocation::::contains_key(asset_id)); assert!(!AssetLocationToId::::contains_key( - asset_location.clone().into_versioned() + asset_location.into_versioned() )); assert!(!AssetLocationUnitsPerSecond::::contains_key( - asset_location.clone().into_versioned() + asset_location.into_versioned() )); }) } @@ -282,7 +282,7 @@ fn not_registered_asset_is_not_ok() { assert_noop!( XcAssetConfig::set_asset_units_per_second( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), units ), Error::::AssetDoesNotExist @@ -291,7 +291,7 @@ fn not_registered_asset_is_not_ok() { assert_noop!( XcAssetConfig::change_existing_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id ), Error::::AssetDoesNotExist @@ -314,33 +314,33 @@ fn public_interfaces_are_ok() { // Initially, expect `None` to be returned for all assert!(XcAssetConfig::get_xc_asset_location(asset_id).is_none()); - assert!(XcAssetConfig::get_asset_id(asset_location.clone()).is_none()); - assert!(XcAssetConfig::get_units_per_second(asset_location.clone()).is_none()); + assert!(XcAssetConfig::get_asset_id(asset_location).is_none()); + assert!(XcAssetConfig::get_units_per_second(asset_location).is_none()); // Register asset and expect values to be returned but UPS should still be `None` assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), asset_id )); assert_eq!( XcAssetConfig::get_xc_asset_location(asset_id), - Some(asset_location.clone()) + Some(asset_location) ); assert_eq!( - XcAssetConfig::get_asset_id(asset_location.clone()), + XcAssetConfig::get_asset_id(asset_location), Some(asset_id) ); - assert!(XcAssetConfig::get_units_per_second(asset_location.clone()).is_none()); + assert!(XcAssetConfig::get_units_per_second(asset_location).is_none()); // Register ups and expect value value to be returned assert_ok!(XcAssetConfig::set_asset_units_per_second( RuntimeOrigin::root(), - Box::new(asset_location.clone().into_versioned()), + Box::new(asset_location.into_versioned()), units )); assert_eq!( - XcAssetConfig::get_units_per_second(asset_location.clone()), + XcAssetConfig::get_units_per_second(asset_location), Some(units) ); }) @@ -357,14 +357,14 @@ fn different_xcm_versions_are_ok() { // Register asset using legacy multilocation assert_ok!(XcAssetConfig::register_asset_location( RuntimeOrigin::root(), - Box::new(VersionedMultiLocation::V2(legacy_asset_location.clone())), + Box::new(VersionedMultiLocation::V2(legacy_asset_location)), asset_id )); // Ensure that the new format is properly returned assert_eq!( XcAssetConfig::get_xc_asset_location(asset_id), - Some(new_asset_location.clone()) + Some(new_asset_location) ); }) } @@ -418,7 +418,7 @@ fn incompatible_versioned_multilocations_are_not_ok() { XcAssetConfig::remove_payment_asset( RuntimeOrigin::root(), Box::new(VersionedMultiLocation::V2( - incompatible_asset_location.clone() + incompatible_asset_location )), ), Error::::MultiLocationNotSupported diff --git a/precompiles/assets-erc20/src/mock.rs b/precompiles/assets-erc20/src/mock.rs index f785ded..5f064c5 100644 --- a/precompiles/assets-erc20/src/mock.rs +++ b/precompiles/assets-erc20/src/mock.rs @@ -275,16 +275,13 @@ construct_runtime!( } ); +#[derive(Default)] pub(crate) struct ExtBuilder { // endowed accounts with balances balances: Vec<(AccountId, Balance)>, } -impl Default for ExtBuilder { - fn default() -> ExtBuilder { - ExtBuilder { balances: vec![] } - } -} + impl ExtBuilder { pub(crate) fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { diff --git a/precompiles/assets-erc20/src/tests.rs b/precompiles/assets-erc20/src/tests.rs index 6983153..7b528d7 100644 --- a/precompiles/assets-erc20/src/tests.rs +++ b/precompiles/assets-erc20/src/tests.rs @@ -35,7 +35,7 @@ fn selector_less_than_four_bytes() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); @@ -52,7 +52,7 @@ fn no_selector_exists_but_length_is_right() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); @@ -103,14 +103,14 @@ fn get_total_supply() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -135,14 +135,14 @@ fn get_balances_known_user() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -169,7 +169,7 @@ fn get_balances_unknown_user() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); @@ -197,14 +197,14 @@ fn approve() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -236,14 +236,14 @@ fn approve_saturating() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -288,14 +288,14 @@ fn check_allowance_existing() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -334,7 +334,7 @@ fn check_allowance_not_existing() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); @@ -363,14 +363,14 @@ fn increase_allowance() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1200 )); @@ -419,14 +419,14 @@ fn increase_allowance_saturating() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1200 )); @@ -505,14 +505,14 @@ fn decrease_allowance() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1200 )); @@ -562,14 +562,14 @@ fn decrease_allowance_saturating() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1200 )); @@ -619,14 +619,14 @@ fn transfer() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -682,14 +682,14 @@ fn transfer_not_enough_founds() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1 )); @@ -703,10 +703,10 @@ fn transfer_not_enough_founds() { .build(), ) .execute_reverts(|output| { - from_utf8(&output) + from_utf8(output) .unwrap() .contains("Dispatched call failed with error: DispatchErrorWithPostInfo") - && from_utf8(&output).unwrap().contains("BalanceLow") + && from_utf8(output).unwrap().contains("BalanceLow") }); }); } @@ -720,14 +720,14 @@ fn transfer_from() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -818,14 +818,14 @@ fn transfer_from_non_incremental_approval() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -898,14 +898,14 @@ fn transfer_from_above_allowance() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -949,14 +949,14 @@ fn transfer_from_self() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), 0u128, - Account::Alice.into(), + Account::Alice, 1000 )); @@ -1013,7 +1013,7 @@ fn get_metadata() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, 1 )); @@ -1069,7 +1069,7 @@ fn minimum_balance_is_right() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), 0u128, - Account::Alice.into(), + Account::Alice, true, expected_min_balance, )); @@ -1093,13 +1093,13 @@ fn mint_is_ok() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), asset_id, - Account::Alice.into(), + Account::Alice, true, 1, )); // Sanity check, Bob should be without assets - assert!(Assets::balance(asset_id, &Account::Bob.into()).is_zero()); + assert!(Assets::balance(asset_id, &Account::Bob).is_zero()); // Mint some assets for Bob let mint_amount = 7 * 11 * 19; @@ -1116,7 +1116,7 @@ fn mint_is_ok() { .execute_returns(EvmDataWriter::new().write(true).build()); // Ensure Bob's asset balance was increased - assert_eq!(Assets::balance(asset_id, &Account::Bob.into()), mint_amount); + assert_eq!(Assets::balance(asset_id, &Account::Bob), mint_amount); }); } @@ -1127,7 +1127,7 @@ fn mint_non_admin_is_not_ok() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), asset_id, - Account::Alice.into(), + Account::Alice, true, 1, )); @@ -1142,7 +1142,7 @@ fn mint_non_admin_is_not_ok() { .build(), ) .expect_no_logs() - .execute_reverts(|output| from_utf8(&output).unwrap().contains("NoPermission")); + .execute_reverts(|output| from_utf8(output).unwrap().contains("NoPermission")); }); } @@ -1153,7 +1153,7 @@ fn burn_is_ok() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), asset_id, - Account::Alice.into(), + Account::Alice, true, 1, )); @@ -1163,10 +1163,10 @@ fn burn_is_ok() { assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), asset_id, - Account::Bob.into(), + Account::Bob, init_amount, )); - assert_eq!(Assets::balance(asset_id, &Account::Bob.into()), init_amount); + assert_eq!(Assets::balance(asset_id, &Account::Bob), init_amount); // Burn some assets from Bob let burn_amount = 19; @@ -1184,7 +1184,7 @@ fn burn_is_ok() { // Ensure Bob's asset balance was decreased assert_eq!( - Assets::balance(asset_id, &Account::Bob.into()), + Assets::balance(asset_id, &Account::Bob), init_amount - burn_amount ); }); @@ -1197,14 +1197,14 @@ fn burn_non_admin_is_not_ok() { assert_ok!(Assets::force_create( RuntimeOrigin::root(), asset_id, - Account::Alice.into(), + Account::Alice, true, 1, )); assert_ok!(Assets::mint( RuntimeOrigin::signed(Account::Alice), asset_id, - Account::Bob.into(), + Account::Bob, 1000000, )); @@ -1218,6 +1218,6 @@ fn burn_non_admin_is_not_ok() { .build(), ) .expect_no_logs() - .execute_reverts(|output| from_utf8(&output).unwrap().contains("NoPermission")); + .execute_reverts(|output| from_utf8(output).unwrap().contains("NoPermission")); }); } diff --git a/precompiles/utils/macro/src/lib.rs b/precompiles/utils/macro/src/lib.rs index 64394e7..4aff9b2 100644 --- a/precompiles/utils/macro/src/lib.rs +++ b/precompiles/utils/macro/src/lib.rs @@ -37,7 +37,7 @@ impl ::std::fmt::Debug for Bytes { if !data.is_empty() { write!(f, "{:#04x}u8", data[0])?; for unit in data.iter().skip(1) { - write!(f, ", {:#04x}", unit)?; + write!(f, ", {unit:#04x}")?; } } write!(f, "]") @@ -51,7 +51,7 @@ pub fn keccak256(input: TokenStream) -> TokenStream { let hash = Keccak256::digest(lit_str.value().as_ref()); let bytes = Bytes(hash.to_vec()); - let eval_str = format!("{:?}", bytes); + let eval_str = format!("{bytes:?}"); let eval_ts: proc_macro2::TokenStream = eval_str.parse().unwrap_or_else(|_| { panic!( "Failed to parse the string \"{}\" to TokenStream.", diff --git a/precompiles/utils/src/lib.rs b/precompiles/utils/src/lib.rs index e20bee6..f396c8f 100644 --- a/precompiles/utils/src/lib.rs +++ b/precompiles/utils/src/lib.rs @@ -196,7 +196,7 @@ where // computations. let result = call .dispatch(origin) - .map_err(|e| revert(alloc::format!("Dispatched call failed with error: {:?}", e)))?; + .map_err(|e| revert(alloc::format!("Dispatched call failed with error: {e:?}")))?; let used_weight = result.actual_weight; diff --git a/precompiles/utils/src/testing.rs b/precompiles/utils/src/testing.rs index 8a05bfd..c1ac1b1 100644 --- a/precompiles/utils/src/testing.rs +++ b/precompiles/utils/src/testing.rs @@ -414,7 +414,7 @@ impl core::fmt::Debug for PrettyLog { .0 .data .iter() - .map(|b| format!("{:02X}", b)) + .map(|b| format!("{b:02X}")) .collect::>() .join(""); diff --git a/precompiles/utils/src/tests.rs b/precompiles/utils/src/tests.rs index 071a7a8..223a0fd 100644 --- a/precompiles/utils/src/tests.rs +++ b/precompiles/utils/src/tests.rs @@ -13,8 +13,8 @@ fn u256_repeat_byte(byte: u8) -> U256 { fn display_bytes(bytes: &[u8]) { bytes .chunks_exact(32) - .map(|chunk| H256::from_slice(chunk)) - .for_each(|hash| println!("{:?}", hash)); + .map(H256::from_slice) + .for_each(|hash| println!("{hash:?}")); } #[test] @@ -555,8 +555,8 @@ fn write_vec_bytes() { writer_output .chunks_exact(32) - .map(|chunk| H256::from_slice(chunk)) - .for_each(|hash| println!("{:?}", hash)); + .map(H256::from_slice) + .for_each(|hash| println!("{hash:?}")); // We pad data to a multiple of 32 bytes. let mut padded = data.to_vec(); @@ -608,8 +608,8 @@ fn read_vec_of_bytes() { writer_output .chunks_exact(32) - .map(|chunk| H256::from_slice(chunk)) - .for_each(|hash| println!("{:?}", hash)); + .map(H256::from_slice) + .for_each(|hash| println!("{hash:?}")); let mut reader = EvmDataReader::new(&writer_output); let parsed: Vec = reader.read().expect("to correctly parse Vec"); From 296c872c3bee991c887b10760b2e084cd51a6a08 Mon Sep 17 00:00:00 2001 From: siddharthteli12 Date: Sat, 14 Oct 2023 13:50:13 +0530 Subject: [PATCH 2/2] Refactor: Remove must use macro --- precompiles/utils/src/lib.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/precompiles/utils/src/lib.rs b/precompiles/utils/src/lib.rs index f396c8f..09eb403 100644 --- a/precompiles/utils/src/lib.rs +++ b/precompiles/utils/src/lib.rs @@ -241,27 +241,22 @@ pub enum FunctionModifier { } pub trait PrecompileHandleExt: PrecompileHandle { - #[must_use] /// Record cost of a log manually. /// This can be useful to record log costs early when their content have static size. fn record_log_costs_manual(&mut self, topics: usize, data_len: usize) -> EvmResult; - #[must_use] /// Record cost of logs. fn record_log_costs(&mut self, logs: &[&Log]) -> EvmResult; - #[must_use] /// Check that a function call is compatible with the context it is /// called into. fn check_function_modifier(&self, modifier: FunctionModifier) -> EvmResult; - #[must_use] /// Read the selector from the input data. fn read_selector(&self) -> EvmResult where T: num_enum::TryFromPrimitive; - #[must_use] /// Returns a reader of the input, skipping the selector. fn read_input(&self) -> EvmResult; } @@ -298,7 +293,6 @@ pub fn log_costs(topics: usize, data_len: usize) -> EvmResult { } impl PrecompileHandleExt for T { - #[must_use] /// Record cost of a log manualy. /// This can be useful to record log costs early when their content have static size. fn record_log_costs_manual(&mut self, topics: usize, data_len: usize) -> EvmResult { @@ -307,7 +301,6 @@ impl PrecompileHandleExt for T { Ok(()) } - #[must_use] /// Record cost of logs. fn record_log_costs(&mut self, logs: &[&Log]) -> EvmResult { for log in logs { @@ -317,14 +310,12 @@ impl PrecompileHandleExt for T { Ok(()) } - #[must_use] /// Check that a function call is compatible with the context it is /// called into. fn check_function_modifier(&self, modifier: FunctionModifier) -> EvmResult { check_function_modifier(self.context(), self.is_static(), modifier) } - #[must_use] /// Read the selector from the input data. fn read_selector(&self) -> EvmResult where @@ -333,7 +324,6 @@ impl PrecompileHandleExt for T { EvmDataReader::read_selector(self.input()) } - #[must_use] /// Returns a reader of the input, skipping the selector. fn read_input(&self) -> EvmResult { EvmDataReader::new_skip_selector(self.input())