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::{
20
	construct_runtime, parameter_types,
21
	traits::{AsEnsureOriginWithArg, Contains, ContainsPair, Everything, Get, Nothing},
22
	weights::Weight,
23
};
24
use frame_system::{EnsureRoot, EnsureSigned};
25

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

            
32
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
33

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
320
pub type TrustedTeleporters = (ConcreteAssetFromRelay<RelayTokenLocation>,);
321

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

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

            
358
pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>;
359

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

            
386
impl cumulus_pallet_xcm::Config for Runtime {
387
	type RuntimeEvent = RuntimeEvent;
388
	type XcmExecutor = XcmExecutor<XcmConfig>;
389
}
390

            
391
#[frame_support::pallet]
392
pub mod mock_msg_queue {
393
	use super::*;
394
	use frame_support::pallet_prelude::*;
395

            
396
	#[pallet::config]
397
	pub trait Config: frame_system::Config {
398
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
399
		type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
400
	}
401

            
402
	#[pallet::call]
403
	impl<T: Config> Pallet<T> {}
404

            
405
1
	#[pallet::pallet]
406
	pub struct Pallet<T>(_);
407

            
408
282
	#[pallet::storage]
409
	#[pallet::getter(fn parachain_id)]
410
	pub(super) type ParachainId<T: Config> = StorageValue<_, ParaId, ValueQuery>;
411

            
412
	impl<T: Config> Get<ParaId> for Pallet<T> {
413
14
		fn get() -> ParaId {
414
14
			Self::parachain_id()
415
14
		}
416
	}
417

            
418
	pub type MessageId = [u8; 32];
419

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

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

            
442
	impl<T: Config> Pallet<T> {
443
78
		pub fn set_para_id(para_id: ParaId) {
444
78
			ParachainId::<T>::put(para_id);
445
78
		}
446

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

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

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

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

            
537
5
						Self::deposit_event(Event::ExecutedDownward(id, outcome));
538
5
					}
539
				}
540
			}
541
5
			limit
542
5
		}
543
	}
544
}
545
impl mock_msg_queue::Config for Runtime {
546
	type RuntimeEvent = RuntimeEvent;
547
	type XcmExecutor = XcmExecutor<XcmConfig>;
548
}
549

            
550
// Pallet to cover test cases for change https://github.com/paritytech/cumulus/pull/831
551
#[frame_support::pallet]
552
pub mod mock_statemint_prefix {
553
	use super::*;
554
	use frame_support::pallet_prelude::*;
555

            
556
	#[pallet::config]
557
	pub trait Config: frame_system::Config {
558
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
559
	}
560

            
561
	#[pallet::call]
562
	impl<T: Config> Pallet<T> {}
563

            
564
1
	#[pallet::pallet]
565
	#[pallet::without_storage_info]
566
	pub struct Pallet<T>(_);
567

            
568
53
	#[pallet::storage]
569
	#[pallet::getter(fn current_prefix)]
570
	pub(super) type CurrentPrefix<T: Config> = StorageValue<_, Location, ValueQuery>;
571

            
572
	impl<T: Config> Get<Location> for Pallet<T> {
573
15
		fn get() -> Location {
574
15
			Self::current_prefix()
575
15
		}
576
	}
577

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

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

            
593
impl mock_statemint_prefix::Config for Runtime {
594
	type RuntimeEvent = RuntimeEvent;
595
}
596

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

            
608
427
	}
609
3019
);