diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 241a03334..dfe572303 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,9 +39,5 @@ jobs: run: cargo clippy -- -D warnings - name: Check for Wasm run: make dev-check - - name: Install Zepter - run: cargo install zepter --version 0.15.0 --locked -q -f --no-default-features && zepter --version - - name: Check Rust features - run: make dev-features-check - name: Run tests run: make dev-test diff --git a/.github/workflows/zepter.yml b/.github/workflows/zepter.yml new file mode 100644 index 000000000..e2cbd94d6 --- /dev/null +++ b/.github/workflows/zepter.yml @@ -0,0 +1,33 @@ +name: Zepter + +on: + pull_request: + branches: + - master + - polkadot-** + paths-ignore: + - '**/README.md' + push: + branches: + - master + - polkadot-** + paths-ignore: + - '**/README.md' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + - name: Install Zepter + run: cargo install zepter --version 0.15.0 --locked -q -f --no-default-features && zepter --version + - run: make Cargo.toml + - run: cargo update + - name: Check Rust features + run: make dev-features-check diff --git a/Cargo.dev.toml b/Cargo.dev.toml index 4f93f70dc..147fdc758 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -4,24 +4,25 @@ members = [ "auction", "authority", "benchmarking", + "build-script-utils", "currencies", "gradually-update", + "nft", "oracle", "oracle/runtime-api", + "parameters", + "payments", + "rewards", "tokens", "tokens/runtime-api", "traits", + "unknown-tokens", "utilities", "vesting", - "rewards", - "nft", + "xcm-mock-message-queue", + "xcm-support", "xcm", "xtokens", - "xcm-support", - "unknown-tokens", - "build-script-utils", - "payments", - "parameters", ] resolver = "2" @@ -35,72 +36,34 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive serde = { version = "1.0.189" } parity-scale-codec = { version = "3.6.5", default-features = false, features = ["max-encoded-len"] } -cumulus-pallet-dmp-queue = { version = "0.4.0", default-features = false } -cumulus-pallet-parachain-system = { version = "0.4.0", default-features = false } -cumulus-pallet-xcm = { version = "0.4.0", default-features = false } -cumulus-pallet-xcmp-queue = { version = "0.4.0", default-features = false } -cumulus-primitives-core = { version = "0.4.0", default-features = false } -frame-benchmarking = { version = "25.0.0", default-features = false } -frame-support = { version = "25.0.0", default-features = false } -frame-system = { version = "25.0.0", default-features = false } -pallet-authority-discovery = { version = "25.0.0", default-features = false } -pallet-authorship = { version = "25.0.0", default-features = false } -pallet-babe = { version = "25.0.0", default-features = false } -pallet-balances = { version = "25.0.0", default-features = false } -pallet-elections-phragmen = { version = "26.0.0", default-features = false } -pallet-message-queue = { version = "28.0.0", default-features = false } -pallet-preimage = { version = "25.0.0", default-features = false } -pallet-root-testing = { version = "1.0.0", default-features = false } -pallet-scheduler = { version = "26.0.0", default-features = false } -pallet-session = { version = "25.0.0", default-features = false } -pallet-staking = { version = "25.0.0", default-features = false } -pallet-timestamp = { version = "24.0.0", default-features = false } -pallet-transaction-payment = { version = "25.0.0", default-features = false } -pallet-treasury = { version = "24.0.0", default-features = false } -pallet-vesting = { version = "25.0.0", default-features = false } -pallet-xcm = { version = "4.0.0", default-features = false } -parachain-info = { package = "staging-parachain-info", version = "0.4.0", default-features = false } -polkadot-core-primitives = { version = "4.0.0", default-features = false } -polkadot-parachain-primitives = { version = "3.0.0", default-features = false } -polkadot-primitives = { version = "4.0.0", default-features = false } -polkadot-runtime-common = { version = "4.0.0", default-features = false } -polkadot-runtime-parachains = { version = "4.0.0", default-features = false } -sp-api = { version = "23.0.0", default-features = false } -sp-application-crypto = { version = "27.0.0", default-features = false } -sp-arithmetic = { version = "20.0.0", default-features = false } -sp-authority-discovery = { version = "23.0.0", default-features = false } -sp-blockchain = { version = "25.0.0", default-features = false } -sp-consensus = { version = "0.29.0", default-features = false } -sp-consensus-slots = { version = "0.29.0", default-features = false } -sp-core = { version = "25.0.0", default-features = false } -sp-debug-derive = { version = "12.0.0", default-features = false } -sp-externalities = { version = "0.23.0", default-features = false } -sp-inherents = { version = "23.0.0", default-features = false } -sp-io = { version = "27.0.0", default-features = false } -sp-keystore = { version = "0.31.0", default-features = false } -sp-maybe-compressed-blob = { version = "9.0.0", default-features = false } -sp-npos-elections = { version = "23.0.0", default-features = false } -sp-panic-handler = { version = "12.0.0", default-features = false } -sp-runtime = { version = "28.0.0", default-features = false } -sp-runtime-interface = { version = "21.0.0", default-features = false } -sp-session = { version = "24.0.0", default-features = false } -sp-staking = { version = "23.0.0", default-features = false } -sp-state-machine = { version = "0.32.0", default-features = false } -sp-std = { version = "12.0.0", default-features = false } -sp-storage = { version = "17.0.0", default-features = false } -sp-timestamp = { version = "23.0.0", default-features = false } -sp-tracing = { version = "14.0.0", default-features = false } -sp-trie = { version = "26.0.0", default-features = false } -sp-version = { version = "26.0.0", default-features = false } -sp-wasm-interface = { version = "18.0.0", default-features = false } -sp-weights = { version = "24.0.0", default-features = false } -xcm = { package = "staging-xcm", version = "4.0.0", default-features = false } -xcm-builder = { package = "staging-xcm-builder", version = "4.0.0", default-features = false } -xcm-executor = { package = "staging-xcm-executor", version = "4.0.0", default-features = false } +cumulus-pallet-xcm = { version = "0.7.0", default-features = false } +cumulus-primitives-core = { version = "0.7.0", default-features = false } +frame-benchmarking = { version = "28.0.0", default-features = false } +frame-support = { version = "28.0.0", default-features = false } +frame-system = { version = "28.0.0", default-features = false } +pallet-balances = { version = "28.0.0", default-features = false } +pallet-elections-phragmen = { version = "29.0.0", default-features = false } +pallet-message-queue = { version = "31.0.0", default-features = false } +pallet-preimage = { version = "28.0.0", default-features = false } +pallet-root-testing = { version = "4.0.0", default-features = false } +pallet-scheduler = { version = "29.0.0", default-features = false } +pallet-treasury = { version = "27.0.0", default-features = false } +pallet-xcm = { version = "7.0.0", default-features = false } +polkadot-parachain-primitives = { version = "6.0.0", default-features = false } +polkadot-runtime-common = { version = "7.0.0", default-features = false } +polkadot-runtime-parachains = { version = "7.0.0", default-features = false } +sp-api = { version = "26.0.0", default-features = false } +sp-application-crypto = { version = "30.0.0", default-features = false } +sp-arithmetic = { version = "23.0.0", default-features = false } +sp-core = { version = "28.0.0", default-features = false } +sp-io = { version = "30.0.0", default-features = false } +sp-runtime = { version = "31.0.1", default-features = false } +sp-runtime-interface = { version = "24.0.0", default-features = false } +sp-staking = { version = "26.0.0", default-features = false } +sp-std = { version = "14.0.0", default-features = false } +sp-storage = { version = "19.0.0", default-features = false } +xcm = { package = "staging-xcm", version = "7.0.0", default-features = false } +xcm-builder = { package = "staging-xcm-builder", version = "7.0.0", default-features = false } +xcm-executor = { package = "staging-xcm-executor", version = "7.0.0", default-features = false } -sc-client-api = { version = "25.0.0" } -sc-client-db = { version = "0.32.0" } -sc-executor = { version = "0.29.0" } -sc-executor-common = { version = "0.26.0" } -sc-utils = { version = "11.0.0" } -xcm-simulator = { version = "4.0.0" } +xcm-simulator = { version = "7.0.0" } diff --git a/asset-registry/Cargo.toml b/asset-registry/Cargo.toml index 2a76deb23..839d3cf7c 100644 --- a/asset-registry/Cargo.toml +++ b/asset-registry/Cargo.toml @@ -41,11 +41,7 @@ pallet-message-queue = { workspace = true, features = ["std"] } # cumulus cumulus-primitives-core = { workspace = true, features = ["std"] } -cumulus-pallet-dmp-queue = { workspace = true, features = ["std"] } -cumulus-pallet-xcmp-queue = { workspace = true, features = ["std"] } cumulus-pallet-xcm = { workspace = true, features = ["std"] } -cumulus-pallet-parachain-system = { workspace = true, features = ["std"] } -parachain-info = { workspace = true, features = ["std"] } # polkadot polkadot-parachain-primitives = { workspace = true, features = ["std"] } @@ -58,6 +54,7 @@ orml-tokens = { path = "../tokens" } orml-xcm = { path = "../xcm" } orml-xcm-support = { path = "../xcm-support" } orml-xtokens = { path = "../xtokens" } +orml-xcm-mock-message-queue = { path = "../xcm-mock-message-queue" } [features] default = [ "std" ] diff --git a/asset-registry/src/mock/mod.rs b/asset-registry/src/mock/mod.rs index 7bcdf01aa..092b3a194 100644 --- a/asset-registry/src/mock/mod.rs +++ b/asset-registry/src/mock/mod.rs @@ -162,8 +162,8 @@ pub type Amount = i128; decl_test_parachain! { pub struct ParaA { Runtime = para::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(1, None), } } @@ -171,8 +171,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaB { Runtime = para::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(2, None), } } @@ -180,8 +180,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaC { Runtime = para::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(3, None), } } @@ -189,8 +189,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaG { Runtime = para::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(4, Some(( vec![( 4, @@ -248,18 +248,12 @@ pub type ParaTokens = orml_tokens::Pallet; pub type ParaXTokens = orml_xtokens::Pallet; pub fn para_ext(para_id: u32, asset_data: Option<(Vec<(u32, Vec)>, u32)>) -> TestExternalities { - use para::{Runtime, System}; + use para::{MsgQueue, Runtime, System}; let mut t = frame_system::GenesisConfig::::default() .build_storage() .unwrap(); - let parachain_info_config = parachain_info::GenesisConfig:: { - _config: Default::default(), - parachain_id: para_id.into(), - }; - parachain_info_config.assimilate_storage(&mut t).unwrap(); - orml_tokens::GenesisConfig:: { balances: vec![(ALICE, CurrencyId::R, 1_000)], } @@ -273,7 +267,10 @@ pub fn para_ext(para_id: u32, asset_data: Option<(Vec<(u32, Vec)>, u32)>) -> } let mut ext = TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); ext } diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index 2d17ccf30..0fb781750 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -2,13 +2,10 @@ use super::{Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter}; use crate as orml_asset_registry; -use cumulus_pallet_parachain_system::AnyRelayNumber; -use cumulus_primitives_core::ParaId; -use frame_support::traits::{EnsureOrigin, EnsureOriginWithArg}; +use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ - construct_runtime, match_types, ord_parameter_types, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing}, - weights::constants::WEIGHT_REF_TIME_PER_SECOND, + construct_runtime, derive_impl, match_types, ord_parameter_types, parameter_types, + traits::{ConstU128, ConstU32, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing}, PalletId, }; use frame_system::{EnsureRoot, EnsureSignedBy}; @@ -21,8 +18,7 @@ use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset} use pallet_xcm::XcmPassthrough; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; -use sp_core::H256; +use sp_core::Get; use sp_runtime::{ traits::{AccountIdConversion, Convert, IdentityLookup}, AccountId32, @@ -37,30 +33,12 @@ use xcm_executor::{Config, XcmExecutor}; pub type AccountId = AccountId32; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { @@ -157,18 +135,10 @@ impl orml_asset_registry::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); - pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -} - -impl parachain_info::Config for Runtime {} - -parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = - X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); + X2(GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::get().into())); } pub type LocationToAccountId = ( @@ -196,7 +166,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< (), >; -pub type XcmRouter = ParachainXcmRouter; +pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); parameter_types! { @@ -234,6 +204,7 @@ parameter_types! { pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; } pub struct XcmConfig; @@ -264,36 +235,6 @@ impl Config for XcmConfig { type Aliasers = Nothing; } -impl cumulus_pallet_parachain_system::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type OnSystemEvent = (); - type SelfParaId = (); - type OutboundXcmpMessageSource = XcmpQueue; - type DmpMessageHandler = (); - type ReservedDmpWeight = (); - type XcmpMessageHandler = XcmpQueue; - type ReservedXcmpWeight = (); - type CheckAssociatedRelayNumber = AnyRelayNumber; -} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; - type VersionWrapper = (); - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToCallOrigin; - type WeightInfo = (); - type PriceForSiblingDelivery = NoPriceForMessageDelivery; -} - -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; -} - impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -306,11 +247,6 @@ parameter_types! { pub const MaxAssetsForTransfer: usize = 3; } -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -335,8 +271,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; @@ -394,6 +328,11 @@ impl orml_xcm::Config for Runtime { type SovereignOrigin = EnsureRoot; } +impl orml_xcm_mock_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + type Block = frame_system::mocking::MockBlock; construct_runtime!( @@ -401,10 +340,7 @@ construct_runtime!( System: frame_system, Balances: pallet_balances, - ParachainInfo: parachain_info, - ParachainSystem: cumulus_pallet_parachain_system, - XcmpQueue: cumulus_pallet_xcmp_queue, - DmpQueue: cumulus_pallet_dmp_queue, + MsgQueue: orml_xcm_mock_message_queue, CumulusXcm: cumulus_pallet_xcm, Tokens: orml_tokens, diff --git a/asset-registry/src/mock/relay.rs b/asset-registry/src/mock/relay.rs index 9e1404c15..148d80dc3 100644 --- a/asset-registry/src/mock/relay.rs +++ b/asset-registry/src/mock/relay.rs @@ -1,8 +1,8 @@ use crate::Weight; use cumulus_primitives_core::ParaId; use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing, ProcessMessage, ProcessMessageError}, + construct_runtime, derive_impl, parameter_types, + traits::{ConstU128, ConstU32, Everything, Nothing, ProcessMessage, ProcessMessageError}, weights::{IdentityFee, WeightMeter}, }; use frame_system::EnsureRoot; @@ -11,43 +11,24 @@ use polkadot_runtime_parachains::{ inclusion::{AggregateMessageOrigin, UmpQueueId}, origin, shared, }; -use sp_core::H256; use sp_runtime::{traits::IdentityLookup, AccountId32}; use xcm::v3::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, - CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, + FixedWeightBounds, FungibleAdapter, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{Config, XcmExecutor}; pub type AccountId = AccountId32; pub type Balance = u128; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { @@ -84,8 +65,7 @@ pub type SovereignAccountOf = ( AccountId32Aliases, ); -pub type LocalAssetTransactor = - XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; +pub type LocalAssetTransactor = FungibleAdapter, SovereignAccountOf, AccountId, ()>; type LocalOriginConverter = ( SovereignSignedViaLocation, @@ -136,11 +116,6 @@ parameter_types! { pub SelfLocation: MultiLocation = MultiLocation::here(); } -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(MultiLocation::here()); -} - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; @@ -166,8 +141,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; } impl origin::Config for Runtime {} diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index d8bc6b206..36a840f26 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -3,7 +3,7 @@ use super::*; use crate as orml_asset_registry; use crate::tests::para::{AdminAssetTwo, AssetRegistry, CustomMetadata, RuntimeOrigin, Tokens, TreasuryAccount}; -use frame_support::{assert_noop, assert_ok, traits::OnRuntimeUpgrade, StorageHasher}; +use frame_support::{assert_noop, assert_ok}; use mock::{para::RuntimeCall, *}; use orml_traits::MultiCurrency; use polkadot_parachain_primitives::primitives::Sibling; diff --git a/auction/src/mock.rs b/auction/src/mock.rs index 3dda1d2b0..712e65b90 100644 --- a/auction/src/mock.rs +++ b/auction/src/mock.rs @@ -3,12 +3,8 @@ #![cfg(test)] use super::*; -use frame_support::{ - construct_runtime, - traits::{ConstU64, Everything}, -}; +use frame_support::{construct_runtime, derive_impl}; use orml_traits::OnNewBidResult; -use sp_core::H256; use sp_runtime::{traits::IdentityLookup, BuildStorage}; use crate as auction; @@ -18,30 +14,12 @@ pub type Balance = u64; pub type BlockNumber = u64; pub type AuctionId = u64; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } pub struct Handler; diff --git a/authority/src/mock.rs b/authority/src/mock.rs index 14deac4ae..59ea0dbae 100644 --- a/authority/src/mock.rs +++ b/authority/src/mock.rs @@ -3,14 +3,9 @@ #![cfg(test)] use super::*; -use frame_support::{ - parameter_types, - traits::{ConstU64, EqualPrivilegeOnly, Everything}, - weights::Weight, -}; +use frame_support::{derive_impl, parameter_types, traits::EqualPrivilegeOnly, weights::Weight}; use frame_system::{ensure_root, ensure_signed, EnsureRoot}; use parity_scale_codec::{Decode, Encode}; -use sp_core::H256; use sp_runtime::{ traits::{BadOrigin, IdentityLookup}, BuildStorage, Perbill, @@ -26,30 +21,12 @@ parameter_types! { frame_system::limits::BlockWeights::simple_max(Weight::from_parts(2_000_000_000_000, 0).set_proof_size(u64::MAX)); } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = BlockWeights; - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl pallet_preimage::Config for Runtime { @@ -76,7 +53,9 @@ impl pallet_scheduler::Config for Runtime { type Preimages = Preimage; } -impl pallet_root_testing::Config for Runtime {} +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} #[derive(Clone, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo)] pub enum MockAsOriginId { diff --git a/benchmarking/src/tests.rs b/benchmarking/src/tests.rs index 70af2da86..4220badd7 100644 --- a/benchmarking/src/tests.rs +++ b/benchmarking/src/tests.rs @@ -4,16 +4,9 @@ use super::*; use frame_benchmarking::account; -use frame_support::{ - assert_err, assert_ok, construct_runtime, ensure, - traits::{ConstU32, Everything}, -}; +use frame_support::{assert_err, assert_ok, construct_runtime, derive_impl, ensure}; use frame_system::RawOrigin; -use sp_runtime::{ - testing::{Header, H256}, - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, -}; +use sp_runtime::{testing::Header, traits::IdentityLookup, BuildStorage}; use sp_std::prelude::*; pub use test::*; @@ -53,30 +46,12 @@ pub mod test { type AccountId = u128; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type Hash = H256; - type RuntimeCall = RuntimeCall; - type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type DbWeight = (); - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl Config for Test {} diff --git a/currencies/src/mock.rs b/currencies/src/mock.rs index 64e417eab..8c17bae4c 100644 --- a/currencies/src/mock.rs +++ b/currencies/src/mock.rs @@ -4,12 +4,11 @@ use super::*; use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU32, ConstU64, Everything, Nothing}, + construct_runtime, derive_impl, parameter_types, + traits::{ConstU32, ConstU64, Nothing}, PalletId, }; use orml_traits::{currency::MutationHooks, parameter_type_with_key}; -use sp_core::H256; use sp_runtime::{ traits::{AccountIdConversion, IdentityLookup}, AccountId32, BuildStorage, @@ -20,30 +19,14 @@ use crate as currencies; pub type ReserveIdentifier = [u8; 8]; pub type AccountId = AccountId32; + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } type CurrencyId = u32; diff --git a/gradually-update/src/mock.rs b/gradually-update/src/mock.rs index 14fb1172b..c5e9264e6 100644 --- a/gradually-update/src/mock.rs +++ b/gradually-update/src/mock.rs @@ -4,40 +4,21 @@ use super::*; use frame_support::{ - construct_runtime, - traits::{ConstU32, ConstU64, Everything}, + construct_runtime, derive_impl, + traits::{ConstU32, ConstU64}, }; -use sp_core::H256; use sp_runtime::{traits::IdentityLookup, BuildStorage}; use crate as gradually_update; pub type AccountId = u128; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl Config for Runtime { diff --git a/nft/src/mock.rs b/nft/src/mock.rs index 81a5ce3fa..b8db62292 100644 --- a/nft/src/mock.rs +++ b/nft/src/mock.rs @@ -2,11 +2,7 @@ #![cfg(test)] -use frame_support::{ - construct_runtime, - traits::{ConstU32, ConstU64, Everything}, -}; -use sp_core::H256; +use frame_support::{construct_runtime, derive_impl, traits::ConstU32}; use sp_runtime::{traits::IdentityLookup, BuildStorage}; use super::*; @@ -15,30 +11,11 @@ use crate as nft; pub type AccountId = u128; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl Config for Runtime { diff --git a/oracle/src/mock.rs b/oracle/src/mock.rs index 9173bbfac..502f33805 100644 --- a/oracle/src/mock.rs +++ b/oracle/src/mock.rs @@ -3,14 +3,10 @@ use super::*; use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU32, ConstU64, Everything, SortedMembers}, -}; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, + construct_runtime, derive_impl, parameter_types, + traits::{ConstU32, SortedMembers}, }; +use sp_runtime::{traits::IdentityLookup, BuildStorage}; use std::cell::RefCell; @@ -22,30 +18,11 @@ pub type AccountId = u128; type Key = u32; type Value = u32; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } thread_local! { diff --git a/parameters/src/mock.rs b/parameters/src/mock.rs index 62ab382e9..bdee5e041 100644 --- a/parameters/src/mock.rs +++ b/parameters/src/mock.rs @@ -1,12 +1,8 @@ #![cfg(test)] use frame_support::traits::EnsureOriginWithArg; -use frame_support::{ - construct_runtime, - traits::{ConstU32, ConstU64, Everything}, -}; +use frame_support::{construct_runtime, derive_impl}; use orml_traits::define_aggregrated_parameters; -use sp_core::H256; use sp_runtime::{traits::IdentityLookup, BuildStorage}; use super::*; @@ -15,30 +11,11 @@ use crate as parameters; pub type AccountId = u128; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } pub mod pallet1 { diff --git a/payments/Cargo.toml b/payments/Cargo.toml index 57380f69d..5fbc19192 100644 --- a/payments/Cargo.toml +++ b/payments/Cargo.toml @@ -27,7 +27,7 @@ serde = "1.0.136" sp-core = { workspace = true } sp-io = { workspace = true } -orml-tokens = { path = "../tokens", default-features = false } +orml-tokens = { path = "../tokens" } [features] default = [ 'std' ] diff --git a/payments/src/mock.rs b/payments/src/mock.rs index 82aac6335..039291c78 100644 --- a/payments/src/mock.rs +++ b/payments/src/mock.rs @@ -1,17 +1,14 @@ use crate as payment; use crate::PaymentDetail; use frame_support::{ + derive_impl, dispatch::DispatchClass, parameter_types, - traits::{ConstU32, Contains, Everything, Hooks, OnFinalize}, + traits::{ConstU32, Contains, Hooks, OnFinalize}, }; use frame_system as system; use orml_traits::parameter_type_with_key; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, Percent, -}; +use sp_runtime::{traits::IdentityLookup, BuildStorage, Percent}; type Block = frame_system::mocking::MockBlock; pub type Balance = u128; @@ -42,30 +39,11 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_type_with_key! { diff --git a/rewards/src/mock.rs b/rewards/src/mock.rs index fe18f4277..c46c03b69 100644 --- a/rewards/src/mock.rs +++ b/rewards/src/mock.rs @@ -3,12 +3,7 @@ #![cfg(test)] use super::*; -use frame_support::{ - construct_runtime, - traits::{ConstU64, Everything}, - weights::constants::RocksDbWeight, -}; -use sp_core::H256; +use frame_support::{construct_runtime, derive_impl}; use sp_runtime::{traits::IdentityLookup, BuildStorage}; use sp_std::cell::RefCell; use std::collections::HashMap; @@ -28,30 +23,11 @@ pub const DOT_POOL: PoolId = 1; pub const NATIVE_COIN: CurrencyId = 0; pub const STABLE_COIN: CurrencyId = 1; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = RocksDbWeight; - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } thread_local! { diff --git a/tokens/src/impls.rs b/tokens/src/impls.rs index f68d9330d..04ace3eda 100644 --- a/tokens/src/impls.rs +++ b/tokens/src/impls.rs @@ -102,6 +102,7 @@ where TestKey: Contains<>::AssetId>, A: fungible::Mutate>::Balance>, B: fungibles::Mutate, + AccountId: Eq, { fn mint_into( asset: Self::AssetId, @@ -149,6 +150,7 @@ where TestKey: Contains<>::AssetId>, A: fungible::Mutate>::Balance>, B: fungibles::Mutate, + AccountId: Eq, { fn handle_dust(_dust: fungibles::Dust) { // FIXME: only way to access internals of Dust is into_credit, but T is @@ -280,6 +282,7 @@ where >, B: BalanceT, GetCurrencyId: Get<>::AssetId>, + AccountId: Eq, { fn mint_into(dest: &AccountId, amount: Self::Balance) -> Result { T::mint_into( diff --git a/tokens/src/lib.rs b/tokens/src/lib.rs index 082bd22cb..b5375561d 100644 --- a/tokens/src/lib.rs +++ b/tokens/src/lib.rs @@ -425,7 +425,9 @@ pub mod module { impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { balances: vec![] } + GenesisConfig { + balances: Default::default(), + } } } diff --git a/tokens/src/mock.rs b/tokens/src/mock.rs index a59180a64..1f190df00 100644 --- a/tokens/src/mock.rs +++ b/tokens/src/mock.rs @@ -4,15 +4,14 @@ use super::*; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, derive_impl, parameter_types, traits::{ tokens::{PayFromAccount, UnityAssetBalanceConversion}, - ChangeMembers, ConstU32, ConstU64, ContainsLengthBound, Everything, SortedMembers, + ChangeMembers, ConstU32, ConstU64, ContainsLengthBound, SortedMembers, }, PalletId, }; use orml_traits::parameter_type_with_key; -use sp_core::H256; use sp_runtime::{ traits::{AccountIdConversion, IdentityLookup}, AccountId32, BuildStorage, Permill, @@ -40,30 +39,11 @@ pub const RID_2: ReserveIdentifier = [2u8; 8]; use crate as tokens; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } thread_local! { diff --git a/unknown-tokens/src/mock.rs b/unknown-tokens/src/mock.rs index a34bec19e..d845a2fe7 100644 --- a/unknown-tokens/src/mock.rs +++ b/unknown-tokens/src/mock.rs @@ -5,39 +5,16 @@ use super::*; use crate as unknown_tokens; -use frame_support::{ - construct_runtime, - traits::{ConstU64, Everything}, -}; -use sp_core::H256; +use frame_support::{construct_runtime, derive_impl}; use sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage}; pub type AccountId = AccountId32; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl Config for Runtime { diff --git a/unknown-tokens/src/tests.rs b/unknown-tokens/src/tests.rs index 5ef1d1a74..99b247f4c 100644 --- a/unknown-tokens/src/tests.rs +++ b/unknown-tokens/src/tests.rs @@ -5,7 +5,7 @@ use super::*; use mock::*; -use frame_support::{assert_err, assert_ok, storage::unhashed::put_raw, traits::OnRuntimeUpgrade}; +use frame_support::{assert_err, assert_ok}; const MOCK_RECIPIENT: MultiLocation = MultiLocation::parent(); const MOCK_CONCRETE_FUNGIBLE_ID: MultiLocation = MultiLocation::parent(); diff --git a/utilities/src/lib.rs b/utilities/src/lib.rs index ad2b61c82..97be33a12 100644 --- a/utilities/src/lib.rs +++ b/utilities/src/lib.rs @@ -40,8 +40,7 @@ pub fn simulate_execution(f: impl FnOnce() -> Result) -> Re #[cfg(test)] mod tests { use super::*; - use frame_support::{assert_noop, assert_ok, construct_runtime, pallet_prelude::*, traits::Everything}; - use sp_core::{ConstU64, H256}; + use frame_support::{assert_noop, assert_ok, construct_runtime, derive_impl, pallet_prelude::*}; use sp_io::TestExternalities; use sp_runtime::traits::IdentityLookup; use sp_runtime::{DispatchError, DispatchResult}; @@ -67,30 +66,11 @@ mod tests { use module::*; + #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u128; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl module::Config for Runtime {} diff --git a/vesting/src/mock.rs b/vesting/src/mock.rs index 71e09674d..6f561b9e0 100644 --- a/vesting/src/mock.rs +++ b/vesting/src/mock.rs @@ -4,40 +4,22 @@ use super::*; use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU32, ConstU64, EnsureOrigin, Everything}, + construct_runtime, derive_impl, parameter_types, + traits::{ConstU32, ConstU64, EnsureOrigin}, }; use frame_system::RawOrigin; -use sp_core::H256; use sp_runtime::{traits::IdentityLookup, BuildStorage}; use crate as vesting; pub type AccountId = u128; + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; + type AccountData = pallet_balances::AccountData; } type Balance = u64; diff --git a/xcm-mock-message-queue/Cargo.toml b/xcm-mock-message-queue/Cargo.toml new file mode 100644 index 000000000..4932bbb10 --- /dev/null +++ b/xcm-mock-message-queue/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "orml-xcm-mock-message-queue" +description = "XCM Mock Message Qeueu for XCM Simulator tests" +repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/xcm-mock-message-queue" +license = "Apache-2.0" +version = "0.6.7" +authors = ["Acala Developers"] +edition = "2021" + +[dependencies] +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } + +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +xcm = { workspace = true } +polkadot-parachain-primitives = { workspace = true } +cumulus-primitives-core = { workspace = true } + +[dev-dependencies] + +[features] +default = [ "std" ] +std = [ + "cumulus-primitives-core/std", + "frame-support/std", + "frame-system/std", + "parity-scale-codec/std", + "polkadot-parachain-primitives/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "xcm/std", +] diff --git a/xcm-mock-message-queue/src/lib.rs b/xcm-mock-message-queue/src/lib.rs new file mode 100644 index 000000000..d83db4436 --- /dev/null +++ b/xcm-mock-message-queue/src/lib.rs @@ -0,0 +1,159 @@ +//! # Mock Message Queue for XCM Simulator tests + +#![cfg_attr(not(feature = "std"), no_std)] + +use cumulus_primitives_core::{ParaId, XcmpMessageFormat, XcmpMessageHandler}; +use frame_support::pallet_prelude::*; +use parity_scale_codec::{Decode, Encode}; +use polkadot_parachain_primitives::primitives::DmpMessageHandler; +use sp_std::prelude::*; +use xcm::{ + v3::{prelude::*, Weight}, + VersionedXcm, +}; + +pub use module::*; + +#[frame_support::pallet] +pub mod module { + use super::*; + + type RelayBlockNumber = u32; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + use sp_runtime::traits::Hash; + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error(error) => (Err(error), Event::Fail(Some(hash), error)), + Outcome::Complete(used) => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete(used, error) => (Ok(used), Event::Fail(Some(hash), error)), + } + } + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = + XcmpMessageFormat::decode(&mut data_ref).expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = data_ref; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = VersionedXcm::::decode(&mut remaining_fragments) { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages(iter: impl Iterator)>, limit: Weight) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = + T::XcmExecutor::prepare_and_execute(Parent, x.clone(), &mut id, limit, Weight::zero()); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + }, + } + } + limit + } + } +} diff --git a/xtokens/Cargo.toml b/xtokens/Cargo.toml index d96bdae05..901c5d2e9 100644 --- a/xtokens/Cargo.toml +++ b/xtokens/Cargo.toml @@ -20,9 +20,6 @@ sp-io = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } -# cumulus -cumulus-primitives-core = { default-features = false , workspace = true } - # polkadot pallet-xcm = { workspace = true } xcm = { workspace = true } @@ -39,12 +36,8 @@ sp-core = { workspace = true, features = ["std"] } pallet-message-queue = { workspace = true, features = ["std"] } # cumulus -cumulus-pallet-dmp-queue = { workspace = true, features = ["std"] } cumulus-pallet-xcm = { workspace = true, features = ["std"] } -cumulus-pallet-xcmp-queue = { workspace = true, features = ["std"] } cumulus-primitives-core = { workspace = true, features = ["std"] } -cumulus-pallet-parachain-system = { workspace = true, features = ["std"] } -parachain-info = { workspace = true, features = ["std"] } # polkadot polkadot-parachain-primitives = { workspace = true, features = ["std"] } @@ -56,6 +49,7 @@ xcm-simulator = { workspace = true } # orml orml-tokens = { path = "../tokens" } orml-xcm = { path = "../xcm" } +orml-xcm-mock-message-queue = { path = "../xcm-mock-message-queue" } [features] default = [ "std" ] diff --git a/xtokens/src/mock/mod.rs b/xtokens/src/mock/mod.rs index bec6dd96c..48a9365ba 100644 --- a/xtokens/src/mock/mod.rs +++ b/xtokens/src/mock/mod.rs @@ -183,8 +183,8 @@ pub type Amount = i128; decl_test_parachain! { pub struct ParaA { Runtime = para::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(1), } } @@ -192,8 +192,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaB { Runtime = para::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(2), } } @@ -201,8 +201,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaC { Runtime = para_teleport::Runtime, - XcmpMessageHandler = para_teleport::XcmpQueue, - DmpMessageHandler = para_teleport::DmpQueue, + XcmpMessageHandler = para_teleport::MsgQueue, + DmpMessageHandler = para_teleport::MsgQueue, new_ext = para_teleport_ext(3), } } @@ -212,8 +212,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaD { Runtime = para_relative_view::Runtime, - XcmpMessageHandler = para::XcmpQueue, - DmpMessageHandler = para::DmpQueue, + XcmpMessageHandler = para::MsgQueue, + DmpMessageHandler = para::MsgQueue, new_ext = para_ext(4), } } @@ -252,18 +252,12 @@ pub type ParaRelativeXTokens = orml_xtokens::Pallet pub type ParaTeleportTokens = orml_tokens::Pallet; pub fn para_ext(para_id: u32) -> TestExternalities { - use para::{Runtime, System}; + use para::{MsgQueue, Runtime, System}; let mut t = frame_system::GenesisConfig::::default() .build_storage() .unwrap(); - let parachain_info_config = parachain_info::GenesisConfig:: { - _config: Default::default(), - parachain_id: para_id.into(), - }; - parachain_info_config.assimilate_storage(&mut t).unwrap(); - orml_tokens::GenesisConfig:: { balances: vec![(ALICE, CurrencyId::R, 1_000)], } @@ -271,23 +265,20 @@ pub fn para_ext(para_id: u32) -> TestExternalities { .unwrap(); let mut ext = TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); ext } pub fn para_teleport_ext(para_id: u32) -> TestExternalities { - use para_teleport::{Runtime, System}; + use para_teleport::{MsgQueue, Runtime, System}; let mut t = frame_system::GenesisConfig::::default() .build_storage() .unwrap(); - let parachain_info_config = parachain_info::GenesisConfig:: { - _config: Default::default(), - parachain_id: para_id.into(), - }; - parachain_info_config.assimilate_storage(&mut t).unwrap(); - orml_tokens::GenesisConfig:: { balances: vec![(ALICE, CurrencyId::R, 1_000)], } @@ -295,7 +286,10 @@ pub fn para_teleport_ext(para_id: u32) -> TestExternalities { .unwrap(); let mut ext = TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); ext } diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index f2947a4c6..b8885ef81 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -1,18 +1,13 @@ use super::{AllowTopLevelPaidExecution, Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter}; use crate as orml_xtokens; -use cumulus_pallet_parachain_system::AnyRelayNumber; -use cumulus_primitives_core::ParaId; use frame_support::{ - construct_runtime, match_types, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything, Get, Nothing}, - weights::constants::WEIGHT_REF_TIME_PER_SECOND, + construct_runtime, derive_impl, match_types, parameter_types, + traits::{ConstU128, ConstU32, Everything, Get, Nothing}, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; -use sp_core::H256; use sp_runtime::{ traits::{Convert, IdentityLookup}, AccountId32, @@ -31,30 +26,12 @@ use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset} pub type AccountId = AccountId32; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { @@ -95,18 +72,10 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); - pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -} - -impl parachain_info::Config for Runtime {} - -parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = - X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); + X2(GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::get().into())); } pub type LocationToAccountId = ( @@ -134,7 +103,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< (), >; -pub type XcmRouter = ParachainXcmRouter; +pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecution); parameter_types! { @@ -172,36 +141,6 @@ impl Config for XcmConfig { type Aliasers = (); } -impl cumulus_pallet_parachain_system::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type OnSystemEvent = (); - type SelfParaId = (); - type OutboundXcmpMessageSource = XcmpQueue; - type DmpMessageHandler = (); - type ReservedDmpWeight = (); - type XcmpMessageHandler = XcmpQueue; - type ReservedXcmpWeight = (); - type CheckAssociatedRelayNumber = AnyRelayNumber; -} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; - type VersionWrapper = (); - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToCallOrigin; - type WeightInfo = (); - type PriceForSiblingDelivery = NoPriceForMessageDelivery; -} - -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; -} - impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -209,11 +148,6 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -238,8 +172,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; @@ -254,7 +186,7 @@ impl Convert for AccountIdToMultiLocation { } parameter_types! { - pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); + pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(MsgQueue::get().into()))); pub const MaxAssetsForTransfer: usize = 3; } @@ -302,6 +234,11 @@ impl orml_xcm::Config for Runtime { type SovereignOrigin = EnsureRoot; } +impl orml_xcm_mock_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + type Block = frame_system::mocking::MockBlock; construct_runtime!( @@ -309,10 +246,7 @@ construct_runtime!( System: frame_system, Balances: pallet_balances, - ParachainInfo: parachain_info, - ParachainSystem: cumulus_pallet_parachain_system, - XcmpQueue: cumulus_pallet_xcmp_queue, - DmpQueue: cumulus_pallet_dmp_queue, + MsgQueue: orml_xcm_mock_message_queue, CumulusXcm: cumulus_pallet_xcm, Tokens: orml_tokens, diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index 549ab4423..9399d47bf 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -1,18 +1,13 @@ use super::{Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter}; use crate as orml_xtokens; -use cumulus_pallet_parachain_system::AnyRelayNumber; -use cumulus_primitives_core::ParaId; use frame_support::{ - construct_runtime, match_types, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing}, - weights::constants::WEIGHT_REF_TIME_PER_SECOND, + construct_runtime, derive_impl, match_types, parameter_types, + traits::{ConstU128, ConstU32, Everything, Get, Nothing}, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; -use sp_core::H256; use sp_runtime::{ traits::{Convert, IdentityLookup}, AccountId32, BoundedVec, @@ -34,30 +29,12 @@ use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset} pub type AccountId = AccountId32; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { @@ -98,18 +75,10 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); - pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -} - -impl parachain_info::Config for Runtime {} - -parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = - X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); + X2(GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::get().into())); } pub type LocationToAccountId = ( @@ -137,7 +106,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< (), >; -pub type XcmRouter = ParachainXcmRouter; +pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); parameter_types! { @@ -175,36 +144,6 @@ impl Config for XcmConfig { type Aliasers = (); } -impl cumulus_pallet_parachain_system::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type OnSystemEvent = (); - type SelfParaId = (); - type OutboundXcmpMessageSource = XcmpQueue; - type DmpMessageHandler = (); - type ReservedDmpWeight = (); - type XcmpMessageHandler = XcmpQueue; - type ReservedXcmpWeight = (); - type CheckAssociatedRelayNumber = AnyRelayNumber; -} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; - type VersionWrapper = (); - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToCallOrigin; - type WeightInfo = (); - type PriceForSiblingDelivery = NoPriceForMessageDelivery; -} - -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; -} - impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -212,11 +151,6 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -241,8 +175,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; @@ -330,7 +262,7 @@ impl Convert> for RelativeCurrencyIdConvert { let mut d: Vec = "D".into(); d.resize(32, 0); - let self_para_id: u32 = ParachainInfo::parachain_id().into(); + let self_para_id: u32 = MsgQueue::get().into(); if l == MultiLocation::parent() { return Some(CurrencyId::R); } @@ -425,6 +357,11 @@ impl orml_xcm::Config for Runtime { type SovereignOrigin = EnsureRoot; } +impl orml_xcm_mock_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + type Block = frame_system::mocking::MockBlock; construct_runtime!( @@ -432,10 +369,7 @@ construct_runtime!( System: frame_system, Balances: pallet_balances, - ParachainInfo: parachain_info, - ParachainSystem: cumulus_pallet_parachain_system, - XcmpQueue: cumulus_pallet_xcmp_queue, - DmpQueue: cumulus_pallet_dmp_queue, + MsgQueue: orml_xcm_mock_message_queue, CumulusXcm: cumulus_pallet_xcm, Tokens: orml_tokens, diff --git a/xtokens/src/mock/para_teleport.rs b/xtokens/src/mock/para_teleport.rs index dd63753f3..b5a16ad7d 100644 --- a/xtokens/src/mock/para_teleport.rs +++ b/xtokens/src/mock/para_teleport.rs @@ -1,18 +1,13 @@ use super::{AllowTopLevelPaidExecution, Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter}; use crate as orml_xtokens; -use cumulus_pallet_parachain_system::AnyRelayNumber; -use cumulus_primitives_core::ParaId; use frame_support::{ - construct_runtime, match_types, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything, Get, Nothing}, - weights::constants::WEIGHT_REF_TIME_PER_SECOND, + construct_runtime, derive_impl, match_types, parameter_types, + traits::{ConstU128, ConstU32, Everything, Get, Nothing}, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; -use sp_core::H256; use sp_runtime::{ traits::{Convert, IdentityLookup}, AccountId32, @@ -32,30 +27,12 @@ use orml_xcm_support::{DisabledParachainFee, IsNativeConcrete, MultiNativeAsset} pub type AccountId = AccountId32; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { @@ -96,18 +73,10 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); - pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -} - -impl parachain_info::Config for Runtime {} - -parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = - X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); + X2(GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::get().into())); } pub type LocationToAccountId = ( @@ -135,7 +104,7 @@ pub type LocalAssetTransactor = MultiTeleportCurrencyAdapter< (), >; -pub type XcmRouter = ParachainXcmRouter; +pub type XcmRouter = ParachainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecution); parameter_types! { @@ -173,36 +142,6 @@ impl Config for XcmConfig { type Aliasers = (); } -impl cumulus_pallet_parachain_system::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type OnSystemEvent = (); - type SelfParaId = (); - type OutboundXcmpMessageSource = XcmpQueue; - type DmpMessageHandler = (); - type ReservedDmpWeight = (); - type XcmpMessageHandler = XcmpQueue; - type ReservedXcmpWeight = (); - type CheckAssociatedRelayNumber = AnyRelayNumber; -} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; - type VersionWrapper = (); - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToCallOrigin; - type WeightInfo = (); - type PriceForSiblingDelivery = NoPriceForMessageDelivery; -} - -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; -} - impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -210,11 +149,6 @@ impl cumulus_pallet_xcm::Config for Runtime { pub type LocalOriginToLocation = SignedToAccountId32; -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -239,8 +173,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; } pub struct AccountIdToMultiLocation; @@ -255,7 +187,7 @@ impl Convert for AccountIdToMultiLocation { } parameter_types! { - pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); + pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(MsgQueue::get().into()))); pub const MaxAssetsForTransfer: usize = 3; } @@ -293,6 +225,11 @@ impl orml_xcm::Config for Runtime { type SovereignOrigin = EnsureRoot; } +impl orml_xcm_mock_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + type Block = frame_system::mocking::MockBlock; construct_runtime!( @@ -300,10 +237,7 @@ construct_runtime!( System: frame_system, Balances: pallet_balances, - ParachainInfo: parachain_info, - ParachainSystem: cumulus_pallet_parachain_system, - XcmpQueue: cumulus_pallet_xcmp_queue, - DmpQueue: cumulus_pallet_dmp_queue, + MsgQueue: orml_xcm_mock_message_queue, CumulusXcm: cumulus_pallet_xcm, Tokens: orml_tokens, diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index da78f8c76..4e8747d3a 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -1,10 +1,9 @@ use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing, ProcessMessage, ProcessMessageError}, + construct_runtime, derive_impl, parameter_types, + traits::{ConstU128, ConstU32, Everything, Nothing, ProcessMessage, ProcessMessageError}, weights::{IdentityFee, WeightMeter}, }; use frame_system::EnsureRoot; -use sp_core::H256; use sp_runtime::{traits::IdentityLookup, AccountId32}; use crate::Weight; @@ -17,38 +16,20 @@ use polkadot_runtime_parachains::{ use xcm::v3::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, - CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, + FixedWeightBounds, FungibleAdapter, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{Config, XcmExecutor}; pub type AccountId = AccountId32; pub type Balance = u128; +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { @@ -85,8 +66,7 @@ pub type SovereignAccountOf = ( AccountId32Aliases, ); -pub type LocalAssetTransactor = - XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; +pub type LocalAssetTransactor = FungibleAdapter, SovereignAccountOf, AccountId, ()>; type LocalOriginConverter = ( SovereignSignedViaLocation, @@ -142,11 +122,6 @@ impl Config for XcmConfig { pub type LocalOriginToLocation = SignedToAccountId32; -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; @@ -172,8 +147,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; } impl origin::Config for Runtime {}