1use frame_support::{
20 construct_runtime, derive_impl, parameter_types,
21 traits::{Disabled, Everything, Nothing, ProcessMessage, ProcessMessageError},
22 weights::{Weight, WeightMeter},
23};
24
25use frame_system::EnsureRoot;
26use sp_core::ConstU32;
27use sp_runtime::{
28 generic,
29 traits::{BlakeTwo256, IdentifyAccount, Verify},
30 MultiAddress, MultiSignature,
31};
32
33use polkadot_parachain_primitives::primitives::Id as ParaId;
34use polkadot_runtime_parachains::{
35 configuration,
36 inclusion::{AggregateMessageOrigin, UmpQueueId},
37 origin, shared,
38};
39use xcm::latest::prelude::*;
40use xcm_builder::{
41 AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative,
42 ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, FixedRateOfFungible,
43 FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete,
44 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
45};
46use xcm_executor::{Config, XcmExecutor};
47
48pub type TxExtension = (frame_system::CheckNonZeroSender<Runtime>,);
49
50pub type BlockNumber = u64;
51pub type Address = MultiAddress<AccountId, ()>;
52pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
53pub type UncheckedExtrinsic =
54 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
55pub type Block = generic::Block<Header, UncheckedExtrinsic>;
56
57pub type Signature = MultiSignature;
58pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
59pub type Balance = u128;
60
61parameter_types! {
62 pub const BlockHashCount: u32 = 250;
63}
64
65#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
66impl frame_system::Config for Runtime {
67 type AccountId = AccountId;
68 type Lookup = sp_runtime::traits::AccountIdLookup<AccountId, ()>;
69 type Block = Block;
70 type AccountData = pallet_balances::AccountData<Balance>;
71}
72
73parameter_types! {
74 pub ExistentialDeposit: Balance = 1;
75}
76
77#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
78impl pallet_balances::Config for Runtime {
79 type Balance = Balance;
80 type ExistentialDeposit = ExistentialDeposit;
81 type AccountStore = System;
82}
83
84impl shared::Config for Runtime {
85 type DisabledValidators = ();
86}
87
88impl configuration::Config for Runtime {
89 type WeightInfo = configuration::TestWeightInfo;
90}
91
92parameter_types! {
93 pub const TokenLocation: Location = Here.into_location();
94 pub const ThisNetwork: NetworkId = NetworkId::ByGenesis([0; 32]);
95 pub const AnyNetwork: Option<NetworkId> = None;
96 pub UniversalLocation: InteriorLocation = ThisNetwork::get().into();
97}
98
99pub type SovereignAccountOf =
100 (ChildParachainConvertsVia<ParaId, AccountId>, AccountId32Aliases<ThisNetwork, AccountId>);
101
102pub type LocalAssetTransactor =
103 FungibleAdapter<Balances, IsConcrete<TokenLocation>, SovereignAccountOf, AccountId, ()>;
104
105type LocalOriginConverter = (
106 SovereignSignedViaLocation<SovereignAccountOf, RuntimeOrigin>,
107 ChildParachainAsNative<origin::Origin, RuntimeOrigin>,
108 SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
109 ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
110);
111
112parameter_types! {
113 pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000);
114 pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(TokenLocation::get()), 1, 1);
115 pub const MaxInstructions: u32 = u32::MAX;
116 pub const MaxAssetsIntoHolding: u32 = 64;
117}
118
119pub type XcmRouter = super::RelayChainXcmRouter;
120pub type Barrier = AllowUnpaidExecutionFrom<Everything>;
121
122pub struct XcmConfig;
123impl Config for XcmConfig {
124 type RuntimeCall = RuntimeCall;
125 type XcmSender = XcmRouter;
126 type XcmEventEmitter = ();
127 type AssetTransactor = LocalAssetTransactor;
128 type OriginConverter = LocalOriginConverter;
129 type IsReserve = ();
130 type IsTeleporter = ();
131 type UniversalLocation = UniversalLocation;
132 type Barrier = Barrier;
133 type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
134 type Trader = FixedRateOfFungible<KsmPerSecondPerByte, ()>;
135 type ResponseHandler = ();
136 type AssetTrap = ();
137 type AssetLocker = ();
138 type AssetExchanger = ();
139 type AssetClaims = ();
140 type SubscriptionService = ();
141 type PalletInstancesInfo = ();
142 type FeeManager = ();
143 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
144 type MessageExporter = ();
145 type UniversalAliases = Nothing;
146 type CallDispatcher = RuntimeCall;
147 type SafeCallFilter = Everything;
148 type Aliasers = Nothing;
149 type TransactionalProcessor = FrameTransactionalProcessor;
150 type HrmpNewChannelOpenRequestHandler = ();
151 type HrmpChannelAcceptedHandler = ();
152 type HrmpChannelClosingHandler = ();
153 type XcmRecorder = ();
154}
155
156pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>;
157
158impl pallet_xcm::Config for Runtime {
159 type RuntimeEvent = RuntimeEvent;
160 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
161 type XcmRouter = XcmRouter;
162 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
164 type XcmExecuteFilter = Nothing;
165 type XcmExecutor = XcmExecutor<XcmConfig>;
166 type XcmTeleportFilter = Everything;
167 type XcmReserveTransferFilter = Everything;
168 type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
169 type UniversalLocation = UniversalLocation;
170 type RuntimeOrigin = RuntimeOrigin;
171 type RuntimeCall = RuntimeCall;
172 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
173 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
174 type Currency = Balances;
175 type CurrencyMatcher = ();
176 type TrustedLockers = ();
177 type SovereignAccountOf = SovereignAccountOf;
178 type MaxLockers = ConstU32<8>;
179 type MaxRemoteLockConsumers = ConstU32<0>;
180 type RemoteLockConsumerIdentifier = ();
181 type WeightInfo = pallet_xcm::TestWeightInfo;
182 type AdminOrigin = EnsureRoot<AccountId>;
183 type AuthorizedAliasConsideration = Disabled;
184}
185
186impl origin::Config for Runtime {}
187
188parameter_types! {
189 pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000);
191 pub const MessageQueueHeapSize: u32 = 65_536;
192 pub const MessageQueueMaxStale: u32 = 16;
193}
194
195pub struct MessageProcessor;
197impl ProcessMessage for MessageProcessor {
198 type Origin = AggregateMessageOrigin;
199
200 fn process_message(
201 message: &[u8],
202 origin: Self::Origin,
203 meter: &mut WeightMeter,
204 id: &mut [u8; 32],
205 ) -> Result<bool, ProcessMessageError> {
206 let para = match origin {
207 AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
208 };
209 xcm_builder::ProcessXcmMessage::<
210 Junction,
211 xcm_executor::XcmExecutor<XcmConfig>,
212 RuntimeCall,
213 >::process_message(message, Junction::Parachain(para.into()), meter, id)
214 }
215}
216
217impl pallet_message_queue::Config for Runtime {
218 type RuntimeEvent = RuntimeEvent;
219 type Size = u32;
220 type HeapSize = MessageQueueHeapSize;
221 type MaxStale = MessageQueueMaxStale;
222 type ServiceWeight = MessageQueueServiceWeight;
223 type IdleMaxServiceWeight = ();
224 #[cfg(not(feature = "runtime-benchmarks"))]
225 type MessageProcessor = MessageProcessor;
226 #[cfg(feature = "runtime-benchmarks")]
227 type MessageProcessor =
228 pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
229 type QueueChangeHandler = ();
230 type QueuePausedQuery = ();
231 type WeightInfo = ();
232}
233
234construct_runtime!(
235 pub enum Runtime
236 {
237 System: frame_system,
238 Balances: pallet_balances,
239 ParasOrigin: origin,
240 XcmPallet: pallet_xcm,
241 MessageQueue: pallet_message_queue,
242 }
243);