1
// Copyright 2021 Parity Technologies (UK) Ltd.
2
// This file is part of Polkadot.
3

            
4
// Polkadot is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Polkadot is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! Relay chain runtime mock.
18

            
19
use frame_support::traits::Disabled;
20
use frame_support::{
21
	construct_runtime, parameter_types,
22
	traits::{AsEnsureOriginWithArg, Contains, ContainsPair, Everything, Get, Nothing},
23
	weights::Weight,
24
};
25
use frame_system::{EnsureRoot, EnsureSigned};
26

            
27
use sp_core::H256;
28
use sp_runtime::{
29
	traits::{ConstU32, Hash, IdentityLookup},
30
	AccountId32,
31
};
32

            
33
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
34

            
35
use polkadot_parachain::primitives::Id as ParaId;
36
use polkadot_parachain::primitives::Sibling;
37
use sp_std::convert::TryFrom;
38
use xcm::latest::prelude::*;
39
use xcm::VersionedXcm;
40
use xcm_builder::{
41
	AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
42
	AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex,
43
	ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungibleAdapter,
44
	FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset,
45
	RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
46
	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
47
};
48
use xcm_executor::{traits::JustTry, Config, XcmExecutor};
49
use xcm_simulator::{
50
	DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat,
51
	XcmpMessageHandlerT as XcmpMessageHandler,
52
};
53
pub type AccountId = AccountId32;
54
pub type Balance = u128;
55
pub type AssetId = u128;
56

            
57
parameter_types! {
58
	pub const BlockHashCount: u32 = 250;
59
}
60

            
61
impl frame_system::Config for Runtime {
62
	type RuntimeOrigin = RuntimeOrigin;
63
	type RuntimeCall = RuntimeCall;
64
	type RuntimeTask = RuntimeTask;
65
	type Nonce = u64;
66
	type Block = Block;
67
	type Hash = H256;
68
	type Hashing = ::sp_runtime::traits::BlakeTwo256;
69
	type AccountId = AccountId;
70
	type Lookup = IdentityLookup<Self::AccountId>;
71
	type RuntimeEvent = RuntimeEvent;
72
	type BlockHashCount = BlockHashCount;
73
	type BlockWeights = ();
74
	type BlockLength = ();
75
	type Version = ();
76
	type PalletInfo = PalletInfo;
77
	type AccountData = pallet_balances::AccountData<Balance>;
78
	type OnNewAccount = ();
79
	type OnKilledAccount = ();
80
	type DbWeight = ();
81
	type BaseCallFilter = Everything;
82
	type SystemWeightInfo = ();
83
	type SS58Prefix = ();
84
	type OnSetCode = ();
85
	type MaxConsumers = frame_support::traits::ConstU32<16>;
86
	type SingleBlockMigrations = ();
87
	type MultiBlockMigrator = ();
88
	type PreInherents = ();
89
	type PostInherents = ();
90
	type PostTransactions = ();
91
	type ExtensionsWeightInfo = ();
92
}
93

            
94
parameter_types! {
95
	pub ExistentialDeposit: Balance = 1;
96
	pub const MaxLocks: u32 = 50;
97
	pub const MaxReserves: u32 = 50;
98
}
99

            
100
impl pallet_balances::Config for Runtime {
101
	type MaxLocks = MaxLocks;
102
	type Balance = Balance;
103
	type RuntimeEvent = RuntimeEvent;
104
	type DustRemoval = ();
105
	type ExistentialDeposit = ExistentialDeposit;
106
	type AccountStore = System;
107
	type WeightInfo = ();
108
	type MaxReserves = MaxReserves;
109
	type ReserveIdentifier = [u8; 8];
110
	type RuntimeHoldReason = ();
111
	type FreezeIdentifier = ();
112
	type MaxFreezes = ();
113
	type RuntimeFreezeReason = ();
114
	type DoneSlashHandler = ();
115
}
116

            
117
// Required for runtime benchmarks
118
pallet_assets::runtime_benchmarks_enabled! {
119
	pub struct BenchmarkHelper;
120
	impl<AssetIdParameter> pallet_assets::BenchmarkHelper<AssetIdParameter> for BenchmarkHelper
121
	where
122
		AssetIdParameter: From<u128>,
123
	{
124
		fn create_asset_id_parameter(id: u32) -> AssetIdParameter {
125
			(id as u128).into()
126
		}
127
	}
128
}
129

            
130
parameter_types! {
131
	pub const AssetDeposit: Balance = 0; // 1 UNIT deposit to create asset
132
	pub const ApprovalDeposit: Balance = 0;
133
	pub const AssetsStringLimit: u32 = 50;
134
	/// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1)
135
	// https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271
136
	pub const MetadataDepositBase: Balance = 0;
137
	pub const MetadataDepositPerByte: Balance = 0;
138
	pub const ExecutiveBody: BodyId = BodyId::Executive;
139
	pub const AssetAccountDeposit: Balance = 0;
140
}
141

            
142
impl pallet_assets::Config for Runtime {
143
	type RuntimeEvent = RuntimeEvent;
144
	type Balance = Balance;
145
	type AssetId = AssetId;
146
	type Currency = Balances;
147
	type ForceOrigin = EnsureRoot<AccountId>;
148
	type AssetDeposit = AssetDeposit;
149
	type MetadataDepositBase = MetadataDepositBase;
150
	type MetadataDepositPerByte = MetadataDepositPerByte;
151
	type ApprovalDeposit = ApprovalDeposit;
152
	type StringLimit = AssetsStringLimit;
153
	type Freezer = ();
154
	type Extra = ();
155
	type AssetAccountDeposit = AssetAccountDeposit;
156
	type WeightInfo = ();
157
	type RemoveItemsLimit = ConstU32<656>;
158
	type AssetIdParameter = AssetId;
159
	type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
160
	type CallbackHandle = ();
161
	type Holder = ();
162
	pallet_assets::runtime_benchmarks_enabled! {
163
		type BenchmarkHelper = BenchmarkHelper;
164
	}
165
}
166

            
167
parameter_types! {
168
	pub const KsmLocation: Location = Location::parent();
169
	pub const RelayNetwork: NetworkId = NetworkId::Kusama;
170
	pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
171
	pub UniversalLocation: InteriorLocation =
172
		[GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into();
173
	pub Local: Location = Here.into();
174
	pub CheckingAccount: AccountId = PolkadotXcm::check_account();
175
	pub KsmPerSecond: (xcm::latest::prelude::AssetId, u128, u128) =
176
		(AssetId(KsmLocation::get()), 1, 1);
177
}
178

            
179
/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
180
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
181
/// `Transact` in order to determine the dispatch Origin.
182
pub type LocationToAccountId = (
183
	// The parent (Relay-chain) origin converts to the default `AccountId`.
184
	ParentIsPreset<AccountId>,
185
	// Sibling parachain origins convert to AccountId via the `ParaId::into`.
186
	SiblingParachainConvertsVia<Sibling, AccountId>,
187
	// Straight up local `AccountId32` origins just alias directly to `AccountId`.
188
	AccountId32Aliases<RelayNetwork, AccountId>,
189
);
190

            
191
/// Means for transacting the native currency on this chain.
192
pub type CurrencyTransactor = FungibleAdapter<
193
	// Use this currency:
194
	Balances,
195
	// Use this currency when it is a fungible asset matching the given location or name:
196
	IsConcrete<KsmLocation>,
197
	// Convert an XCM Location into a local account id:
198
	LocationToAccountId,
199
	// Our chain's account ID type (we can't get away without mentioning it explicitly):
200
	AccountId,
201
	// We don't track any teleports of `Balances`.
202
	(),
203
>;
204

            
205
/// Means for transacting assets besides the native currency on this chain.
206
pub type FungiblesTransactor = FungiblesAdapter<
207
	// Use this fungibles implementation:
208
	Assets,
209
	// Use this currency when it is a fungible asset matching the given location or name:
210
	ConvertedConcreteId<
211
		AssetId,
212
		Balance,
213
		AsPrefixedGeneralIndex<PrefixChanger, AssetId, JustTry>,
214
		JustTry,
215
	>,
216
	// Convert an XCM Location into a local account id:
217
	LocationToAccountId,
218
	// Our chain's account ID type (we can't get away without mentioning it explicitly):
219
	AccountId,
220
	// We only want to allow teleports of known assets. We use non-zero issuance as an indication
221
	// that this asset is known.
222
	NoChecking,
223
	// The account to use for tracking teleports.
224
	CheckingAccount,
225
>;
226
/// Means for transacting assets on this chain.
227
pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor);
228

            
229
/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
230
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
231
/// biases the kind of local `Origin` it will become.
232
pub type XcmOriginToTransactDispatchOrigin = (
233
	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
234
	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
235
	// foreign chains who want to have a local sovereign account on this chain which they control.
236
	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
237
	// Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when
238
	// recognised.
239
	RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
240
	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
241
	// recognised.
242
	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
243
	// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
244
	// transaction from the Root origin.
245
	ParentAsSuperuser<RuntimeOrigin>,
246
	// Native signed account converter; this just converts an `AccountId32` origin into a normal
247
	// `RuntimeOrigin::signed` origin of the same 32-byte value.
248
	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
249
	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
250
	pallet_xcm::XcmPassthrough<RuntimeOrigin>,
251
);
252

            
253
parameter_types! {
254
	// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
255
	pub UnitWeightCost: Weight = Weight::from_parts(100u64, 100u64);
256
	pub const MaxInstructions: u32 = 100;
257
}
258

            
259
pub struct ParentOrParentsExecutivePlurality;
260
impl Contains<Location> for ParentOrParentsExecutivePlurality {
261
	fn contains(location: &Location) -> bool {
262
		matches!(
263
			location.unpack(),
264
			(1, [])
265
				| (
266
					1,
267
					[Plurality {
268
						id: BodyId::Executive,
269
						..
270
					}]
271
				)
272
		)
273
	}
274
}
275

            
276
pub struct ParentOrSiblings;
277
impl Contains<Location> for ParentOrSiblings {
278
	fn contains(location: &Location) -> bool {
279
		matches!(location.unpack(), (1, []) | (1, [_]))
280
	}
281
}
282

            
283
pub type Barrier = (
284
	TakeWeightCredit,
285
	AllowTopLevelPaidExecutionFrom<Everything>,
286
	// Parent and its exec plurality get free execution
287
	AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
288
	// Expected responses are OK.
289
	AllowKnownQueryResponses<PolkadotXcm>,
290
	// Subscriptions for version tracking are OK.
291
	AllowSubscriptionsFrom<ParentOrSiblings>,
292
);
293

            
294
parameter_types! {
295
	pub MatcherLocation: Location = Location::here();
296
	pub const MaxAssetsIntoHolding: u32 = 64;
297
	pub const RelayTokenLocation: Location = Location::parent();
298
}
299

            
300
// Copied from:
301
//
302
// https://github.com/paritytech/polkadot-sdk/blob/f4eb41773611008040c9d4d8a8e6b7323eccfca1/cumulus
303
// /parachains/common/src/xcm_config.rs#L118
304
//
305
// The difference with the original "ConcreteAssetFromSystem" (which is used by AssetHub),
306
// is that in our tests we only need to check if the asset matches the relay one.
307
pub struct ConcreteAssetFromRelay<AssetLocation>(sp_std::marker::PhantomData<AssetLocation>);
308
impl<AssetLocation: Get<Location>> ContainsPair<Asset, Location>
309
	for ConcreteAssetFromRelay<AssetLocation>
