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::{ConstBool, 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
29
	fn contains(asset: &Asset, origin: &Location) -> bool {
312
29
		let is_relay = match origin.unpack() {
313
			// The Relay Chain
314
29
			(1, []) => true,
315
			// Others
316
14
			_ => false,
317
		};
318
29
		asset.id.0 == AssetLocation::get() && is_relay
319
29
	}
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
	type AssetHubMigrationStarted = ConstBool<false>;
389
}
390

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

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

            
401
	#[pallet::config]
402
	pub trait Config: frame_system::Config {
403
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
404
		type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
405
	}
406

            
407
	#[pallet::call]
408
	impl<T: Config> Pallet<T> {}
409

            
410
3
	#[pallet::pallet]
411
	pub struct Pallet<T>(_);
412

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

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

            
423
	pub type MessageId = [u8; 32];
424

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

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

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

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

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

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

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

            
542
5
						Self::deposit_event(Event::ExecutedDownward(id, outcome));
543
5
					}
544
				}
545
			}
546
5
			limit
547
5
		}
548
	}
549
}
550
impl mock_msg_queue::Config for Runtime {
551
	type RuntimeEvent = RuntimeEvent;
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
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
564
	}
565

            
566
	#[pallet::call]
567
	impl<T: Config> Pallet<T> {}
568

            
569
3
	#[pallet::pallet]
570
	#[pallet::without_storage_info]
571
	pub struct Pallet<T>(_);
572

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

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

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

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

            
598
impl mock_statemine_prefix::Config for Runtime {
599
	type RuntimeEvent = RuntimeEvent;
600
}
601

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

            
613
439
	}
614
439
);