Skip to content

Commit 376a3c4

Browse files
kianenigmaacatangiuKiChjang
authored
migrate alliance, fast-unstake and bags list to use derive-impl (paritytech#1636)
Moving a few pallets to the latest and greatest `derive_impl` to give it a try. Part of paritytech#171 --------- Co-authored-by: Adrian Catangiu <[email protected]> Co-authored-by: Keith Yeung <[email protected]>
1 parent b6bd08e commit 376a3c4

File tree

11 files changed

+33
-128
lines changed

11 files changed

+33
-128
lines changed

substrate/frame/alliance/src/mock.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use sp_runtime::{
2626
use sp_std::convert::{TryFrom, TryInto};
2727

2828
pub use frame_support::{
29-
assert_noop, assert_ok, ord_parameter_types, parameter_types,
29+
assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types,
3030
traits::{EitherOfDiverse, SortedMembers},
3131
BoundedVec,
3232
};
@@ -45,30 +45,11 @@ parameter_types! {
4545
pub BlockWeights: frame_system::limits::BlockWeights =
4646
frame_system::limits::BlockWeights::simple_max(Weight::MAX);
4747
}
48+
49+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
4850
impl frame_system::Config for Test {
49-
type BaseCallFilter = frame_support::traits::Everything;
50-
type BlockWeights = BlockWeights;
51-
type BlockLength = ();
52-
type RuntimeOrigin = RuntimeOrigin;
53-
type RuntimeCall = RuntimeCall;
54-
type Nonce = u64;
55-
type Hash = H256;
56-
type Hashing = BlakeTwo256;
57-
type AccountId = AccountId;
58-
type Lookup = IdentityLookup<Self::AccountId>;
5951
type Block = Block;
60-
type RuntimeEvent = RuntimeEvent;
61-
type BlockHashCount = BlockHashCount;
62-
type DbWeight = ();
63-
type Version = ();
64-
type PalletInfo = PalletInfo;
6552
type AccountData = pallet_balances::AccountData<AccountId>;
66-
type OnNewAccount = ();
67-
type OnKilledAccount = ();
68-
type SystemWeightInfo = ();
69-
type SS58Prefix = ();
70-
type OnSetCode = ();
71-
type MaxConsumers = frame_support::traits::ConstU32<16>;
7253
}
7354

7455
parameter_types! {

substrate/frame/bags-list/src/mock.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
use super::*;
2121
use crate::{self as bags_list};
2222
use frame_election_provider_support::VoteWeight;
23-
use frame_support::parameter_types;
23+
use frame_support::{derive_impl, parameter_types};
2424
use sp_runtime::BuildStorage;
2525
use std::collections::HashMap;
2626

27-
pub type AccountId = u32;
27+
pub type AccountId = <Runtime as frame_system::Config>::AccountId;
2828
pub type Balance = u32;
2929

3030
parameter_types! {
@@ -48,30 +48,10 @@ impl frame_election_provider_support::ScoreProvider<AccountId> for StakingMock {
4848
}
4949
}
5050

51+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
5152
impl frame_system::Config for Runtime {
52-
type SS58Prefix = ();
53-
type BaseCallFilter = frame_support::traits::Everything;
54-
type RuntimeOrigin = RuntimeOrigin;
55-
type Nonce = u64;
56-
type RuntimeCall = RuntimeCall;
57-
type Hash = sp_core::H256;
58-
type Hashing = sp_runtime::traits::BlakeTwo256;
59-
type AccountId = AccountId;
60-
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
6153
type Block = Block;
62-
type RuntimeEvent = RuntimeEvent;
63-
type BlockHashCount = ();
64-
type DbWeight = ();
65-
type BlockLength = ();
66-
type BlockWeights = ();
67-
type Version = ();
68-
type PalletInfo = PalletInfo;
6954
type AccountData = pallet_balances::AccountData<Balance>;
70-
type OnNewAccount = ();
71-
type OnKilledAccount = ();
72-
type SystemWeightInfo = ();
73-
type OnSetCode = ();
74-
type MaxConsumers = frame_support::traits::ConstU32<16>;
7555
}
7656

7757
parameter_types! {

substrate/frame/bags-list/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ mod pallet {
163163

164164
assert_eq!(Bag::<Runtime>::get(10).unwrap(), Bag::new(Some(1), Some(3), 10));
165165
assert_eq!(Bag::<Runtime>::get(1_000).unwrap(), Bag::new(Some(2), Some(2), 1_000));
166-
assert_eq!(get_list_as_ids(), vec![2u32, 1, 4, 3]);
166+
assert_eq!(get_list_as_ids(), vec![2u64, 1, 4, 3]);
167167

168168
// when
169169
StakingMock::set_score_of(&2, 10);
@@ -272,10 +272,10 @@ mod pallet {
272272
// given
273273
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![10, 11, 12])]);
274274
// 11 now has more weight than 10 and can be moved before it.
275-
StakingMock::set_score_of(&11u32, 17);
275+
StakingMock::set_score_of(&11u64, 17);
276276

277277
// when
278-
assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11u32, 10));
278+
assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11u64, 10));
279279

