1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
3// This file is part of Polkadot.
45// Polkadot is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
910// Polkadot is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
1415// You should have received a copy of the GNU General Public License
16// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1718//! Relay chain runtime mock.
1920use frame::{
21 deps::{frame_support::weights::WeightMeter, sp_runtime::AccountId32},
22 prelude::*,
23 runtime::prelude::*,
24 traits::{IdentityLookup, ProcessMessage, ProcessMessageError},
25};
26use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};
27use xcm::latest::prelude::*;
2829mod xcm_config;
30pub use xcm_config::LocationToAccountId;
31use xcm_config::XcmConfig;
3233pub type AccountId = AccountId32;
34pub type Balance = u64;
3536parameter_types! {
37pub const BlockHashCount: u64 = 250;
38}
3940#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
41impl frame_system::Config for Runtime {
42type AccountId = AccountId;
43type Lookup = IdentityLookup<Self::AccountId>;
44type Block = Block;
45type AccountData = pallet_balances::AccountData<Balance>;
46}
4748#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
49impl pallet_balances::Config for Runtime {
50type AccountStore = System;
51}
5253type Block = frame_system::mocking::MockBlock<Runtime>;
5455parameter_types! {
56/// Amount of weight that can be spent per block to service messages.
57pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000);
58pub const MessageQueueHeapSize: u32 = 65_536;
59pub const MessageQueueMaxStale: u32 = 16;
60}
6162/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet.
63pub struct MessageProcessor;
64impl ProcessMessage for MessageProcessor {
65type Origin = AggregateMessageOrigin;
6667fn process_message(
68 message: &[u8],
69 origin: Self::Origin,
70 meter: &mut WeightMeter,
71 id: &mut [u8; 32],
72 ) -> Result<bool, ProcessMessageError> {
73let para = match origin {
74 AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
75 };
76 xcm_builder::ProcessXcmMessage::<
77 Junction,
78 xcm_executor::XcmExecutor<XcmConfig>,
79 RuntimeCall,
80 >::process_message(message, Junction::Parachain(para.into()), meter, id)
81 }
82}
8384impl pallet_message_queue::Config for Runtime {
85type RuntimeEvent = RuntimeEvent;
86type Size = u32;
87type HeapSize = MessageQueueHeapSize;
88type MaxStale = MessageQueueMaxStale;
89type ServiceWeight = MessageQueueServiceWeight;
90type MessageProcessor = MessageProcessor;
91type QueueChangeHandler = ();
92type QueuePausedQuery = ();
93type WeightInfo = ();
94type IdleMaxServiceWeight = MessageQueueServiceWeight;
95}
9697construct_runtime! {
98pub struct Runtime {
99 System: frame_system,
100 Balances: pallet_balances,
101 MessageQueue: pallet_message_queue,
102 XcmPallet: pallet_xcm,
103 }
104}