Skip to content

Commit b239753

Browse files
authored
Use derive_impl and DefaulConfig in mocks (#2658)
* Use `derive_impl` in mocks
1 parent 80a700a commit b239753

File tree

11 files changed

+49
-351
lines changed

11 files changed

+49
-351
lines changed

crates/pallet-domains/src/tests.rs

+7-32
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use core::mem;
1212
use domain_runtime_primitives::opaque::Header as DomainHeader;
1313
use domain_runtime_primitives::BlockNumber as DomainBlockNumber;
1414
use frame_support::dispatch::{DispatchInfo, RawOrigin};
15-
use frame_support::traits::{ConstU16, ConstU32, ConstU64, Currency, Hooks, VariantCount};
15+
use frame_support::traits::{ConstU64, Currency, Hooks, VariantCount};
1616
use frame_support::weights::constants::ParityDbWeight;
1717
use frame_support::weights::{IdentityFee, Weight};
18-
use frame_support::{assert_err, assert_ok, parameter_types, PalletId};
18+
use frame_support::{assert_err, assert_ok, derive_impl, parameter_types, PalletId};
1919
use frame_system::mocking::MockUncheckedExtrinsic;
2020
use frame_system::pallet_prelude::*;
2121
use scale_info::TypeInfo;
@@ -76,31 +76,14 @@ type BlockNumber = u64;
7676
type Hash = H256;
7777
type AccountId = u128;
7878

79+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
7980
impl frame_system::Config for Test {
80-
type BaseCallFilter = frame_support::traits::Everything;
81-
type BlockWeights = ();
82-
type BlockLength = ();
83-
type DbWeight = ParityDbWeight;
84-
type RuntimeOrigin = RuntimeOrigin;
85-
type RuntimeCall = RuntimeCall;
86-
type RuntimeTask = RuntimeTask;
87-
type Nonce = u64;
81+
type Block = Block;
8882
type Hash = Hash;
89-
type Hashing = BlakeTwo256;
9083
type AccountId = AccountId;
9184
type Lookup = IdentityLookup<Self::AccountId>;
92-
type Block = Block;
93-
type RuntimeEvent = RuntimeEvent;
94-
type BlockHashCount = ConstU64<2>;
95-
type Version = ();
96-
type PalletInfo = PalletInfo;
9785
type AccountData = pallet_balances::AccountData<Balance>;
98-
type OnNewAccount = ();
99-
type OnKilledAccount = ();
100-
type SystemWeightInfo = ();
101-
type SS58Prefix = ConstU16<42>;
102-
type OnSetCode = ();
103-
type MaxConsumers = ConstU32<16>;
86+
type DbWeight = ParityDbWeight;
10487
}
10588

10689
parameter_types! {
@@ -157,21 +140,13 @@ parameter_types! {
157140
pub const ExistentialDeposit: Balance = 1;
158141
}
159142

143+
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
160144
impl pallet_balances::Config for Test {
161-
type RuntimeFreezeReason = RuntimeFreezeReason;
162-
type MaxLocks = ();
163-
type MaxReserves = ();
164-
type ReserveIdentifier = [u8; 8];
165145
type Balance = Balance;
166-
type DustRemoval = ();
167-
type RuntimeEvent = RuntimeEvent;
168146
type ExistentialDeposit = ExistentialDeposit;
169147
type AccountStore = System;
170-
type WeightInfo = ();
171-
type FreezeIdentifier = ();
172-
type MaxFreezes = ();
173148
type RuntimeHoldReason = HoldIdentifier;
174-
type MaxHolds = MaxHolds;
149+
type DustRemoval = ();
175150
}
176151

177152
parameter_types! {

crates/pallet-feeds/src/mock.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use crate::feed_processor::{FeedObjectMapping, FeedProcessor, FeedProcessor as FeedProcessorT};
22
use crate::{self as pallet_feeds};
33
use codec::{Compact, CompactLen, Decode, Encode};
4-
use frame_support::parameter_types;
5-
use frame_support::traits::{ConstU16, ConstU32, ConstU64};
4+
use frame_support::{derive_impl, parameter_types};
65
use scale_info::TypeInfo;
7-
use sp_core::H256;
8-
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
96
use sp_runtime::BuildStorage;
107

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

18+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
2119
impl frame_system::Config for Test {
22-
type BaseCallFilter = frame_support::traits::Everything;
23-
type BlockWeights = ();
24-
type BlockLength = ();
25-
type DbWeight = ();
26-
type RuntimeOrigin = RuntimeOrigin;
27-
type RuntimeCall = RuntimeCall;
28-
type RuntimeTask = RuntimeTask;
29-
type Nonce = u64;
30-
type Hash = H256;
31-
type Hashing = BlakeTwo256;
32-
type AccountId = u64;
33-
type Lookup = IdentityLookup<Self::AccountId>;
3420
type Block = Block;
35-
type RuntimeEvent = RuntimeEvent;
36-
type BlockHashCount = ConstU64<250>;
37-
type Version = ();
38-
type PalletInfo = PalletInfo;
39-
type AccountData = ();
40-
type OnNewAccount = ();
41-
type OnKilledAccount = ();
42-
type SystemWeightInfo = ();
43-
type SS58Prefix = ConstU16<42>;
44-
type OnSetCode = ();
45-
type MaxConsumers = ConstU32<16>;
4621
}
4722

4823
parameter_types! {

crates/pallet-grandpa-finality-verifier/src/tests/mock.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use frame_support::weights::Weight;
2-
use frame_support::{construct_runtime, parameter_types};
3-
use sp_runtime::testing::H256;
4-
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
2+
use frame_support::{construct_runtime, derive_impl, parameter_types};
53
use sp_runtime::Perbill;
64

7-
type AccountId = u64;
85
pub(crate) type ChainId = u64;
96
type Block = frame_system::mocking::MockBlock<TestRuntime>;
107

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

24+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
2725
impl frame_system::Config for TestRuntime {
28-
type RuntimeOrigin = RuntimeOrigin;
29-
type Nonce = u64;
30-
type RuntimeCall = RuntimeCall;
31-
type RuntimeTask = RuntimeTask;
32-
type Hash = H256;
33-
type Hashing = BlakeTwo256;
34-
type AccountId = AccountId;
35-
type Lookup = IdentityLookup<Self::AccountId>;
3626
type Block = Block;
37-
type RuntimeEvent = ();
38-
type BlockHashCount = BlockHashCount;
39-
type Version = ();
40-
type PalletInfo = PalletInfo;
41-
type AccountData = ();
42-
type OnNewAccount = ();
43-
type OnKilledAccount = ();
44-
type BaseCallFilter = frame_support::traits::Everything;
45-
type SystemWeightInfo = ();
46-
type DbWeight = ();
47-
type BlockWeights = ();
48-
type BlockLength = ();
49-
type SS58Prefix = ();
50-
type OnSetCode = ();
51-
type MaxConsumers = frame_support::traits::ConstU32<16>;
5227
}
5328

5429
impl grandpa::Config for TestRuntime {

crates/pallet-object-store/src/mock.rs

+2-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use frame_support::parameter_types;
2-
use frame_support::traits::{ConstU16, ConstU32, ConstU64};
3-
use sp_core::H256;
4-
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
1+
use frame_support::derive_impl;
52
use sp_runtime::BuildStorage;
63

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

13+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
1614
impl frame_system::Config for Test {
17-
type BaseCallFilter = frame_support::traits::Everything;
18-
type BlockWeights = ();
19-
type BlockLength = ();
20-
type DbWeight = ();
21-
type RuntimeOrigin = RuntimeOrigin;
22-
type RuntimeCall = RuntimeCall;
23-
type RuntimeTask = RuntimeTask;
24-
type Nonce = u64;
25-
type Hash = H256;
26-
type Hashing = BlakeTwo256;
27-
type AccountId = u64;
28-
type Lookup = IdentityLookup<Self::AccountId>;
2915
type Block = Block;
30-
type RuntimeEvent = RuntimeEvent;
31-
type BlockHashCount = ConstU64<250>;
32-
type Version = ();
33-
type PalletInfo = PalletInfo;
34-
type AccountData = ();
35-
type OnNewAccount = ();
36-
type OnKilledAccount = ();
37-
type SystemWeightInfo = ();
38-
type SS58Prefix = ConstU16<42>;
39-
type OnSetCode = ();
40-
type MaxConsumers = ConstU32<16>;
41-
}
42-
43-
parameter_types! {
44-
pub const ExistentialDeposit: u64 = 1;
4516
}
4617

4718
impl crate::Config for Test {

crates/pallet-offences-subspace/src/mock.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
use crate as pallet_offences_subspace;
2222
use crate::Config;
2323
use codec::Encode;
24-
use frame_support::traits::{ConstU32, ConstU64};
24+
use frame_support::derive_impl;
2525
use frame_support::weights::constants::ParityDbWeight;
2626
use frame_support::weights::Weight;
2727
use sp_consensus_subspace::offence::{self, Kind, OffenceDetails};
2828
use sp_consensus_subspace::FarmerPublicKey;
2929
use sp_core::H256;
30-
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
3130
use sp_runtime::{BuildStorage, Perbill};
3231
use std::cell::RefCell;
3332

@@ -59,31 +58,10 @@ frame_support::construct_runtime!(
5958
}
6059
);
6160

61+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
6262
impl frame_system::Config for Runtime {
63-
type BaseCallFilter = frame_support::traits::Everything;
64-
type BlockWeights = ();
65-
type BlockLength = ();
66-
type DbWeight = ParityDbWeight;
67-
type RuntimeOrigin = RuntimeOrigin;
68-
type Nonce = u64;
69-
type RuntimeCall = RuntimeCall;
70-
type RuntimeTask = RuntimeTask;
71-
type Hash = H256;
72-
type Hashing = BlakeTwo256;
73-
type AccountId = u64;
74-
type Lookup = IdentityLookup<Self::AccountId>;
7563
type Block = Block;
76-
type RuntimeEvent = RuntimeEvent;
77-
type BlockHashCount = ConstU64<250>;
78-
type Version = ();
79-
type PalletInfo = PalletInfo;
80-
type AccountData = ();
81-
type OnNewAccount = ();
82-
type OnKilledAccount = ();
83-
type SystemWeightInfo = ();
84-
type SS58Prefix = ();
85-
type OnSetCode = ();
86-
type MaxConsumers = ConstU32<16>;
64+
type DbWeight = ParityDbWeight;
8765
}
8866

8967
impl Config for Runtime {

crates/pallet-rewards/src/mock.rs

+9-37
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#![allow(missing_debug_implementations)]
22

3-
use frame_support::traits::{ConstU128, ConstU16, ConstU32, ConstU64};
4-
use sp_core::H256;
5-
use sp_runtime::traits::{parameter_types, BlakeTwo256, IdentityLookup};
3+
use frame_support::derive_impl;
4+
use frame_support::traits::{ConstU128, ConstU32};
5+
use sp_runtime::traits::parameter_types;
66
use subspace_runtime_primitives::{
77
FindBlockRewardAddress, FindVotingRewardAddresses, RewardsEnabled,
88
};
99

1010
type Block = frame_system::mocking::MockBlock<Test>;
11+
type Balance = u128;
1112

1213
frame_support::construct_runtime!(
1314
pub struct Test {
@@ -17,48 +18,19 @@ frame_support::construct_runtime!(
1718
}
1819
);
1920

21+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
2022
impl frame_system::Config for Test {
21-
type BaseCallFilter = frame_support::traits::Everything;
22-
type BlockWeights = ();
23-
type BlockLength = ();
24-
type DbWeight = ();
25-
type RuntimeOrigin = RuntimeOrigin;
26-
type RuntimeCall = RuntimeCall;
27-
type RuntimeTask = RuntimeTask;
28-
type Nonce = u64;
29-
type Hash = H256;
30-
type Hashing = BlakeTwo256;
31-
type AccountId = u64;
32-
type Lookup = IdentityLookup<Self::AccountId>;
3323
type Block = Block;
34-
type RuntimeEvent = RuntimeEvent;
35-
type BlockHashCount = ConstU64<250>;
36-
type Version = ();
37-
type PalletInfo = PalletInfo;
38-
type AccountData = pallet_balances::AccountData<u128>;
39-
type OnNewAccount = ();
40-
type OnKilledAccount = ();
41-
type SystemWeightInfo = ();
42-
type SS58Prefix = ConstU16<42>;
43-
type OnSetCode = ();
44-
type MaxConsumers = ConstU32<16>;
24+
type AccountData = pallet_balances::AccountData<Balance>;
4525
}
4626

27+
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
4728
impl pallet_balances::Config for Test {
48-
type RuntimeFreezeReason = RuntimeFreezeReason;
49-
type MaxLocks = ();
50-
type MaxReserves = ();
51-
type ReserveIdentifier = [u8; 8];
52-
type Balance = u128;
53-
type DustRemoval = ();
54-
type RuntimeEvent = RuntimeEvent;
29+
type Balance = Balance;
5530
type ExistentialDeposit = ConstU128<1>;
5631
type AccountStore = System;
57-
type WeightInfo = ();
58-
type FreezeIdentifier = ();
59-
type MaxFreezes = ();
6032
type RuntimeHoldReason = ();
61-
type MaxHolds = ();
33+
type DustRemoval = ();
6234
}
6335

6436
parameter_types! {

0 commit comments

Comments
 (0)