From 668380cf23dd788fe89cc6797f0f71e318b76af5 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 26 Aug 2024 17:43:59 +0200 Subject: [PATCH] fix pallet_xcm benchmarks --- runtime/basilisk/src/apis.rs | 44 +++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/runtime/basilisk/src/apis.rs b/runtime/basilisk/src/apis.rs index fab28eb729..bb3d110925 100644 --- a/runtime/basilisk/src/apis.rs +++ b/runtime/basilisk/src/apis.rs @@ -217,7 +217,6 @@ impl_runtime_apis! { ) -> Result, sp_runtime::RuntimeString> { use frame_benchmarking::{BenchmarkError, Benchmarking, BenchmarkBatch}; use frame_support::traits::TrackedStorageKey; - use sp_core::Get; use sp_std::sync::Arc; use primitives::constants::chain::CORE_ASSET_ID; @@ -241,19 +240,19 @@ impl_runtime_apis! { parameter_types! { pub const RandomParaId: ParaId = ParaId::new(22222222); pub const ExistentialDeposit: u128= 1_000_000_000_000; - pub AssetLocation: Location = Location::new(1, cumulus_primitives_core::Junctions::X2( - Arc::new([cumulus_primitives_core::Junction::Parachain(ParachainInfo::get().into()), + pub AssetLocation: Location = Location::new(0, cumulus_primitives_core::Junctions::X1( + Arc::new([ cumulus_primitives_core::Junction::GeneralIndex(CORE_ASSET_ID.into()) ]) )); } use cumulus_primitives_core::ParaId; - use polkadot_xcm::latest::prelude::{Location, AssetId, Fungible, Asset, ParentThen, Parachain, Parent}; + use polkadot_xcm::latest::prelude::{Location, AssetId, Fungible, Asset, Assets, ParentThen, Parachain, Parent}; impl pallet_xcm::benchmarking::Config for Runtime { - // TODO: type DeliveryHelper = (); + fn reachable_dest() -> Option { Some(Parent.into()) } @@ -276,7 +275,40 @@ impl_runtime_apis! { )) } - // TODO: + fn set_up_complex_asset_transfer() -> Option<(Assets, u32, Location, Box)> { + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests( + RandomParaId::get().into() + ); + + let destination = ParentThen(Parachain(RandomParaId::get().into()).into()).into(); + + let fee_asset: Asset = ( + AssetLocation::get(), + ExistentialDeposit::get(), + ).into(); + + let who = frame_benchmarking::whitelisted_caller(); + let balance = 10 * ExistentialDeposit::get(); + let _ = >::make_free_balance_be(&who, balance ); + + assert_eq!(Balances::free_balance(&who), balance); + + let transfer_asset: Asset = ( + AssetLocation::get(), + ExistentialDeposit::get(), + ).into(); + + let assets: Assets = vec![fee_asset.clone(), transfer_asset].into(); + + let fee_index: u32 = 0; + + let verify: Box = Box::new(move || { + assert!(Balances::free_balance(&who) <= balance - ExistentialDeposit::get()); + }); + + Some((assets, fee_index, destination, verify)) + } + fn get_asset() -> Asset { Asset { id: AssetId(Location::here()),