git.delta.rocks / unique-network / refs/commits / 900be63a359f

difftreelog

source

pallets/foreign-assets/src/benchmarking.rs3.0 KiBsourcehistory
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 frame_benchmarking::{account, benchmarks};20use frame_support::traits::Currency;21use frame_system::RawOrigin;22use sp_std::{boxed::Box, vec::Vec};23use staging_xcm::{opaque::latest::Junction::Parachain, v3::Junctions::X1, VersionedMultiLocation};2425use super::{Call, Config, Pallet};26use crate::AssetMetadata;2728fn bounded<T: TryFrom<Vec<u8>>>(slice: &[u8]) -> T {29	T::try_from(slice.to_vec())30		.map_err(|_| "slice doesn't fit")31		.unwrap()32}3334benchmarks! {35	register_foreign_asset {36		let owner: T::AccountId = account("user", 0, 1);37		let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(1000)));38		let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{39			name: bounded(b"name"),40			symbol: bounded(b"symbol"),41			decimals: 18,42			minimal_balance: 1u32.into()43		};44		let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =45		   4_000_000_000u32.into();46		balance = balance * balance;47		<T as Config>::Currency::make_free_balance_be(&owner,48			balance);49	}: _(RawOrigin::Root, owner, Box::new(location), Box::new(metadata))5051	update_foreign_asset {52		let owner: T::AccountId = account("user", 0, 1);53		let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(2000)));54		let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{55			name: bounded(b"name"),56			symbol: bounded(b"symbol"),57			decimals: 18,58			minimal_balance: 1u32.into()59		};60		let metadata2: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{61			name: bounded(b"name2"),62			symbol: bounded(b"symbol2"),63			decimals: 18,64			minimal_balance: 1u32.into()65		};66		let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =67		   4_000_000_000u32.into();68		balance = balance * balance;69		<T as Config>::Currency::make_free_balance_be(&owner, balance);70		Pallet::<T>::register_foreign_asset(RawOrigin::Root.into(), owner, Box::new(location.clone()), Box::new(metadata))?;71	}: _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2))72}