Skip to content

Commit

Permalink
mock config fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofdeepanshu committed Oct 20, 2023
1 parent ac8d97e commit a4e2bd9
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 318 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions pallets/astar-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ serde = { workspace = true, optional = true }
# Substrate
frame-support = { workspace = true, default-features = false }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-std = { workspace = true }

# Polkadot / XCM
astar-primitives = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
xcm = { workspace = true }
Expand All @@ -31,7 +32,9 @@ frame-benchmarking = { workspace = true }
pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
pallet-xcm = { workspace = true }
paste = { workspace = true }
sp-core = { workspace = true }
sp-tracing = { workspace = true }

[features]
default = ["std"]
Expand All @@ -46,12 +49,23 @@ std = [
"xcm/std",
"sp-io/std",
"sp-runtime/std",
"sp-core/std",
"astar-primitives/std",
"scale-info/std",
"astar-primitives/std",
"pallet-balances/std",
"pallet-assets/std",
]

runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"astar-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]

try-runtime = ["frame-support/try-runtime"]
50 changes: 32 additions & 18 deletions pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,36 @@ use crate::{fungible::assets as xcm_assets_benchmark, mock::*};
use frame_benchmarking::BenchmarkError;
use frame_support::{
parameter_types,
traits::{ConstU32, Everything, Nothing},
traits::{AsEnsureOriginWithArg, ConstU32, Everything, Nothing},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSigned};
use parity_scale_codec::Compact;
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_std::borrow::Borrow;
use xcm::latest::prelude::*;
use xcm_builder::{AllowUnpaidExecutionFrom, ConvertedConcreteId, IsConcrete, MintLocation};
use xcm_executor::traits::JustTry;
use xcm_builder::{AllowUnpaidExecutionFrom, ConvertedConcreteId, MintLocation};
use xcm_executor::traits::{Convert, JustTry};

type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;

// For testing the pallet, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test
pub struct Test
where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
XcmAssetsBenchmark: xcm_assets_benchmark::{Pallet},
Assets : pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
System: frame_system,
Balances: pallet_balances,
XcmAssetsBenchmark: xcm_assets_benchmark,
Assets: pallet_assets,
}
);

Expand All @@ -56,13 +67,14 @@ impl frame_system::Config for Test {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type Hash = H256;
type Index = u64;
type Header = Header;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -90,10 +102,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
type HoldIdentifier = ();
}

parameter_types! {
Expand All @@ -103,7 +115,7 @@ parameter_types! {
pub const MetadataDepositBase: u64 = 10 * ExistentialDeposit::get();
pub const MetadataDepositPerByte: u64 = 1 * ExistentialDeposit::get();
pub const AssetAccountDeposit: u64 = 1 * ExistentialDeposit::get();
const AssetsStringLimit: u32 = 50;
pub const AssetsStringLimit: u32 = 50;

}

Expand All @@ -112,8 +124,8 @@ impl pallet_assets::Config for Test {
type Balance = u64;
type AssetId = u64;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type ForceOrigin = EnsureRoot<u64>;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
Expand All @@ -130,21 +142,24 @@ impl pallet_assets::Config for Test {
type BenchmarkHelper = ();
}

parameter_types! {
pub const DummyCheckingAccount : u64 = 0;
}
// Use fungible transactor as the asset transactor.
pub type AssetTransactor = xcm_builder::FungiblesAdapter<
Assets,
ConvertedConcreteId<u64, u64, AssetLocationIdConverter, JustTry>,
AccountIdConverter,
u64,
xcm_builder::NoChecking,
0,
DummyCheckingAccount,
>;

pub struct AssetLocationIdConverter;
impl Convert<MultiLocation, u64> for AssetLocationIdConverter {
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<u64, ()> {
if let X1(GeneralIndex(i)) = location.borrow().clone().interior {
Ok(i.into())
Ok(<u128 as TryInto<u64>>::try_into(i).map_err(|_| ())?)
} else {
Err(())
}
Expand Down Expand Up @@ -187,7 +202,6 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
}

impl crate::Config for Test {
Expand Down
28 changes: 18 additions & 10 deletions pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,35 @@
// Copyright (C) Parity Technologies (UK) Ltd.
//! A mock runtime for XCM benchmarking.
use crate::{fungible as xcm_balances_benchmark, mock::*};
use crate::{fungible::balances as xcm_balances_benchmark, mock::*};
use frame_benchmarking::BenchmarkError;
use frame_support::{
parameter_types,
traits::{ConstU32, Everything, Nothing},
weights::Weight,
};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use xcm::latest::prelude::*;
use xcm_builder::{AllowUnpaidExecutionFrom, MintLocation};

type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;

// For testing the pallet, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test
pub struct Test
where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
XcmBalancesBenchmark: xcm_balances_benchmark::{Pallet},
System: frame_system,
Balances: pallet_balances,
XcmBalancesBenchmark: xcm_balances_benchmark,
}
);

Expand All @@ -54,13 +62,14 @@ impl frame_system::Config for Test {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type Hash = H256;
type Index = u64;
type Header = Header;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -88,10 +97,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
type HoldIdentifier = ();
}

parameter_types! {
Expand Down Expand Up @@ -155,7 +164,6 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
}

impl crate::Config for Test {
Expand Down
Loading

0 comments on commit a4e2bd9

Please sign in to comment.