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 SubscriptionService = XcmPallet;
172 type PalletInstancesInfo = AllPalletsWithSystem;
173 type FeeManager = ();
174 type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
175 type MessageExporter = ();
176 type UniversalAliases = Nothing;
177 type CallDispatcher = RuntimeCall;
178 type SafeCallFilter = Everything;
179 type Aliasers = Nothing;
180 type TransactionalProcessor = FrameTransactionalProcessor;
181 type HrmpNewChannelOpenRequestHandler = ();
182 type HrmpChannelAcceptedHandler = ();
183 type HrmpChannelClosingHandler = ();
184 type XcmRecorder = XcmPallet;
185}
186
187pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
188
189impl pallet_xcm::Config for Runtime {
190 type RuntimeEvent = RuntimeEvent;
191 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
192 type XcmRouter = XcmRouter;
193 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
194 type XcmExecuteFilter = Everything;
195 type XcmExecutor = XcmExecutor<XcmConfig>;
196 type XcmTeleportFilter = Everything;
197 type XcmReserveTransferFilter = Everything;
198 type Weigher = FixedWeightBounds<XcmInstructionWeight, RuntimeCall, MaxInstructions>;
199 type UniversalLocation = UniversalLocation;
200 type RuntimeOrigin = RuntimeOrigin;
201 type RuntimeCall = RuntimeCall;
202 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
203 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
204 type Currency = Balances;
205 type CurrencyMatcher = IsConcrete<TokenLocation>;
206 type TrustedLockers = ();
207 type SovereignAccountOf = SovereignAccountOf;
208 type MaxLockers = ConstU32<8>;
209 type MaxRemoteLockConsumers = ConstU32<0>;
210 type RemoteLockConsumerIdentifier = ();
211 type WeightInfo = pallet_xcm::TestWeightInfo;
212 type AdminOrigin = EnsureRoot<AccountId>;
213 type AuthorizedAliasConsideration = Disabled;
215}
216
217impl origin::Config for Runtime {}
218
219type Block = frame_system::mocking::MockBlock<Runtime>;
220
221impl pallet_message_queue::Config for Runtime {
222 type RuntimeEvent = RuntimeEvent;
223 type Size = u32;
224 type HeapSize = MessageQueueHeapSize;
225 type MaxStale = MessageQueueMaxStale;
226 type ServiceWeight = MessageQueueServiceWeight;
227 type IdleMaxServiceWeight = ();
228 type MessageProcessor = MessageProcessor;
229 type QueueChangeHandler = ();
230 type WeightInfo = ();
231 type QueuePausedQuery = ();
232}
233
234construct_runtime!(
235 pub enum Runtime {
236 System: frame_system,
237 Balances: pallet_balances,
238 ParasOrigin: origin,
239 XcmPallet: pallet_xcm,
240 MessageQueue: pallet_message_queue,
241 }
242);