Skip to content

Commit 7e2f985

Browse files
syan095Roy Yang
and
Roy Yang
authored
Refactor/paramter types (#725)
* WIP Refactor parameter-types * Replaced parameter_types! with ConstU types * Replaced paramter types with ConstU types Co-authored-by: Roy Yang <[email protected]>
1 parent 2b5d4ce commit 7e2f985

File tree

16 files changed

+111
-222
lines changed

16 files changed

+111
-222
lines changed

auction/src/mock.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
#![cfg(test)]
44

55
use super::*;
6-
use frame_support::{construct_runtime, parameter_types, traits::Everything};
6+
use frame_support::{
7+
construct_runtime,
8+
traits::{ConstU64, Everything},
9+
};
710
use orml_traits::OnNewBidResult;
811
use sp_core::H256;
912
use sp_runtime::{testing::Header, traits::IdentityLookup};
1013

1114
use crate as auction;
1215

13-
parameter_types! {
14-
pub const BlockHashCount: u64 = 250;
15-
}
16-
1716
pub type AccountId = u128;
1817
pub type Balance = u64;
1918
pub type BlockNumber = u64;
@@ -30,7 +29,7 @@ impl frame_system::Config for Runtime {
3029
type Lookup = IdentityLookup<Self::AccountId>;
3130
type Header = Header;
3231
type Event = Event;
33-
type BlockHashCount = BlockHashCount;
32+
type BlockHashCount = ConstU64<250>;
3433
type BlockWeights = ();
3534
type BlockLength = ();
3635
type Version = ();
@@ -43,7 +42,7 @@ impl frame_system::Config for Runtime {
4342
type SystemWeightInfo = ();
4443
type SS58Prefix = ();
4544
type OnSetCode = ();
46-
type MaxConsumers = frame_support::traits::ConstU32<16>;
45+
type MaxConsumers = ConstU32<16>;
4746
}
4847

4948
pub struct Handler;

authority/src/mock.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::*;
66
use codec::{Decode, Encode};
77
use frame_support::{
88
parameter_types,
9-
traits::{EqualPrivilegeOnly, Everything},
9+
traits::{ConstU64, EqualPrivilegeOnly, Everything},
1010
weights::Weight,
1111
};
1212
use frame_system::{ensure_root, ensure_signed, EnsureRoot};
@@ -23,7 +23,6 @@ pub type AccountId = u128;
2323
pub type BlockNumber = u64;
2424

2525
parameter_types! {
26-
pub const BlockHashCount: u64 = 250;
2726
pub BlockWeights: frame_system::limits::BlockWeights =
2827
frame_system::limits::BlockWeights::simple_max(2_000_000_000_000);
2928
}
@@ -39,7 +38,7 @@ impl frame_system::Config for Runtime {
3938
type Lookup = IdentityLookup<Self::AccountId>;
4039
type Header = Header;
4140
type Event = Event;
42-
type BlockHashCount = BlockHashCount;
41+
type BlockHashCount = ConstU64<250>;
4342
type BlockWeights = ();
4443
type BlockLength = ();
4544
type Version = ();
@@ -52,7 +51,7 @@ impl frame_system::Config for Runtime {
5251
type SystemWeightInfo = ();
5352
type SS58Prefix = ();
5453
type OnSetCode = ();
55-
type MaxConsumers = frame_support::traits::ConstU32<16>;
54+
type MaxConsumers = ConstU32<16>;
5655
}
5756

5857
parameter_types! {

bencher/test/src/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl frame_system::Config for Runtime {
5454
type SystemWeightInfo = ();
5555
type SS58Prefix = ();
5656
type OnSetCode = ();
57-
type MaxConsumers = frame_support::traits::ConstU32<16>;
57+
type MaxConsumers = ConstU32<16>;
5858
}
5959

6060
impl crate::pallet::Config for Runtime {}

benchmarking/src/tests.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use super::*;
66
use frame_benchmarking::account;
7-
use frame_support::{assert_err, assert_ok, construct_runtime, ensure, traits::Everything};
7+
use frame_support::{
8+
assert_err, assert_ok, construct_runtime, ensure,
9+
traits::{ConstU32, Everything},
10+
};
811
use frame_system::RawOrigin;
912
use sp_runtime::{
1013
testing::{Header, H256},
@@ -72,7 +75,7 @@ impl frame_system::Config for Test {
7275
type SystemWeightInfo = ();
7376
type SS58Prefix = ();
7477
type OnSetCode = ();
75-
type MaxConsumers = frame_support::traits::ConstU32<16>;
78+
type MaxConsumers = ConstU32<16>;
7679
}
7780

7881
impl Config for Test {}

currencies/src/mock.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use super::*;
66
use frame_support::{
77
construct_runtime, parameter_types,
8-
traits::{Everything, Nothing},
8+
traits::{ConstU32, ConstU64, Everything, Nothing},
99
PalletId,
1010
};
1111
use orml_traits::parameter_type_with_key;
@@ -18,10 +18,6 @@ use sp_runtime::{
1818

1919
use crate as currencies;
2020

21-
parameter_types! {
22-
pub const BlockHashCount: u64 = 250;
23-
}
24-
2521
pub type AccountId = AccountId32;
2622
impl frame_system::Config for Runtime {
2723
type Origin = Origin;
@@ -34,7 +30,7 @@ impl frame_system::Config for Runtime {
3430
type Lookup = IdentityLookup<Self::AccountId>;
3531
type Header = Header;
3632
type Event = Event;
37-
type BlockHashCount = BlockHashCount;
33+
type BlockHashCount = ConstU64<250>;
3834
type BlockWeights = ();
3935
type BlockLength = ();
4036
type Version = ();
@@ -47,21 +43,17 @@ impl frame_system::Config for Runtime {
4743
type SystemWeightInfo = ();
4844
type SS58Prefix = ();
4945
type OnSetCode = ();
50-
type MaxConsumers = frame_support::traits::ConstU32<16>;
46+
type MaxConsumers = ConstU32<16>;
5147
}
5248

5349
type CurrencyId = u32;
5450
type Balance = u64;
5551

56-
parameter_types! {
57-
pub const ExistentialDeposit: u64 = 2;
58-
}
59-
6052
impl pallet_balances::Config for Runtime {
6153
type Balance = Balance;
6254
type DustRemoval = ();
6355
type Event = Event;
64-
type ExistentialDeposit = ExistentialDeposit;
56+
type ExistentialDeposit = ConstU64<2>;
6557
type AccountStore = frame_system::Pallet<Runtime>;
6658
type MaxLocks = ();
6759
type MaxReserves = ();
@@ -77,7 +69,6 @@ parameter_type_with_key! {
7769

7870
parameter_types! {
7971
pub DustAccount: AccountId = PalletId(*b"orml/dst").into_account();
80-
pub MaxLocks: u32 = 100_000;
8172
}
8273

8374
impl orml_tokens::Config for Runtime {
@@ -88,7 +79,7 @@ impl orml_tokens::Config for Runtime {
8879
type WeightInfo = ();
8980
type ExistentialDeposits = ExistentialDeposits;
9081
type OnDust = orml_tokens::TransferDust<Runtime, DustAccount>;
91-
type MaxLocks = MaxLocks;
82+
type MaxLocks = ConstU32<100_000>;
9283
type DustRemovalWhitelist = Nothing;
9384
}
9485

gradually-update/src/mock.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
#![cfg(test)]
44

55
use super::*;
6-
use frame_support::{construct_runtime, parameter_types, traits::Everything};
6+
use frame_support::{
7+
construct_runtime,
8+
traits::{ConstU32, ConstU64, Everything},
9+
};
710
use sp_core::H256;
811
use sp_runtime::{testing::Header, traits::IdentityLookup};
912

1013
use crate as gradually_update;
1114

12-
parameter_types! {
13-
pub const BlockHashCount: u64 = 250;
14-
}
15-
1615
pub type AccountId = u128;
1716
pub type BlockNumber = u64;
1817

@@ -27,7 +26,7 @@ impl frame_system::Config for Runtime {
2726
type Lookup = IdentityLookup<Self::AccountId>;
2827
type Header = Header;
2928
type Event = Event;
30-
type BlockHashCount = BlockHashCount;
29+
type BlockHashCount = ConstU64<250>;
3130
type BlockWeights = ();
3231
type BlockLength = ();
3332
type Version = ();
@@ -40,24 +39,17 @@ impl frame_system::Config for Runtime {
4039
type SystemWeightInfo = ();
4140
type SS58Prefix = ();
4241
type OnSetCode = ();
43-
type MaxConsumers = frame_support::traits::ConstU32<16>;
44-
}
45-
46-
parameter_types! {
47-
pub const UpdateFrequency: BlockNumber = 10;
48-
pub MaxGraduallyUpdate: u32 = 3;
49-
pub MaxStorageKeyBytes: u32 = 100_000;
50-
pub MaxStorageValueBytes: u32 = 100_000;
42+
type MaxConsumers = ConstU32<16>;
5143
}
5244

5345
impl Config for Runtime {
5446
type Event = Event;
55-
type UpdateFrequency = UpdateFrequency;
47+
type UpdateFrequency = ConstU64<10>;
5648
type DispatchOrigin = frame_system::EnsureRoot<AccountId>;
5749
type WeightInfo = ();
58-
type MaxGraduallyUpdate = MaxGraduallyUpdate;
59-
type MaxStorageKeyBytes = MaxStorageKeyBytes;
60-
type MaxStorageValueBytes = MaxStorageValueBytes;
50+
type MaxGraduallyUpdate = ConstU32<3>;
51+
type MaxStorageKeyBytes = ConstU32<100_000>;
52+
type MaxStorageValueBytes = ConstU32<100_000>;
6153
}
6254

6355
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;

nft/src/mock.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
33
#![cfg(test)]
44

5-
use frame_support::{construct_runtime, parameter_types, traits::Everything};
5+
use frame_support::{
6+
construct_runtime,
7+
traits::{ConstU32, ConstU64, Everything},
8+
};
69
use sp_core::H256;
710
use sp_runtime::{testing::Header, traits::IdentityLookup};
811

912
use super::*;
1013

1114
use crate as nft;
1215

13-
parameter_types! {
14-
pub const BlockHashCount: u64 = 250;
15-
}
16-
1716
pub type AccountId = u128;
1817
pub type BlockNumber = u64;
1918

@@ -28,7 +27,7 @@ impl frame_system::Config for Runtime {
2827
type Lookup = IdentityLookup<Self::AccountId>;
2928
type Header = Header;
3029
type Event = Event;
31-
type BlockHashCount = BlockHashCount;
30+
type BlockHashCount = ConstU64<250>;
3231
type BlockWeights = ();
3332
type BlockLength = ();
3433
type Version = ();
@@ -41,21 +40,16 @@ impl frame_system::Config for Runtime {
4140
type SystemWeightInfo = ();
4241
type SS58Prefix = ();
4342
type OnSetCode = ();
44-
type MaxConsumers = frame_support::traits::ConstU32<16>;
45-
}
46-
47-
parameter_types! {
48-
pub const MaxClassMetadata: u32 = 1;
49-
pub const MaxTokenMetadata: u32 = 1;
43+
type MaxConsumers = ConstU32<16>;
5044
}
5145

5246
impl Config for Runtime {
5347
type ClassId = u64;
5448
type TokenId = u64;
5549
type ClassData = ();
5650
type TokenData = ();
57-
type MaxClassMetadata = MaxClassMetadata;
58-
type MaxTokenMetadata = MaxTokenMetadata;
51+
type MaxClassMetadata = ConstU32<1>;
52+
type MaxTokenMetadata = ConstU32<1>;
5953
}
6054

6155
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;

oracle/src/mock.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44

55
use frame_support::{
66
construct_runtime, parameter_types,
7-
traits::{Everything, SortedMembers},
7+
traits::{ConstU32, ConstU64, Everything, SortedMembers},
88
};
99
use sp_core::H256;
1010
use sp_runtime::{
@@ -22,9 +22,6 @@ pub type AccountId = u128;
2222
type Key = u32;
2323
type Value = u32;
2424

25-
parameter_types! {
26-
pub const BlockHashCount: u64 = 250;
27-
}
2825
impl frame_system::Config for Test {
2926
type Origin = Origin;
3027
type Call = Call;
@@ -36,7 +33,7 @@ impl frame_system::Config for Test {
3633
type Lookup = IdentityLookup<Self::AccountId>;
3734
type Header = Header;
3835
type Event = Event;
39-
type BlockHashCount = BlockHashCount;
36+
type BlockHashCount = ConstU64<250>;
4037
type BlockWeights = ();
4138
type BlockLength = ();
4239
type Version = ();
@@ -49,7 +46,7 @@ impl frame_system::Config for Test {
4946
type SystemWeightInfo = ();
5047
type SS58Prefix = ();
5148
type OnSetCode = ();
52-
type MaxConsumers = frame_support::traits::ConstU32<16>;
49+
type MaxConsumers = ConstU32<16>;
5350
}
5451

5552
thread_local! {
@@ -72,8 +69,6 @@ impl Timestamp {
7269
}
7370

7471
parameter_types! {
75-
pub const MinimumCount: u32 = 3;
76-
pub const ExpiresIn: u32 = 600;
7772
pub const RootOperatorAccountId: AccountId = 4;
7873
pub static OracleMembers: Vec<AccountId> = vec![1, 2, 3];
7974
}
@@ -86,21 +81,17 @@ impl SortedMembers<AccountId> for Members {
8681
}
8782
}
8883

89-
parameter_types! {
90-
pub const MaxHasDispatchedSize: u32 = 100;
91-
}
92-
9384
impl Config for Test {
9485
type Event = Event;
9586
type OnNewData = ();
96-
type CombineData = DefaultCombineData<Self, MinimumCount, ExpiresIn>;
87+
type CombineData = DefaultCombineData<Self, ConstU32<3>, ConstU32<600>>;
9788
type Time = Timestamp;
9889
type OracleKey = Key;
9990
type OracleValue = Value;
10091
type RootOperatorAccountId = RootOperatorAccountId;
10192
type Members = Members;
10293
type WeightInfo = ();
103-
type MaxHasDispatchedSize = MaxHasDispatchedSize;
94+
type MaxHasDispatchedSize = ConstU32<100>;
10495
}
10596

10697
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;

0 commit comments

Comments
 (0)