diff --git a/pallets/foreign-asset-creator/src/benchmarks.rs b/pallets/foreign-asset-creator/src/benchmarks.rs index a8cd473..7bad7f5 100644 --- a/pallets/foreign-asset-creator/src/benchmarks.rs +++ b/pallets/foreign-asset-creator/src/benchmarks.rs @@ -16,11 +16,55 @@ #![cfg(feature = "runtime-benchmarks")] -use crate::{AssetId, Call, Config, Pallet}; -use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; +use crate::{AssetBalance, AssetId, Call, Config, Pallet}; +use frame_benchmarking::{ + account, benchmarks, impl_benchmark_test_suite, whitelisted_caller, BenchmarkError, +}; +use frame_support::traits::{fungibles, fungibles::Mutate, EnsureOrigin}; use frame_system::RawOrigin; use sp_arithmetic::traits::AtLeast16BitUnsigned; use staging_xcm::latest::prelude::*; + +#[allow(dead_code)] +pub fn create_default_minted_asset( + amount: AssetBalance, + receiver: T::AccountId, +) -> (AssetId, T::ForeignAsset) +where + T::ForeignAsset: From, + T::Fungibles: fungibles::Mutate, + AssetId: AtLeast16BitUnsigned, +{ + let (asset_id, foreign_asset) = create_default_asset::(true); + + assert!(T::Fungibles::mint_into(asset_id.clone(), &receiver, amount).is_ok()); + (asset_id, foreign_asset) +} + +#[allow(dead_code)] +fn create_default_asset(is_sufficient: bool) -> (AssetId, T::ForeignAsset) +where + T::ForeignAsset: From, + AssetId: AtLeast16BitUnsigned, +{ + let asset_id: AssetId = 1u16.into(); + let foreign_asset: T::ForeignAsset = Location::parent().into(); + let admin: T::AccountId = whitelisted_caller(); + let origin = T::ForeignAssetCreatorOrigin::try_successful_origin() + .map_err(|_| BenchmarkError::Weightless) + .expect("Not able to generate an appropriate origin to disptach the call"); + assert!(Pallet::::create_foreign_asset( + origin, + foreign_asset.clone(), + asset_id.clone(), + admin, + is_sufficient, + 1u32.into(), + ) + .is_ok()); + (asset_id, foreign_asset) +} + benchmarks! { // This where clause allows us to create ForeignAssetTypes where_clause { where T::ForeignAsset: From, AssetId: AtLeast16BitUnsigned } diff --git a/pallets/foreign-asset-creator/src/lib.rs b/pallets/foreign-asset-creator/src/lib.rs index af6e89d..a60638a 100644 --- a/pallets/foreign-asset-creator/src/lib.rs +++ b/pallets/foreign-asset-creator/src/lib.rs @@ -21,7 +21,7 @@ pub use pallet::*; pub mod weights; pub use weights::WeightInfo; #[cfg(any(test, feature = "runtime-benchmarks"))] -mod benchmarks; +pub mod benchmarks; #[cfg(test)] pub mod mock; #[cfg(test)]