310
{
311
5
	fn contains(asset: &Asset, origin: &Location) -> bool {
312
5
		let is_relay = match origin.unpack() {
313
			// The Relay Chain
314
5
			(1, []) => true,
315
			// Others
316
			_ => false,
317
		};
318
5
		asset.id.0 == AssetLocation::get() && is_relay
319
5
	}
320
}
321

            
322
pub type TrustedTeleporters = (ConcreteAssetFromRelay<RelayTokenLocation>,);
323

            
324
pub struct XcmConfig;
325
impl Config for XcmConfig {
326
	type RuntimeCall = RuntimeCall;
327
	type XcmSender = XcmRouter;
328
	type AssetTransactor = AssetTransactors;
329
	type OriginConverter = XcmOriginToTransactDispatchOrigin;
330
	type IsReserve = xcm_primitives::MultiNativeAsset<xcm_primitives::RelativeReserveProvider>;
331
	type IsTeleporter = TrustedTeleporters;
332
	type UniversalLocation = UniversalLocation;
333
	type Barrier = Barrier;
334
	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
335
	type Trader = FixedRateOfFungible<KsmPerSecond, ()>;
336
	type ResponseHandler = PolkadotXcm;
337
	type AssetTrap = PolkadotXcm;
338
	type AssetClaims = PolkadotXcm;
339
	type SubscriptionService = PolkadotXcm;
340
	type CallDispatcher = RuntimeCall;
341
	type AssetLocker = ();
342
	type AssetExchanger = ();
343
	type PalletInstancesInfo = ();
344
	type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
345
	type FeeManager = ();
346
	type MessageExporter = ();
347
	type UniversalAliases = Nothing;
348
	type SafeCallFilter = Everything;
349
	type Aliasers = Nothing;
350
	type TransactionalProcessor = ();
351
	type HrmpNewChannelOpenRequestHandler = ();
352
	type HrmpChannelAcceptedHandler = ();
353
	type HrmpChannelClosingHandler = ();
354
	type XcmRecorder = PolkadotXcm;
355
	type XcmEventEmitter = PolkadotXcm;
356
}
357

            
358
/// No local origins on this chain are allowed to dispatch XCM sends/executions.
359
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
360

            
361
pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>;
362

            
363
impl pallet_xcm::Config for Runtime {
364
	type RuntimeEvent = RuntimeEvent;
365
	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
366
	type XcmRouter = XcmRouter;
367
	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
368
	type XcmExecuteFilter = Nothing;
369
	type XcmExecutor = XcmExecutor<XcmConfig>;
370
	type XcmTeleportFilter = Everything;
371
	type XcmReserveTransferFilter = Everything;
372
	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
373
	type UniversalLocation = UniversalLocation;
374
	type RuntimeOrigin = RuntimeOrigin;
375
	type RuntimeCall = RuntimeCall;
376
	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
377
	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
378
	type Currency = Balances;
379
	type CurrencyMatcher = IsConcrete<MatcherLocation>;
380
	type TrustedLockers = ();
381
	type SovereignAccountOf = ();
382
	type MaxLockers = ConstU32<8>;
383
	type WeightInfo = pallet_xcm::TestWeightInfo;
384
	type MaxRemoteLockConsumers = ConstU32<0>;
385
	type RemoteLockConsumerIdentifier = ();
386
	type AdminOrigin = frame_system::EnsureRoot<AccountId>;
387
	type AuthorizedAliasConsideration = Disabled;
388
}
389

            
390
impl cumulus_pallet_xcm::Config for Runtime {
391
	type RuntimeEvent = RuntimeEvent;
392
	type XcmExecutor = XcmExecutor<XcmConfig>;
393
}
394

            
395
#[frame_support::pallet]
396
pub mod mock_msg_queue {
397
	use super::*;
398
	use frame_support::pallet_prelude::*;
399

            
400
	#[pallet::config]
401
	pub trait Config: frame_system::Config {
402
		type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
403
	}
404

            
405
	#[pallet::call]
406
	impl<T: Config> Pallet<T> {}
407

            
408
	#[pallet::pallet]
409
	pub struct Pallet<T>(_);
410

            
411
	#[pallet::storage]
412
	#[pallet::getter(fn parachain_id)]
413
	pub(super) type ParachainId<T: Config> = StorageValue<_, ParaId, ValueQuery>;
414

            
415
	impl<T: Config> Get<ParaId> for Pallet<T> {
416
14
		fn get() -> ParaId {
417
14
			Self::parachain_id()
418
14
		}
419
	}
420

            
421
	pub type MessageId = [u8; 32];
422

            
423
	#[pallet::event]
424
	#[pallet::generate_deposit(pub(super) fn deposit_event)]
425
	pub enum Event<T: Config> {
426
		// XCMP
427
		/// Some XCM was executed OK.
428
		Success(Option<T::Hash>),
429
		/// Some XCM failed.
430
		Fail(Option<T::Hash>, InstructionError),
431
		/// Bad XCM version used.
432
		BadVersion(Option<T::Hash>),
433
		/// Bad XCM format used.
434
		BadFormat(Option<T::Hash>),
435

            
436
		// DMP
437
		/// Downward message is invalid XCM.
438
		InvalidFormat(MessageId),
439
		/// Downward message is unsupported version of XCM.
440
		UnsupportedVersion(MessageId),
441
		/// Downward message executed with the given outcome.
442
		ExecutedDownward(MessageId, Outcome),
443
	}
444

            
445
	impl<T: Config> Pallet<T> {
446
82
		pub fn set_para_id(para_id: ParaId) {
447
82
			ParachainId::<T>::put(para_id);
448
82
		}
449

            
450
6
		fn handle_xcmp_message(
451
6
			sender: ParaId,
452
6
			_sent_at: RelayBlockNumber,
453
6
			xcm: VersionedXcm<T::RuntimeCall>,
454
6
			max_weight: Weight,
455
6
		) -> Result<Weight, InstructionError> {
456
6
			let hash = Encode::using_encoded(&xcm, T::Hashing::hash);
457
6
			let (result, event) = match Xcm::<T::RuntimeCall>::try_from(xcm) {
458
6
				Ok(xcm) => {
459
6
					let location = Location::new(1, [Parachain(sender.into())]);
460
6
					let mut id = [0u8; 32];
461
6
					id.copy_from_slice(hash.as_ref());
462
6
					match T::XcmExecutor::prepare_and_execute(
463
6
						location,
464
6
						xcm,
465
6
						&mut id,
466
6
						max_weight,
467
6
						Weight::zero(),
468
6
					) {
469
						Outcome::Error(error) => {
470
							(Err(error.clone()), Event::Fail(Some(hash), error))
471
						}
472
6
						Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))),
473
						// As far as the caller is concerned, this was dispatched without error, so
474
						// we just report the weight used.
475
						Outcome::Incomplete { used, error } => {
476
							(Ok(used), Event::Fail(Some(hash), error))
477
						}
478
					}
479
				}
480
				Err(()) => (
481
					Err(InstructionError {
482
						error: XcmError::UnhandledXcmVersion,
483
						index: 0,
484
					}),
485
					Event::BadVersion(Some(hash)),
486
				),
487
			};
