Skip to content

Commit

Permalink
Frame Pallets: Clean a lot of test setups (paritytech#4642)
Browse files Browse the repository at this point in the history
<img width="484" alt="Screenshot 2024-05-30 at 10 30 41"
src="https://github.com/paritytech/polkadot-sdk/assets/5588131/92ece1d0-cda3-46cf-9f46-4026c565b52d">

---------

Co-authored-by: Dónal Murray <donal.murray@parity.io>
  • Loading branch information
2 people authored and TarekkMA committed Aug 2, 2024
1 parent 2eddc6f commit 9bcdb80
Show file tree
Hide file tree
Showing 26 changed files with 26 additions and 479 deletions.
2 changes: 1 addition & 1 deletion bridges/modules/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ construct_runtime! {
}
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
}
Expand Down
17 changes: 2 additions & 15 deletions bridges/snowbridge/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
use super::*;

use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, Everything},
weights::IdentityFee,
};
use frame_support::{derive_impl, parameter_types, traits::ConstU32, weights::IdentityFee};
use hex_literal::hex;
use snowbridge_beacon_primitives::{
types::deneb, BeaconHeader, ExecutionProof, Fork, ForkVersions, VersionedExecutionPayloadHeader,
Expand All @@ -19,7 +15,7 @@ use snowbridge_core::{
use snowbridge_router_primitives::inbound::MessageToXcm;
use sp_core::{H160, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
traits::{IdentifyAccount, IdentityLookup, Verify},
BuildStorage, FixedU128, MultiSignature,
};
use sp_std::{convert::From, default::Default};
Expand Down Expand Up @@ -47,18 +43,9 @@ type Balance = u128;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u128>;
type Nonce = u64;
type Block = Block;
}

Expand Down
26 changes: 1 addition & 25 deletions cumulus/pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ use frame_support::{
};
use frame_system as system;
use frame_system::EnsureSignedBy;
use sp_core::H256;
use sp_runtime::{
testing::UintAuthorityId,
traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},
BuildStorage, RuntimeAppPublic,
};
use sp_runtime::{testing::UintAuthorityId, traits::OpaqueKeys, BuildStorage, RuntimeAppPublic};

type Block = frame_system::mocking::MockBlock<Test>;

Expand All @@ -51,28 +46,9 @@ parameter_types! {

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/conviction-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Contains<RuntimeCall> for BaseFilter {

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type Block = Block;
type AccountData = pallet_balances::AccountData<u64>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl pallet_migrations::Config for Runtime {
type MaxServiceWeight = MigratorServiceWeight;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type Block = Block;
type MultiBlockMigrator = Migrator;
Expand Down
19 changes: 1 addition & 18 deletions substrate/frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use frame_support::{
traits::{ConstU64, Currency},
weights::constants::WEIGHT_REF_TIME_PER_SECOND,
};
use sp_runtime::{
traits::{Convert, IdentityLookup},
BuildStorage,
};
use sp_runtime::{traits::IdentityLookup, BuildStorage};

use pallet_staking::{Exposure, IndividualExposure, StakerStatus};
use sp_std::prelude::*;
Expand Down Expand Up @@ -147,20 +144,6 @@ impl pallet_staking::Config for Runtime {
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
}

pub struct BalanceToU256;
impl Convert<Balance, sp_core::U256> for BalanceToU256 {
fn convert(n: Balance) -> sp_core::U256 {
n.into()
}
}

pub struct U256ToBalance;
impl Convert<sp_core::U256, Balance> for U256ToBalance {
fn convert(n: sp_core::U256) -> Balance {
n.try_into().unwrap()
}
}

parameter_types! {
pub static Deposit: u128 = 7;
pub static BatchSize: u32 = 1;
Expand Down
24 changes: 1 addition & 23 deletions substrate/frame/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ use frame_support::{
weights::Weight,
};
use pallet_session::historical as pallet_session_historical;
use sp_core::H256;
use sp_runtime::{
testing::{TestXt, UintAuthorityId},
traits::{BlakeTwo256, ConvertInto, IdentityLookup},
traits::ConvertInto,
BuildStorage, Permill,
};
use sp_staking::{
Expand Down Expand Up @@ -114,28 +113,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}

parameter_types! {
Expand Down
24 changes: 1 addition & 23 deletions substrate/frame/indices/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
#![cfg(test)]

use crate::{self as pallet_indices, Config};
use frame_support::{
derive_impl,
traits::{ConstU32, ConstU64},
};
use sp_core::H256;
use frame_support::{derive_impl, traits::ConstU64};
use sp_runtime::BuildStorage;

type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -40,28 +36,10 @@ frame_support::construct_runtime!(

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = Indices;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}

impl pallet_balances::Config for Test {
Expand Down
20 changes: 0 additions & 20 deletions substrate/frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,15 @@ use sp_runtime::{
};

type AccountId = u128;
type Nonce = u32;
type BlockNumber = u64;
type Balance = u128;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = Nonce;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_timestamp::Config for Runtime {
Expand Down
18 changes: 0 additions & 18 deletions substrate/frame/nomination-pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,29 +240,11 @@ impl sp_staking::StakingInterface for StakingMock {

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type SS58Prefix = ();
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type DbWeight = ();
type BlockLength = ();
type BlockWeights = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
Expand Down
18 changes: 0 additions & 18 deletions substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,11 @@ pub(crate) const POOL1_REWARD: AccountId = 20397359637244482196168876781421u128;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = Nonce;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_timestamp::Config for Runtime {
Expand Down
20 changes: 0 additions & 20 deletions substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use sp_runtime::{
};

type AccountId = u128;
type Nonce = u32;
type BlockNumber = u64;
type Balance = u128;

Expand All @@ -40,29 +39,10 @@ pub(crate) const POOL1_REWARD: AccountId = 20397359637244482196168876781421u128;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = Nonce;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_timestamp::Config for Runtime {
Expand Down
23 changes: 0 additions & 23 deletions substrate/frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,16 @@ use frame_system as system;
use pallet_session::historical as pallet_session_historical;
use sp_runtime::{
testing::{Header, UintAuthorityId},
traits::IdentityLookup,
BuildStorage, Perbill,
};

type AccountId = u64;
type Nonce = u32;
type Balance = u64;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = Nonce;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_balances::Config for Test {
Expand Down
Loading

0 comments on commit 9bcdb80

Please sign in to comment.