1234567891011121314151617#![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}