488
6
			Self::deposit_event(event);
489
6
			result
490
6
		}
491
	}
492

            
493
	impl<T: Config> XcmpMessageHandler for Pallet<T> {
494
6
		fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
495
6
			iter: I,
496
6
			max_weight: Weight,
497
6
		) -> Weight {
498
12
			for (sender, sent_at, data) in iter {
499
6
				let mut data_ref = data;
500
6
				let _ = XcmpMessageFormat::decode(&mut data_ref)
501
6
					.expect("Simulator encodes with versioned xcm format; qed");
502

            
503
6
				let mut remaining_fragments = &data_ref[..];
504
12
				while !remaining_fragments.is_empty() {
505
6
					if let Ok(xcm) =
506
6
						VersionedXcm::<T::RuntimeCall>::decode(&mut remaining_fragments)
507
6
					{
508
6
						let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight);
509
6
					} else {
510
						debug_assert!(false, "Invalid incoming XCMP message data");
511
					}
512
				}
513
			}
514
6
			max_weight
515
6
		}
516
	}
517

            
518
	impl<T: Config> DmpMessageHandler for Pallet<T> {
519
5
		fn handle_dmp_messages(
520
5
			iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
521
5
			limit: Weight,
522
5
		) -> Weight {
523
5
			for (_i, (_sent_at, data)) in iter.enumerate() {
524
5
				let mut id = sp_io::hashing::blake2_256(&data[..]);
525
5
				let maybe_msg = VersionedXcm::<T::RuntimeCall>::decode(&mut &data[..])
526
5
					.map(Xcm::<T::RuntimeCall>::try_from);
527
5
				match maybe_msg {
528
					Err(_) => {
529
						Self::deposit_event(Event::InvalidFormat(id));
530
					}
531
					Ok(Err(())) => {
532
						Self::deposit_event(Event::UnsupportedVersion(id));
533
					}
534
5
					Ok(Ok(x)) => {
535
5
						let outcome = T::XcmExecutor::prepare_and_execute(
536
5
							Parent,
537
5
							x,
538
5
							&mut id,
539
5
							limit,
540
5
							Weight::zero(),
541
5
						);
542
5

            
543
5
						Self::deposit_event(Event::ExecutedDownward(id, outcome));
544
5
					}
545
				}
546
			}
547
5
			limit
548
5
		}
549
	}