280280
// then
281281
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![11, 10, 12])]);

substrate/frame/balances/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub mod pallet {
216216
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
217217
pub mod config_preludes {
218218
use super::*;
219-
use frame_support::derive_impl;
219+
use frame_support::{derive_impl, traits::ConstU64};
220220

221221
pub struct TestDefaultConfig;
222222

@@ -227,12 +227,17 @@ pub mod pallet {
227227
impl DefaultConfig for TestDefaultConfig {
228228
#[inject_runtime_type]
229229
type RuntimeEvent = ();
230+
#[inject_runtime_type]
231+
type RuntimeHoldReason = ();
230232

231233
type Balance = u64;
234+
type ExistentialDeposit = ConstU64<1>;
232235

233236
type ReserveIdentifier = ();
234237
type FreezeIdentifier = ();
235238

239+
type DustRemoval = ();
240+
236241
type MaxLocks = ();
237242
type MaxReserves = ();
238243
type MaxFreezes = ();
@@ -249,6 +254,10 @@ pub mod pallet {
249254
type RuntimeEvent: From<Event<Self, I>>
250255
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
251256

257+
/// The overarching hold reason.
258+
#[pallet::no_default_bounds]
259+
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy;
260+
252261
/// Weight information for extrinsics in this pallet.
253262
type WeightInfo: WeightInfo;
254263

@@ -266,7 +275,7 @@ pub mod pallet {
266275
+ FixedPointOperand;
267276

268277
/// Handler for the unbalanced reduction when removing a dust account.
269-
#[pallet::no_default]
278+
#[pallet::no_default_bounds]
270279
type DustRemoval: OnUnbalanced<CreditOf<Self, I>>;
271280

272281
/// The minimum amount required to keep an account open. MUST BE GREATER THAN ZERO!
@@ -278,7 +287,7 @@ pub mod pallet {
278287
///
279288
/// Bottom line: Do yourself a favour and make it at least one!
280289
#[pallet::constant]
281-
#[pallet::no_default]
290+
#[pallet::no_default_bounds]
282291
type ExistentialDeposit: Get<Self::Balance>;
283292

284293
/// The means of storing the balances of an account.
@@ -290,10 +299,6 @@ pub mod pallet {
290299
/// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/`
291300
type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
292301

293-
/// The overarching hold reason.
294-
#[pallet::no_default]
295-
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy;
296-
297302
/// The ID type for freezes.
298303
type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
299304

substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ type Block = frame_system::mocking::MockBlockU32<Runtime>;
6565
type Extrinsic = testing::TestXt<RuntimeCall, ()>;
6666

6767
frame_support::construct_runtime!(
68-
pub enum Runtime
69-
{
68+
pub enum Runtime {
7069
System: frame_system,
7170
ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
7271
Staking: pallet_staking,
@@ -89,15 +88,8 @@ pub(crate) type Moment = u32;
8988
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
9089
impl frame_system::Config for Runtime {
9190
type Block = Block;
92-
type BlockHashCount = ConstU32<10>;
93-
type BaseCallFilter = frame_support::traits::Everything;
94-
type RuntimeOrigin = RuntimeOrigin;
95-
type RuntimeCall = RuntimeCall;
96-
type RuntimeEvent = RuntimeEvent;
97-
type PalletInfo = PalletInfo;
98-
type OnSetCode = ();
99-
10091
type AccountData = pallet_balances::AccountData<Balance>;
92+
type BlockHashCount = ConstU32<10>;
10193
}
10294

10395
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

substrate/frame/examples/kitchensink/src/tests.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@ frame_support::construct_runtime!(
3939
/// details.
4040
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
4141
impl frame_system::Config for Test {
42-
type BaseCallFilter = frame_support::traits::Everything;
4342
type Block = Block;
44-
type BlockHashCount = ConstU64<10>;
45-
type RuntimeOrigin = RuntimeOrigin;
46-
type RuntimeCall = RuntimeCall;
47-
type RuntimeEvent = RuntimeEvent;
48-
type PalletInfo = PalletInfo;
49-
type OnSetCode = ();
50-
5143
type AccountData = pallet_balances::AccountData<u64>;
5244
}
5345

substrate/frame/examples/split/src/mock.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
use crate as pallet_template;
1919
use frame_support::{derive_impl, sp_runtime::BuildStorage};
20-
use sp_core::ConstU64;
2120

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

@@ -35,13 +34,6 @@ frame_support::construct_runtime!(
3534
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
3635
impl frame_system::Config for Test {
3736
type Block = Block;
38-
type BlockHashCount = ConstU64<10>;
39-
type BaseCallFilter = frame_support::traits::Everything;
40-
type RuntimeOrigin = RuntimeOrigin;
41-
type RuntimeCall = RuntimeCall;
42-
type RuntimeEvent = RuntimeEvent;
43-
type PalletInfo = PalletInfo;
44-
type OnSetCode = ();
4537
}
4638

4739
impl pallet_template::Config for Test {

substrate/frame/fast-unstake/src/mock.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use crate::{self as fast_unstake};
1919
use frame_support::{
20-
assert_ok,
20+
assert_ok, derive_impl,
2121
pallet_prelude::*,
2222
parameter_types,
2323
traits::{ConstU64, Currency},
@@ -32,7 +32,6 @@ use pallet_staking::{Exposure, IndividualExposure, StakerStatus};
3232
use sp_std::prelude::*;
3333

3434
pub type AccountId = u128;
35-
pub type Nonce = u32;
3635
pub type BlockNumber = u64;
3736
pub type Balance = u128;
3837
pub type T = Runtime;
@@ -44,30 +43,13 @@ parameter_types! {
4443
);
4544
}
4645

46+
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
4747
impl frame_system::Config for Runtime {
48-
type BaseCallFilter = frame_support::traits::Everything;
49-
type BlockWeights = BlockWeights;
50-
type BlockLength = ();
51-
type DbWeight = ();
52-
type RuntimeOrigin = RuntimeOrigin;
53-
type Nonce = Nonce;
54-
type RuntimeCall = RuntimeCall;
55-
type Hash = sp_core::H256;
56-
type Hashing = sp_runtime::traits::BlakeTwo256;
57-
type AccountId = AccountId;
58-
type Lookup = IdentityLookup<Self::AccountId>;
5948
type Block = Block;
60-
type RuntimeEvent = RuntimeEvent;
61-
type BlockHashCount = ();
62-
type Version = ();
63-
type PalletInfo = PalletInfo;
6449
type AccountData = pallet_balances::AccountData<Balance>;
65-
type OnNewAccount = ();
66-
type OnKilledAccount = ();
67-
type SystemWeightInfo = ();
68-
type SS58Prefix = ();
69-
type OnSetCode = ();
70-
type MaxConsumers = frame_support::traits::ConstU32<16>;
50+
// we use U128 account id in order to get a better iteration order out of a map.
51+
type AccountId = AccountId;
52+
type Lookup = IdentityLookup<Self::AccountId>;
7153
}
7254

7355
impl pallet_timestamp::Config for Runtime {

substrate/frame/multisig/src/tests.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ use sp_runtime::{BuildStorage, TokenError};
3131
type Block = frame_system::mocking::MockBlockU32<Test>;
3232

3333
frame_support::construct_runtime!(
34-
pub enum Test
35-
{
34+
pub enum Test {
3635
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
3736
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
3837
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>},
@@ -43,24 +42,15 @@ frame_support::construct_runtime!(
4342
impl frame_system::Config for Test {
4443
type Block = Block;
4544
type BlockHashCount = ConstU32<250>;
46-
type RuntimeOrigin = RuntimeOrigin;
47-
type RuntimeCall = RuntimeCall;
48-
type RuntimeEvent = RuntimeEvent;
49-
type BaseCallFilter = TestBaseCallFilter;
50-
type PalletInfo = PalletInfo;
51-
type OnSetCode = ();
52-
5345
type AccountData = pallet_balances::AccountData<u64>;
46+
// This pallet wishes to overwrite this.
47+
type BaseCallFilter = TestBaseCallFilter;
5448
}
5549

5650
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
5751
impl pallet_balances::Config for Test {
58-
type RuntimeEvent = RuntimeEvent;
59-
type RuntimeHoldReason = ();
6052
type ReserveIdentifier = [u8; 8];
61-
type DustRemoval = ();
6253
type AccountStore = System;
63-
type ExistentialDeposit = ConstU64<1>;
6454
}
6555

6656
pub struct TestBaseCallFilter;

substrate/frame/proxy/src/tests.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,14 @@ frame_support::construct_runtime!(
4545
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
4646
impl frame_system::Config for Test {
4747
type Block = Block;
48-
type BlockHashCount = ConstU64<250>;
49-
type RuntimeOrigin = RuntimeOrigin;
50-
type RuntimeCall = RuntimeCall;
51-
type RuntimeEvent = RuntimeEvent;
52-
type PalletInfo = PalletInfo;
53-
type OnSetCode = ();
54-
5548
type BaseCallFilter = BaseFilter;
5649
type AccountData = pallet_balances::AccountData<u64>;
5750
}
5851

5952
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
6053
impl pallet_balances::Config for Test {
61-
type RuntimeEvent = RuntimeEvent;
62-
type RuntimeHoldReason = ();
6354
type ReserveIdentifier = [u8; 8];
64-
type DustRemoval = ();
6555
type AccountStore = System;
66-
type ExistentialDeposit = ConstU64<1>;
6756
}
6857

6958
impl pallet_utility::Config for Test {

substrate/frame/support/procedural/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream {
877877
if item.ident != "RuntimeCall" &&
878878
item.ident != "RuntimeEvent" &&
879879
item.ident != "RuntimeOrigin" &&
880+
item.ident != "RuntimeHoldReason" &&
881+
item.ident != "RuntimeFreezeReason" &&
880882
item.ident != "PalletInfo"
881883
{
882884
return syn::Error::new_spanned(

0 commit comments

Comments
 (0)