Skip to content

Commit

Permalink
add default created asset
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed Apr 24, 2024
1 parent 47ac46f commit b7d3194
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions pallets/foreign-asset-creator/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config>(
amount: AssetBalance<T>,
receiver: T::AccountId,
) -> (AssetId<T>, T::ForeignAsset)
where
T::ForeignAsset: From<Location>,
T::Fungibles: fungibles::Mutate<T::AccountId>,
AssetId<T>: AtLeast16BitUnsigned,
{
let (asset_id, foreign_asset) = create_default_asset::<T>(true);

assert!(T::Fungibles::mint_into(asset_id.clone(), &receiver, amount).is_ok());
(asset_id, foreign_asset)
}

#[allow(dead_code)]
fn create_default_asset<T: Config>(is_sufficient: bool) -> (AssetId<T>, T::ForeignAsset)
where
T::ForeignAsset: From<Location>,
AssetId<T>: AtLeast16BitUnsigned,
{
let asset_id: AssetId<T> = 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)
.unwrap();
assert!(Pallet::<T>::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<Location>, AssetId<T>: AtLeast16BitUnsigned }
Expand Down

0 comments on commit b7d3194

Please sign in to comment.