From 43adad4c1b8ce4b54f5b44441fc74e7b38bf3642 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Sat, 3 Jun 2023 11:33:44 +0100 Subject: [PATCH 1/2] Remove unrequired check The get_pool_account function no longer relies on a `_trucating` function, and there is a test in place should someone alter the function to create pool collisions. --- frame/asset-conversion/src/benchmarking.rs | 2 -- frame/asset-conversion/src/lib.rs | 28 ++-------------------- frame/asset-conversion/src/mock.rs | 2 +- frame/asset-conversion/src/types.rs | 4 ++-- 4 files changed, 5 insertions(+), 31 deletions(-) diff --git a/frame/asset-conversion/src/benchmarking.rs b/frame/asset-conversion/src/benchmarking.rs index 08afc1a46992f..0563a8543f087 100644 --- a/frame/asset-conversion/src/benchmarking.rs +++ b/frame/asset-conversion/src/benchmarking.rs @@ -17,8 +17,6 @@ //! Asset Conversion pallet benchmarking. -#![cfg(feature = "runtime-benchmarks")] - use super::*; use frame_benchmarking::{benchmarks, whitelisted_caller}; use frame_support::{ diff --git a/frame/asset-conversion/src/lib.rs b/frame/asset-conversion/src/lib.rs index 266c4eb77449f..9d7a418f824a9 100644 --- a/frame/asset-conversion/src/lib.rs +++ b/frame/asset-conversion/src/lib.rs @@ -201,7 +201,7 @@ pub mod pallet { type WeightInfo: WeightInfo; /// The benchmarks need a way to create asset ids from u32s. - #[cfg(any(test, feature = "runtime-benchmarks"))] + #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper: BenchmarkHelper; } @@ -349,30 +349,6 @@ pub mod pallet { NonUniquePath, } - #[pallet::hooks] - impl Hooks for Pallet { - fn integrity_test() { - #[cfg(test)] - sp_io::TestExternalities::new_empty().execute_with(|| { - // ensure that the `AccountId` is set properly and doesn't generate the same - // pool account for different pool ids. - let native = T::MultiAssetIdConverter::get_native(); - let asset_1 = - T::MultiAssetIdConverter::into_multiasset_id(&T::BenchmarkHelper::asset_id(1)); - let asset_2 = - T::MultiAssetIdConverter::into_multiasset_id(&T::BenchmarkHelper::asset_id(2)); - assert!(asset_1 != asset_2, "must return different assets for different ids."); - let pool_account_1 = Self::get_pool_account(&(native.clone(), asset_1)); - let pool_account_2 = Self::get_pool_account(&(native, asset_2)); - assert!(sp_std::mem::size_of::() >= sp_std::mem::size_of::()); - assert!( - pool_account_1 != pool_account_2, - "AccountId should be set at least to u128" - ); - }); - } - } - /// Pallet's callable functions. #[pallet::call] impl Pallet { @@ -1107,8 +1083,8 @@ pub mod pallet { Ok(()) } - #[cfg(any(test, feature = "runtime-benchmarks"))] /// Returns the next pool asset id for benchmark purposes only. + #[cfg(feature = "runtime-benchmarks")] pub fn get_next_pool_asset_id() -> T::PoolAssetId { NextPoolAssetId::::get().unwrap_or(T::PoolAssetId::initial_value()) } diff --git a/frame/asset-conversion/src/mock.rs b/frame/asset-conversion/src/mock.rs index 9483cfca25c76..34d2eeb273ca8 100644 --- a/frame/asset-conversion/src/mock.rs +++ b/frame/asset-conversion/src/mock.rs @@ -178,7 +178,7 @@ impl Config for Test { type MultiAssetId = NativeOrAssetId; type MultiAssetIdConverter = NativeOrAssetIdConverter; - #[cfg(any(test, feature = "runtime-benchmarks"))] + #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); } diff --git a/frame/asset-conversion/src/types.rs b/frame/asset-conversion/src/types.rs index b370d410f82a2..837b14be283ef 100644 --- a/frame/asset-conversion/src/types.rs +++ b/frame/asset-conversion/src/types.rs @@ -50,13 +50,13 @@ pub trait MultiAssetIdConverter { } /// Benchmark Helper -#[cfg(any(test, feature = "runtime-benchmarks"))] +#[cfg(feature = "runtime-benchmarks")] pub trait BenchmarkHelper { /// Returns an asset id from a given integer. fn asset_id(asset_id: u32) -> AssetId; } -#[cfg(any(test, feature = "runtime-benchmarks"))] +#[cfg(feature = "runtime-benchmarks")] impl BenchmarkHelper for () where AssetId: From, From 1c9f06490a616a3e568f55a52b055eebb161b041 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Sun, 4 Jun 2023 21:19:45 +0100 Subject: [PATCH 2/2] test needed in this case. --- frame/asset-conversion/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/asset-conversion/src/lib.rs b/frame/asset-conversion/src/lib.rs index 9d7a418f824a9..c1aeb5898da71 100644 --- a/frame/asset-conversion/src/lib.rs +++ b/frame/asset-conversion/src/lib.rs @@ -1084,7 +1084,7 @@ pub mod pallet { } /// Returns the next pool asset id for benchmark purposes only. - #[cfg(feature = "runtime-benchmarks")] + #[cfg(any(test, feature = "runtime-benchmarks"))] pub fn get_next_pool_asset_id() -> T::PoolAssetId { NextPoolAssetId::::get().unwrap_or(T::PoolAssetId::initial_value()) }