pallet_contracts_mock_network/
relay_chain.rs1use frame_support::{
20 construct_runtime, derive_impl, parameter_types,
21 traits::{Contains, Disabled, Everything, Nothing},
22 weights::Weight,
23};
24
25use frame_system::EnsureRoot;
26use sp_core::{ConstU32, H256};
27use sp_runtime::traits::IdentityLookup;
28
29use polkadot_parachain_primitives::primitives::Id as ParaId;
30use polkadot_runtime_parachains::{configuration, origin, shared};
31use xcm::latest::prelude::*;
32use xcm_builder::{
33 AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowSubscriptionsFrom,
34 AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia,
35 ChildSystemParachainAsSuperuser, DescribeAllTerminal, DescribeFamily, FixedRateOfFungible,
36 FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete,
37 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, WithComputedOrigin,
38};
39use xcm_executor::{Config, XcmExecutor};
40
41use super::{
42 mocks::relay_message_queue::*,
43 primitives::{AccountId, Balance},
44};
45
46#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
47impl frame_system::Config for Runtime {
48 type RuntimeOrigin = RuntimeOrigin;
49 type RuntimeCall = RuntimeCall;
50 type Block = Block;
51 type Nonce = u64;
52 type Hash = H256;
53 type Hashing = ::sp_runtime::traits::BlakeTwo256;
54 type AccountId = AccountId;
55 type Lookup = IdentityLookup<Self::AccountId>;
56 type RuntimeEvent = RuntimeEvent;
57 type BlockWeights = ();
58 type BlockLength = ();
59 type Version = ();
60 type PalletInfo = PalletInfo;
61 type AccountData = pallet_balances::AccountData<Balance>;
62 type OnNewAccount = ();
63 type OnKilledAccount = ();
64 type DbWeight = ();
65 type BaseCallFilter = Everything;
66 type SystemWeightInfo = ();
67 type SS58Prefix = ();
68 type OnSetCode = ();
69 type MaxConsumers = ConstU32<16>;
70}
71
72parameter_types! {
73 pub ExistentialDeposit: Balance = 1;
74 pub const MaxLocks: u32 = 50;
75 pub const MaxReserves: u32 = 50;
76}
77
78impl pallet_balances::Config for Runtime {
79 type MaxLocks = MaxLocks;
80 type Balance = Balance;
81 type RuntimeEvent = RuntimeEvent;
82 type DustRemoval = ();
83 type ExistentialDeposit = ExistentialDeposit;
84 type AccountStore = System;
85 type WeightInfo = ();
86 type MaxReserves = MaxReserves;
87 type ReserveIdentifier = [u8; 8];
88 type RuntimeHoldReason = RuntimeHoldReason;
89 type RuntimeFreezeReason = RuntimeFreezeReason;
90 type DoneSlashHandler = ();
91}
92
93impl shared::Config for Runtime {
94 type DisabledValidators = ();
95}
96
97impl configuration::Config for Runtime {
98 type WeightInfo = configuration::TestWeightInfo;
99}
100
101parameter_types! {
102 pub RelayNetwork: NetworkId = ByGenesis([0; 32]);
103 pub const TokenLocation: Location = Here.into_location();
104 pub UniversalLocation: InteriorLocation = RelayNetwork::get().into();
105 pub UnitWeightCost: u64 = 1_000;
106}
107
108pub type SovereignAccountOf = (
109 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
110 AccountId32Aliases<RelayNetwork, AccountId>,
111 ChildParachainConvertsVia<ParaId, AccountId>,
112);
113
114pub type LocalBalancesTransactor =
115 FungibleAdapter<Balances, IsConcrete<TokenLocation>, SovereignAccountOf, AccountId, ()>;
116
117pub type AssetTransactors = LocalBalancesTransactor;
118
119type LocalOriginConverter = (
120 SovereignSignedViaLocation<SovereignAccountOf, RuntimeOrigin>,
121 ChildParachainAsNative<origin::Origin, RuntimeOrigin>,
122 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
123 ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
124);
125
126parameter_types! {
127 pub const XcmInstructionWeight: Weight = Weight::from_parts(1_000, 1_000);
128 pub TokensPerSecondPerMegabyte: (AssetId, u128, u128) =
129 (AssetId(TokenLocation::get()), 1_000_000_000_000, 1024 * 1024);
130 pub const MaxInstructions: u32 = 100;
131 pub const MaxAssetsIntoHolding: u32 = 64;
132}
133
134pub struct ChildrenParachains;
135impl Contains<Location> for ChildrenParachains {
136 fn contains(location: &Location) -> bool {
137 matches!(location.unpack(), (0, [Parachain(_)]))
138 }
139}
140
141pub type XcmRouter = crate::RelayChainXcmRouter;
142pub type Barrier = WithComputedOrigin<
143 (
144 AllowExplicitUnpaidExecutionFrom<ChildrenParachains>,
145 AllowTopLevelPaidExecutionFrom<Everything>,
146 AllowSubscriptionsFrom<Everything>,
147 ),
148 UniversalLocation,
149 ConstU32<1>,
150>;
151
152pub struct XcmConfig;
153impl Config for XcmConfig {
154 type RuntimeCall = RuntimeCall;
155 type XcmSender = XcmRouter;
156 type XcmEventEmitter = XcmPallet;
157 type AssetTransactor = AssetTransactors;
158 type OriginConverter = LocalOriginConverter;
159 type IsReserve = ();
160 type IsTeleporter = ();
161 type UniversalLocation = UniversalLocation;
162 type Barrier = Barrier;
163 type Weigher = FixedWeightBounds<XcmInstructionWeight, RuntimeCall, MaxInstructions>;
164 type Trader = FixedRateOfFungible<TokensPerSecondPerMegabyte, ()>;
165 type ResponseHandler = XcmPallet;
166 type AssetTrap = XcmPallet;
167 type AssetLocker = XcmPallet;
168 type AssetExchanger = ();
169 type SubscriptionService = XcmPallet;
170 type PalletInstancesInfo = AllPalletsWithSystem;
171 type FeeManager = ();
172 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
173 type MessageExporter = ();
174 type UniversalAliases = Nothing;
175 type CallDispatcher = RuntimeCall;
176 type SafeCallFilter = Everything;
177 type Aliasers = Nothing;
178 type TransactionalProcessor = FrameTransactionalProcessor;
179 type HrmpNewChannelOpenRequestHandler = ();
180 type HrmpChannelAcceptedHandler = ();
181 type HrmpChannelClosingHandler = ();
182 type XcmRecorder = XcmPallet;
183}
184
185pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
186
187impl pallet_xcm::Config for Runtime {
188 type RuntimeEvent = RuntimeEvent;
189 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
190 type XcmRouter = XcmRouter;
191 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
192 type XcmExecuteFilter = Everything;
193 type XcmExecutor = XcmExecutor<XcmConfig>;
194 type XcmTeleportFilter = Everything;
195 type XcmReserveTransferFilter = Everything;
196 type Weigher = FixedWeightBounds<XcmInstructionWeight, RuntimeCall, MaxInstructions>;
197 type UniversalLocation = UniversalLocation;
198 type RuntimeOrigin = RuntimeOrigin;
199 type RuntimeCall = RuntimeCall;
200 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
201 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
202 type Currency = Balances;
203 type CurrencyMatcher = IsConcrete<TokenLocation>;
204 type TrustedLockers = ();
205 type SovereignAccountOf = SovereignAccountOf;
206 type MaxLockers = ConstU32<8>;
207 type MaxRemoteLockConsumers = ConstU32<0>;
208 type RemoteLockConsumerIdentifier = ();
209 type WeightInfo = pallet_xcm::TestWeightInfo;
210 type AdminOrigin = EnsureRoot<AccountId>;
211 type AuthorizedAliasConsideration = Disabled;
213}
214
215impl origin::Config for Runtime {}
216
217type Block = frame_system::mocking::MockBlock<Runtime>;
218
219impl pallet_message_queue::Config for Runtime {
220 type RuntimeEvent = RuntimeEvent;
221 type Size = u32;
222 type HeapSize = MessageQueueHeapSize;
223 type MaxStale = MessageQueueMaxStale;
224 type ServiceWeight = MessageQueueServiceWeight;
225 type IdleMaxServiceWeight = ();
226 type MessageProcessor = MessageProcessor;
227 type QueueChangeHandler = ();
228 type WeightInfo = ();
229 type QueuePausedQuery = ();
230}
231
232construct_runtime!(
233 pub enum Runtime {
234 System: frame_system,
235 Balances: pallet_balances,
236 ParasOrigin: origin,
237 XcmPallet: pallet_xcm,
238 MessageQueue: pallet_message_queue,
239 }
240);