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 FreezeIdentifier = ();
89 type MaxFreezes = ConstU32<0>;
90 type RuntimeHoldReason = RuntimeHoldReason;
91 type RuntimeFreezeReason = RuntimeFreezeReason;
92 type DoneSlashHandler = ();
93}
94
95impl shared::Config for Runtime {
96 type DisabledValidators = ();
97}
98
99impl configuration::Config for Runtime {
100 type WeightInfo = configuration::TestWeightInfo;
101}
102
103parameter_types! {
104 pub RelayNetwork: NetworkId = ByGenesis([0; 32]);
105 pub const TokenLocation: Location = Here.into_location();
106 pub UniversalLocation: InteriorLocation = RelayNetwork::get().into();
107 pub UnitWeightCost: u64 = 1_000;
108}
109
110pub type SovereignAccountOf = (
111 HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
112 AccountId32Aliases<RelayNetwork, AccountId>,
113 ChildParachainConvertsVia<ParaId, AccountId>,
114);
115
116pub type LocalBalancesTransactor =
117 FungibleAdapter<Balances, IsConcrete<TokenLocation>, SovereignAccountOf, AccountId, ()>;
118
119pub type AssetTransactors = LocalBalancesTransactor;
120
121type LocalOriginConverter = (
122 SovereignSignedViaLocation<SovereignAccountOf, RuntimeOrigin>,
123 ChildParachainAsNative<origin::Origin, RuntimeOrigin>,
124 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
125 ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
126);
127
128parameter_types! {
129 pub const XcmInstructionWeight: Weight = Weight::from_parts(1_000, 1_000);
130 pub TokensPerSecondPerMegabyte: (AssetId, u128, u128) =
131 (AssetId(TokenLocation::get()), 1_000_000_000_000, 1024 * 1024);
132 pub const MaxInstructions: u32 = 100;
133 pub const MaxAssetsIntoHolding: u32 = 64;
134}
135
136pub struct ChildrenParachains;
137impl Contains<Location> for ChildrenParachains {
138 fn contains(location: &Location) -> bool {
139 matches!(location.unpack(), (0, [Parachain(_)]))
140 }
141}
142
143pub type XcmRouter = crate::RelayChainXcmRouter;
144pub type Barrier = WithComputedOrigin<
145 (
146 AllowExplicitUnpaidExecutionFrom<ChildrenParachains>,
147 AllowTopLevelPaidExecutionFrom<Everything>,
148 AllowSubscriptionsFrom<Everything>,
149 ),
150 UniversalLocation,
151 ConstU32<1>,
152>;
153
154pub struct XcmConfig;
155impl Config for XcmConfig {
156 type RuntimeCall = RuntimeCall;
157 type XcmSender = XcmRouter;
158 type XcmEventEmitter = XcmPallet;
159 type AssetTransactor = AssetTransactors;
160 type OriginConverter = LocalOriginConverter;
161 type IsReserve = ();
162 type IsTeleporter = ();
163 type UniversalLocation = UniversalLocation;
164 type Barrier = Barrier;
165 type Weigher = FixedWeightBounds<XcmInstructionWeight, RuntimeCall, MaxInstructions>;
166 type Trader = FixedRateOfFungible<TokensPerSecondPerMegabyte, ()>;
167 type ResponseHandler = XcmPallet;
168 type AssetTrap = XcmPallet;
169 type AssetLocker = XcmPallet;
170 type AssetExchanger = ();
171 type AssetClaims = XcmPallet;
172 type SubscriptionService = XcmPallet;
173 type PalletInstancesInfo = AllPalletsWithSystem;
174 type FeeManager = ();
175 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
176 type MessageExporter = ();
177 type UniversalAliases = Nothing;
178 type CallDispatcher = RuntimeCall;
179 type SafeCallFilter = Everything;
180 type Aliasers = Nothing;
181 type TransactionalProcessor = FrameTransactionalProcessor;
182 type HrmpNewChannelOpenRequestHandler = ();
183 type HrmpChannelAcceptedHandler = ();
184 type HrmpChannelClosingHandler = ();
185 type XcmRecorder = XcmPallet;
186}
187
188pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
189
190impl pallet_xcm::Config for Runtime {
191 type RuntimeEvent = RuntimeEvent;
192 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
193 type XcmRouter = XcmRouter;
194 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
195 type XcmExecuteFilter = Everything;
196 type XcmExecutor = XcmExecutor<XcmConfig>;
197 type XcmTeleportFilter = Everything;
198 type XcmReserveTransferFilter = Everything;
199 type Weigher = FixedWeightBounds<XcmInstructionWeight, RuntimeCall, MaxInstructions>;
200 type UniversalLocation = UniversalLocation;
201 type RuntimeOrigin = RuntimeOrigin;
202 type RuntimeCall = RuntimeCall;
203 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
204 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
205 type Currency = Balances;
206 type CurrencyMatcher = IsConcrete<TokenLocation>;
207 type TrustedLockers = ();
208 type SovereignAccountOf = SovereignAccountOf;
209 type MaxLockers = ConstU32<8>;
210 type MaxRemoteLockConsumers = ConstU32<0>;
211 type RemoteLockConsumerIdentifier = ();
212 type WeightInfo = pallet_xcm::TestWeightInfo;
213 type AdminOrigin = EnsureRoot<AccountId>;
214 type AuthorizedAliasConsideration = Disabled;
216}
217
218impl origin::Config for Runtime {}
219
220type Block = frame_system::mocking::MockBlock<Runtime>;
221
222impl pallet_message_queue::Config for Runtime {
223 type RuntimeEvent = RuntimeEvent;
224 type Size = u32;
225 type HeapSize = MessageQueueHeapSize;
226 type MaxStale = MessageQueueMaxStale;
227 type ServiceWeight = MessageQueueServiceWeight;
228 type IdleMaxServiceWeight = ();
229 type MessageProcessor = MessageProcessor;
230 type QueueChangeHandler = ();
231 type WeightInfo = ();
232 type QueuePausedQuery = ();
233}
234
235construct_runtime!(
236 pub enum Runtime {
237 System: frame_system,
238 Balances: pallet_balances,
239 ParasOrigin: origin,
240 XcmPallet: pallet_xcm,
241 MessageQueue: pallet_message_queue,
242 }
243);