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
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
27
use sp_core::H256;
28
use sp_runtime::{
29
	traits::{ConstU32, Hash, IdentityLookup},
30
	AccountId32,
31
};
32

            
33
use polkadot_parachain::primitives::Id as ParaId;
34
use polkadot_parachain::primitives::Sibling;
35
use sp_std::convert::TryFrom;
36
use xcm::latest::prelude::*;
37
use xcm::VersionedXcm;
38
use xcm_builder::{
39
	AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
40
	AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex,
41
	ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungibleAdapter,
42
	FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset,
43
	RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
44
	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
45
};
46
use xcm_executor::{traits::JustTry, Config, XcmExecutor};
47
use xcm_simulator::{
48
	DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat,
49
	XcmpMessageHandlerT as XcmpMessageHandler,
50
};
51
pub type AccountId = AccountId32;
52
pub type Balance = u128;
53
pub type AssetId = u128;
54
pub type ReserveId = 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, ReserveIdParameter> pallet_assets::BenchmarkHelper<AssetIdParameter, ReserveIdParameter> for BenchmarkHelper
120
	where
121
		AssetIdParameter: From<u128>,
122
		ReserveIdParameter: From<u128>,
123
	{
124
		fn create_asset_id_parameter(id: u32) -> AssetIdParameter {
125
			(id as u128).into()
126
		}
127
		fn create_reserve_id_parameter(id: u32) -> ReserveIdParameter {
128
			(id as u128).into()
129
		}
130
	}
131
}
132

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

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

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

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

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

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

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

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

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

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

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

            
298
parameter_types! {
299
	pub MatcherLocation: Location = Location::here();
300
	pub const MaxAssetsIntoHolding: u32 = 64;
301
	pub const RelayTokenLocation: Location = Location::parent();
302
}
303

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

            
326
pub type TrustedTeleporters = (ConcreteAssetFromRelay<RelayTokenLocation>,);
327

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

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

            
365
pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>;
366

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

            
394
impl cumulus_pallet_xcm::Config for Runtime {
395
	type RuntimeEvent = RuntimeEvent;
396
	type XcmExecutor = XcmExecutor<XcmConfig>;
397
}
398

            
399
#[frame_support::pallet]
400
pub mod mock_msg_queue {
401
	use super::*;
402
	use frame_support::pallet_prelude::*;
403

            
404
	#[pallet::config]
405
	pub trait Config: frame_system::Config {
406
		type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
407
	}
408

            
409
	#[pallet::call]
410
	impl<T: Config> Pallet<T> {}
411

            
412
	#[pallet::pallet]
413
	pub struct Pallet<T>(_);
414

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

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

            
425
	pub type MessageId = [u8; 32];
426

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

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

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

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

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

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

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

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

            
559
// Pallet to cover test cases for change https://github.com/paritytech/cumulus/pull/831
560
#[frame_support::pallet]
561
pub mod mock_statemint_prefix {
562
	use super::*;
563
	use frame_support::pallet_prelude::*;
564

            
565
	#[pallet::config]
566
	pub trait Config: frame_system::Config {}
567

            
568
	#[pallet::call]
569
	impl<T: Config> Pallet<T> {}
570

            
571
	#[pallet::pallet]
572
	#[pallet::without_storage_info]
573
	pub struct Pallet<T>(_);
574

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

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

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

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

            
600
impl mock_statemint_prefix::Config for Runtime {}
601

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

            
613
	}
614
);