git.delta.rocks / unique-network / refs/commits / 59156c4c0e62

difftreelog

feat(foreign-asset) enable PoV benchmarking

Yaroslav Bolyukin2023-03-24parent: #583a28b.patch.diff
in: master

2 files changed

modifiedpallets/foreign-assets/src/benchmarking.rsdiffbeforeafterboth
before · pallets/foreign-assets/src/benchmarking.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(missing_docs)]1819use super::{Config, Pallet, Call};20use frame_benchmarking::{benchmarks, account};21use frame_system::RawOrigin;22use crate::AssetMetadata;23use xcm::opaque::latest::Junction::Parachain;24use xcm::VersionedMultiLocation;25use xcm::v3::Junctions::X1;26use frame_support::traits::Currency;27use sp_std::boxed::Box;2829benchmarks! {30	register_foreign_asset {31		let owner: T::AccountId = account("user", 0, 1);32		let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(1000)));33		let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{34			name: "name".into(),35			symbol: "symbol".into(),36			decimals: 18,37			minimal_balance: 1u32.into()38		};39		let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =40		   4_000_000_000u32.into();41		balance = balance * balance;42		<T as Config>::Currency::make_free_balance_be(&owner,43			balance);44	}: _(RawOrigin::Root, owner, Box::new(location), Box::new(metadata))4546	update_foreign_asset {47		let owner: T::AccountId = account("user", 0, 1);48		let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(2000)));49		let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{50			name: "name".into(),51			symbol: "symbol".into(),52			decimals: 18,53			minimal_balance: 1u32.into()54		};55		let metadata2: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{56			name: "name2".into(),57			symbol: "symbol2".into(),58			decimals: 18,59			minimal_balance: 1u32.into()60		};61		let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =62		   4_000_000_000u32.into();63		balance = balance * balance;64		<T as Config>::Currency::make_free_balance_be(&owner, balance);65		Pallet::<T>::register_foreign_asset(RawOrigin::Root.into(), owner, Box::new(location.clone()), Box::new(metadata))?;66	}: _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2))67}
after · pallets/foreign-assets/src/benchmarking.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(missing_docs)]1819use super::{Config, Pallet, Call};20use frame_benchmarking::{benchmarks, account};21use frame_system::RawOrigin;22use crate::AssetMetadata;23use xcm::opaque::latest::Junction::Parachain;24use xcm::VersionedMultiLocation;25use xcm::v3::Junctions::X1;26use frame_support::traits::Currency;27use sp_std::{vec::Vec, boxed::Box};2829fn bounded<T: TryFrom<Vec<u8>>>(slice: &[u8]) -> T {30	T::try_from(slice.to_vec())31		.map_err(|_| "slice doesn't fit")32		.unwrap()33}3435benchmarks! {36	register_foreign_asset {37		let owner: T::AccountId = account("user", 0, 1);38		let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(1000)));39		let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{40			name: bounded(b"name"),41			symbol: bounded(b"symbol"),42			decimals: 18,43			minimal_balance: 1u32.into()44		};45		let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =46		   4_000_000_000u32.into();47		balance = balance * balance;48		<T as Config>::Currency::make_free_balance_be(&owner,49			balance);50	}: _(RawOrigin::Root, owner, Box::new(location), Box::new(metadata))5152	update_foreign_asset {53		let owner: T::AccountId = account("user", 0, 1);54		let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(2000)));55		let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{56			name: bounded(b"name"),57			symbol: bounded(b"symbol"),58			decimals: 18,59			minimal_balance: 1u32.into()60		};61		let metadata2: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{62			name: bounded(b"name2"),63			symbol: bounded(b"symbol2"),64			decimals: 18,65			minimal_balance: 1u32.into()66		};67		let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =68		   4_000_000_000u32.into();69		balance = balance * balance;70		<T as Config>::Currency::make_free_balance_be(&owner, balance);71		Pallet::<T>::register_foreign_asset(RawOrigin::Root.into(), owner, Box::new(location.clone()), Box::new(metadata))?;72	}: _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2))73}
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -190,10 +190,13 @@
 		type WeightInfo: WeightInfo;
 	}
 
-	#[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, TypeInfo)]
+	pub type AssetName = BoundedVec<u8, ConstU32<32>>;
+	pub type AssetSymbol = BoundedVec<u8, ConstU32<7>>;
+
+	#[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
 	pub struct AssetMetadata<Balance> {
-		pub name: Vec<u8>,
-		pub symbol: Vec<u8>,
+		pub name: AssetName,
+		pub symbol: AssetSymbol,
 		pub decimals: u8,
 		pub minimal_balance: Balance,
 	}