550
}
551
impl mock_msg_queue::Config for Runtime {
552
	type XcmExecutor = XcmExecutor<XcmConfig>;
553
}
554

            
555
// Pallet to cover test cases for change https://github.com/paritytech/cumulus/pull/831
556
#[frame_support::pallet]
557
pub mod mock_statemine_prefix {
558
	use super::*;
559
	use frame_support::pallet_prelude::*;
560

            
561
	#[pallet::config]
562
	pub trait Config: frame_system::Config {}
563

            
564
	#[pallet::call]
565
	impl<T: Config> Pallet<T> {}
566

            
567
	#[pallet::pallet]
568
	#[pallet::without_storage_info]
569
	pub struct Pallet<T>(_);
570

            
571
	#[pallet::storage]
572
	#[pallet::getter(fn current_prefix)]
573
	pub(super) type CurrentPrefix<T: Config> = StorageValue<_, Location, ValueQuery>;
574

            
575
	impl<T: Config> Get<Location> for Pallet<T> {
576
15
		fn get() -> Location {
577
15
			Self::current_prefix()
578
15
		}
579
	}
580

            
581
	#[pallet::event]
582
	#[pallet::generate_deposit(pub(super) fn deposit_event)]
583
	pub enum Event<T: Config> {
584
		// Changed Prefix
585
		PrefixChanged(Location),
586
	}
587

            
588
	impl<T: Config> Pallet<T> {
589
4
		pub fn set_prefix(prefix: Location) {
590
4
			CurrentPrefix::<T>::put(&prefix);
591
4
			Self::deposit_event(Event::PrefixChanged(prefix));
592
4
		}
593
	}
594
}
595

            
596
impl mock_statemine_prefix::Config for Runtime {}
597

            
598
type Block = frame_system::mocking::MockBlockU32<Runtime>;
599
construct_runtime!(
600
	pub enum Runtime	{
601
		System: frame_system,
602
		Balances: pallet_balances,
603
		PolkadotXcm: pallet_xcm,
604
		CumulusXcm: cumulus_pallet_xcm,
605
		MsgQueue: mock_msg_queue,
606
		Assets: pallet_assets,
607
		PrefixChanger: mock_statemine_prefix,
608

            
609
	}
610
);