1234567891011121314151617#![allow(missing_docs)]1819use super::{Config, Pallet};20use frame_benchmarking::{benchmarks, account};21use frame_system::RawOrigin;22use crate::AssetMetadata;23use crate::Pallet as ForeignAssets;24use xcm::opaque::latest::Junction::Parachain;25use xcm::VersionedMultiLocation;26use frame_support::{27 traits::{Currency},28};29use sp_std::boxed::Box;3031benchmarks! {32 register_foreign_asset {33 let origin: RawOrigin<T::AccountId> = frame_system::RawOrigin::Root;34 let owner: T::AccountId = account("user", 0, 1);35 let location: VersionedMultiLocation = VersionedMultiLocation::from(Parachain(1000).into());36 let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{37 name: "name".into(),38 symbol: "symbol".into(),39 decimals: 18,40 minimal_balance: 1u32.into()41 };42 let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =43 4_000_000_000u32.into();44 balance = balance * balance;45 <T as Config>::Currency::make_free_balance_be(&owner,46 balance);47 }: {48 ForeignAssets::<T>::register_foreign_asset(origin.into(), owner, Box::new(location), Box::new(metadata))?49 }5051 update_foreign_asset {52 let origin: RawOrigin<T::AccountId> = frame_system::RawOrigin::Root;53 let owner: T::AccountId = account("user", 0, 1);54 let location: VersionedMultiLocation = VersionedMultiLocation::from(Parachain(2000).into());55 let metadata: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{56 name: "name".into(),57 symbol: "symbol".into(),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: "name2".into(),63 symbol: "symbol2".into(),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 ForeignAssets::<T>::register_foreign_asset(origin.clone().into(), owner, Box::new(location.clone()), Box::new(metadata))?;7273 }: {74 ForeignAssets::<T>::update_foreign_asset(origin.into(), 0, Box::new(location), Box::new(metadata2))?75 }76}