Lines
51.61 %
Functions
22.34 %
Branches
100 %
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Relay chain runtime mock.
use frame_support::{
construct_runtime, parameter_types,
traits::{Everything, Nothing, ProcessMessage, ProcessMessageError},
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_core::H256;
use sp_runtime::{
traits::{ConstU32, IdentityLookup},
AccountId32,
use frame_support::weights::{Weight, WeightMeter};
use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::{
configuration, dmp, hrmp,
inclusion::{AggregateMessageOrigin, UmpQueueId},
origin, paras, shared,
use sp_runtime::transaction_validity::TransactionPriority;
use sp_runtime::Permill;
use xcm::latest::prelude::*;
use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia,
ChildSystemParachainAsSuperuser, FixedRateOfFungible, FixedWeightBounds,
FungibleAdapter as XcmCurrencyAdapter, IsConcrete, ProcessXcmMessage,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
WithComputedOrigin,
use xcm_executor::{Config, XcmExecutor};
pub type AccountId = AccountId32;
pub type Balance = u128;
pub type BlockNumber = BlockNumberFor<Runtime>;
parameter_types! {
pub const BlockHashCount: u32 = 250;
}
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
type Nonce = u64;
type Block = Block;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
type BlockLength = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = ();
type BaseCallFilter = Everything;
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
type SingleBlockMigrations = ();
type MultiBlockMigrator = ();
type PreInherents = ();
type PostInherents = ();
type PostTransactions = ();
pub ExistentialDeposit: Balance = 1;
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeFreezeReason = ();
impl pallet_utility::Config for Runtime {
type PalletsOrigin = OriginCaller;
impl shared::Config for Runtime {
type DisabledValidators = ();
impl configuration::Config for Runtime {
type WeightInfo = configuration::TestWeightInfo;
pub KsmLocation: Location = Here.into();
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
pub const AnyNetwork: Option<NetworkId> = None;
pub UniversalLocation: InteriorLocation = Here;
pub type SovereignAccountOf = (
ChildParachainConvertsVia<ParaId, AccountId>,
AccountId32Aliases<KusamaNetwork, AccountId>,
// Not enabled in the relay per se, but we enable it to test
// the transact_through_signed extrinsic
Account32Hash<KusamaNetwork, AccountId>,
);
pub type LocalAssetTransactor =
XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, SovereignAccountOf, AccountId, ()>;
type LocalOriginConverter = (
SovereignSignedViaLocation<SovereignAccountOf, RuntimeOrigin>,
ChildParachainAsNative<origin::Origin, RuntimeOrigin>,
SignedAccountId32AsNative<KusamaNetwork, RuntimeOrigin>,
ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
pub const BaseXcmWeight: Weight = Weight::from_parts(1000u64, 1000u64);
pub KsmPerSecond: (AssetId, u128, u128) = (AssetId(KsmLocation::get()), 1, 1);
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
pub MatcherLocation: Location = Location::here();
pub type XcmRouter = super::RelayChainXcmRouter;
pub type XcmBarrier = (
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
AllowKnownQueryResponses<XcmPallet>,
WithComputedOrigin<
(
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
),
UniversalLocation,
ConstU32<8>,
>,
pub Kusama: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(KsmLocation::get()) });
pub Statemine: Location = Parachain(4).into();
pub KusamaForStatemine: (AssetFilter, Location) = (Kusama::get(), Statemine::get());
pub type TrustedTeleporters = xcm_builder::Case<KusamaForStatemine>;
pub struct XcmConfig;
impl Config for XcmConfig {
type XcmSender = XcmRouter;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = TrustedTeleporters;
type UniversalLocation = UniversalLocation;
type Barrier = XcmBarrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
type Trader = FixedRateOfFungible<KsmPerSecond, ()>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type CallDispatcher = RuntimeCall;
type AssetLocker = ();
type AssetExchanger = ();
type PalletInstancesInfo = ();
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
type TransactionalProcessor = ();
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, KusamaNetwork>;
impl pallet_xcm::Config for Runtime {
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
// Anyone can execute XCM messages locally...
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
pub const FirstMessageFactorPercent: u64 = 100;
pub const ParasUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
/// A very dumb implementation of `EstimateNextSessionRotation`. At the moment of writing, this
/// is more to satisfy type requirements rather than to test anything.
pub struct TestNextSessionRotation;
impl frame_support::traits::EstimateNextSessionRotation<u32> for TestNextSessionRotation {
fn average_session_length() -> u32 {
10
fn estimate_current_session_progress(_now: u32) -> (Option<Permill>, Weight) {
(None, Weight::zero())
fn estimate_next_session_rotation(_now: u32) -> (Option<u32>, Weight) {
impl paras::Config for Runtime {
type WeightInfo = paras::TestWeightInfo;
type UnsignedPriority = ParasUnsignedPriority;
type NextSessionRotation = TestNextSessionRotation;
type QueueFootprinter = ();
type OnNewHead = ();
type AssignCoretime = ();
impl dmp::Config for Runtime {}
pub const DefaultChannelSizeAndCapacityWithSystem: (u32, u32) = (4, 1);
impl hrmp::Config for Runtime {
type WeightInfo = TestHrmpWeightInfo;
type ChannelManager = frame_system::EnsureRoot<AccountId>;
type DefaultChannelSizeAndCapacityWithSystem = DefaultChannelSizeAndCapacityWithSystem;
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
RuntimeCall: From<C>,
{
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = RuntimeCall;
impl origin::Config for Runtime {}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlockU32<Runtime>;
pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000);
pub const MessageQueueHeapSize: u32 = 65_536;
pub const MessageQueueMaxStale: u32 = 16;
pub struct MessageProcessor;
impl ProcessMessage for MessageProcessor {
type Origin = AggregateMessageOrigin;
fn process_message(
message: &[u8],
origin: Self::Origin,
meter: &mut WeightMeter,
id: &mut [u8; 32],
) -> Result<bool, ProcessMessageError> {
let para = match origin {
AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
ProcessXcmMessage::<Junction, XcmExecutor<XcmConfig>, RuntimeCall>::process_message(
message,
Junction::Parachain(para.into()),
meter,
id,
)
impl pallet_message_queue::Config for Runtime {
type Size = u32;
type HeapSize = MessageQueueHeapSize;
type MaxStale = MessageQueueMaxStale;
type ServiceWeight = MessageQueueServiceWeight;
type MessageProcessor = MessageProcessor;
type QueueChangeHandler = ();
type QueuePausedQuery = ();
type IdleMaxServiceWeight = MessageQueueServiceWeight;
construct_runtime!(
pub enum Runtime {
System: frame_system,
Balances: pallet_balances,
ParasOrigin: origin,
MessageQueue: pallet_message_queue,
XcmPallet: pallet_xcm,
Utility: pallet_utility,
Hrmp: hrmp,
Dmp: dmp,
Paras: paras,
Configuration: configuration,
pub(crate) fn relay_events() -> Vec<RuntimeEvent> {
System::events()
.into_iter()
.map(|r| r.event)
.filter_map(|e| Some(e))
.collect::<Vec<_>>()
use frame_support::traits::{OnFinalize, OnInitialize};
pub(crate) fn relay_roll_to(n: BlockNumber) {
while System::block_number() < n {
XcmPallet::on_finalize(System::block_number());
Balances::on_finalize(System::block_number());
System::on_finalize(System::block_number());
System::set_block_number(System::block_number() + 1);
System::on_initialize(System::block_number());
Balances::on_initialize(System::block_number());
XcmPallet::on_initialize(System::block_number());
/// A weight info that is only suitable for testing.
pub struct TestHrmpWeightInfo;
impl hrmp::WeightInfo for TestHrmpWeightInfo {
fn hrmp_accept_open_channel() -> Weight {
Weight::from_parts(1, 0)
fn force_clean_hrmp(_: u32, _: u32) -> Weight {
fn force_process_hrmp_close(_: u32) -> Weight {
fn force_process_hrmp_open(_: u32) -> Weight {
fn hrmp_cancel_open_request(_: u32) -> Weight {
fn hrmp_close_channel() -> Weight {
fn hrmp_init_open_channel() -> Weight {
fn clean_open_channel_requests(_: u32) -> Weight {
fn force_open_hrmp_channel(_: u32) -> Weight {
fn establish_system_channel() -> Weight {
fn poke_channel_deposits() -> Weight {
fn establish_channel_with_system() -> Weight {