From 9344aea5040213bf56a80ac2f75e28e45ae7db67 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:26:35 +0100 Subject: [PATCH] Fix weight generation for pallet-asset-manager (#3078) --- pallets/asset-manager/src/benchmarks.rs | 66 ++++++++++--------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/pallets/asset-manager/src/benchmarks.rs b/pallets/asset-manager/src/benchmarks.rs index e4c1ec26d7..27cb259d75 100644 --- a/pallets/asset-manager/src/benchmarks.rs +++ b/pallets/asset-manager/src/benchmarks.rs @@ -37,54 +37,42 @@ benchmarks! { } change_existing_asset_type { - let x in 5..100; - for i in 0..x { - let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into(); - let metadata = T::AssetRegistrarMetadata::default(); - let amount = 1u32.into(); - Pallet::::register_foreign_asset( - RawOrigin::Root.into(), - asset_type.clone(), - metadata, - amount, - true - )?; - } + let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(1 as u128))).into(); + let metadata = T::AssetRegistrarMetadata::default(); + let amount = 1u32.into(); + Pallet::::register_foreign_asset( + RawOrigin::Root.into(), + asset_type.clone(), + metadata, + amount, + true + )?; let new_asset_type = T::ForeignAssetType::default(); - let asset_type_to_be_changed: T::ForeignAssetType = Location::new( - 0, - X1(GeneralIndex((x-1) as u128)) - ).into(); - let asset_id_to_be_changed = asset_type_to_be_changed.into(); - }: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), x) + let asset_id_to_be_changed = asset_type.clone().into(); + }: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), 1) verify { assert_eq!(Pallet::::asset_id_type(asset_id_to_be_changed), Some(new_asset_type.clone())); + assert_eq!(Pallet::::asset_type_id(new_asset_type.clone()), Some(asset_id_to_be_changed)); + assert!(Pallet::::asset_type_id(asset_type).is_none()); } remove_existing_asset_type { - let x in 5..100; - for i in 0..x { - let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into(); - let metadata = T::AssetRegistrarMetadata::default(); - let amount = 1u32.into(); - Pallet::::register_foreign_asset( - RawOrigin::Root.into(), - asset_type.clone(), - metadata, - amount, - true - )?; - } - - let asset_type_to_be_removed: T::ForeignAssetType = Location::new( - 0, - X1(GeneralIndex((x-1) as u128)) - ).into(); - let asset_id: T::AssetId = asset_type_to_be_removed.clone().into(); - }: _(RawOrigin::Root, asset_id, x) + let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(1 as u128))).into(); + let metadata = T::AssetRegistrarMetadata::default(); + let amount = 1u32.into(); + Pallet::::register_foreign_asset( + RawOrigin::Root.into(), + asset_type.clone(), + metadata, + amount, + true + )?; + let asset_id: T::AssetId = asset_type.clone().into(); + }: _(RawOrigin::Root, asset_id, 1) verify { assert!(Pallet::::asset_id_type(asset_id).is_none()); + assert!(Pallet::::asset_type_id(asset_type).is_none()); } }