Skip to content

Commit

Permalink
Use derive_impl and DefaulConfig in mocks (#2658)
Browse files Browse the repository at this point in the history
* Use `derive_impl` in mocks
  • Loading branch information
dastansam authored Apr 1, 2024
1 parent 80a700a commit b239753
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 351 deletions.
39 changes: 7 additions & 32 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use core::mem;
use domain_runtime_primitives::opaque::Header as DomainHeader;
use domain_runtime_primitives::BlockNumber as DomainBlockNumber;
use frame_support::dispatch::{DispatchInfo, RawOrigin};
use frame_support::traits::{ConstU16, ConstU32, ConstU64, Currency, Hooks, VariantCount};
use frame_support::traits::{ConstU64, Currency, Hooks, VariantCount};
use frame_support::weights::constants::ParityDbWeight;
use frame_support::weights::{IdentityFee, Weight};
use frame_support::{assert_err, assert_ok, parameter_types, PalletId};
use frame_support::{assert_err, assert_ok, derive_impl, parameter_types, PalletId};
use frame_system::mocking::MockUncheckedExtrinsic;
use frame_system::pallet_prelude::*;
use scale_info::TypeInfo;
Expand Down Expand Up @@ -76,31 +76,14 @@ type BlockNumber = u64;
type Hash = H256;
type AccountId = u128;

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

parameter_types! {
Expand Down Expand Up @@ -157,21 +140,13 @@ parameter_types! {
pub const ExistentialDeposit: Balance = 1;
}

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
impl pallet_balances::Config for Test {
type RuntimeFreezeReason = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = HoldIdentifier;
type MaxHolds = MaxHolds;
type DustRemoval = ();
}

parameter_types! {
Expand Down
29 changes: 2 additions & 27 deletions crates/pallet-feeds/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::feed_processor::{FeedObjectMapping, FeedProcessor, FeedProcessor as FeedProcessorT};
use crate::{self as pallet_feeds};
use codec::{Compact, CompactLen, Decode, Encode};
use frame_support::parameter_types;
use frame_support::traits::{ConstU16, ConstU32, ConstU64};
use frame_support::{derive_impl, parameter_types};
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::BuildStorage;

type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -18,31 +15,9 @@ frame_support::construct_runtime!(
}
);

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
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 RuntimeTask = RuntimeTask;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}

parameter_types! {
Expand Down
29 changes: 2 additions & 27 deletions crates/pallet-grandpa-finality-verifier/src/tests/mock.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use frame_support::weights::Weight;
use frame_support::{construct_runtime, parameter_types};
use sp_runtime::testing::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use frame_support::{construct_runtime, derive_impl, parameter_types};
use sp_runtime::Perbill;

type AccountId = u64;
pub(crate) type ChainId = u64;
type Block = frame_system::mocking::MockBlock<TestRuntime>;

Expand All @@ -24,31 +21,9 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

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

impl grandpa::Config for TestRuntime {
Expand Down
33 changes: 2 additions & 31 deletions crates/pallet-object-store/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use frame_support::parameter_types;
use frame_support::traits::{ConstU16, ConstU32, ConstU64};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use frame_support::derive_impl;
use sp_runtime::BuildStorage;

type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -13,35 +10,9 @@ frame_support::construct_runtime!(
}
);

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
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 RuntimeTask = RuntimeTask;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}

parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}

impl crate::Config for Test {
Expand Down
28 changes: 3 additions & 25 deletions crates/pallet-offences-subspace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
use crate as pallet_offences_subspace;
use crate::Config;
use codec::Encode;
use frame_support::traits::{ConstU32, ConstU64};
use frame_support::derive_impl;
use frame_support::weights::constants::ParityDbWeight;
use frame_support::weights::Weight;
use sp_consensus_subspace::offence::{self, Kind, OffenceDetails};
use sp_consensus_subspace::FarmerPublicKey;
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::{BuildStorage, Perbill};
use std::cell::RefCell;

Expand Down Expand Up @@ -59,31 +58,10 @@ frame_support::construct_runtime!(
}
);

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

impl Config for Runtime {
Expand Down
46 changes: 9 additions & 37 deletions crates/pallet-rewards/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#![allow(missing_debug_implementations)]

use frame_support::traits::{ConstU128, ConstU16, ConstU32, ConstU64};
use sp_core::H256;
use sp_runtime::traits::{parameter_types, BlakeTwo256, IdentityLookup};
use frame_support::derive_impl;
use frame_support::traits::{ConstU128, ConstU32};
use sp_runtime::traits::parameter_types;
use subspace_runtime_primitives::{
FindBlockRewardAddress, FindVotingRewardAddresses, RewardsEnabled,
};

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

frame_support::construct_runtime!(
pub struct Test {
Expand All @@ -17,48 +18,19 @@ frame_support::construct_runtime!(
}
);

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
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 RuntimeTask = RuntimeTask;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
type AccountData = pallet_balances::AccountData<Balance>;
}

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
impl pallet_balances::Config for Test {
type RuntimeFreezeReason = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = u128;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type ExistentialDeposit = ConstU128<1>;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
type DustRemoval = ();
}

parameter_types! {
Expand Down
Loading

0 comments on commit b239753

Please sign in to comment.