migrate alliance, fast-unstake and bags list to use derive-impl (#1636)

Moving a few pallets to the latest and greatest `derive_impl` to give it
a try.

Part of #171

---------

Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Kian Paimani
2023-10-01 16:16:14 +02:00
committed by GitHub
parent e8baac7848
commit 2ed66a0960
12 changed files with 34 additions and 139 deletions
+1 -11
View File
@@ -49,22 +49,12 @@ construct_runtime!(
} }
); );
parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
}
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test { impl frame_system::Config for Test {
type Block = Block; type Block = Block;
type BlockHashCount = BlockHashCount;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type OnSetCode = ();
type AccountData = pallet_balances::AccountData<Balance>; type AccountData = pallet_balances::AccountData<Balance>;
type AccountId = AccountId; type AccountId = AccountId;
type BlockHashCount = ConstU32<256>;
type Lookup = sp_runtime::traits::IdentityLookup<AccountId>; type Lookup = sp_runtime::traits::IdentityLookup<AccountId>;
} }
+3 -22
View File
@@ -26,7 +26,7 @@ pub use sp_runtime::{
use sp_std::convert::{TryFrom, TryInto}; use sp_std::convert::{TryFrom, TryInto};
pub use frame_support::{ pub use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types, assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types,
traits::{EitherOfDiverse, SortedMembers}, traits::{EitherOfDiverse, SortedMembers},
BoundedVec, BoundedVec,
}; };
@@ -45,30 +45,11 @@ parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::MAX); frame_system::limits::BlockWeights::simple_max(Weight::MAX);
} }
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test { impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block; type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<AccountId>; type AccountData = pallet_balances::AccountData<AccountId>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
} }
parameter_types! { parameter_types! {
+3 -23
View File
@@ -20,11 +20,11 @@
use super::*; use super::*;
use crate::{self as bags_list}; use crate::{self as bags_list};
use frame_election_provider_support::VoteWeight; use frame_election_provider_support::VoteWeight;
use frame_support::parameter_types; use frame_support::{derive_impl, parameter_types};
use sp_runtime::BuildStorage; use sp_runtime::BuildStorage;
use std::collections::HashMap; use std::collections::HashMap;
pub type AccountId = u32; pub type AccountId = <Runtime as frame_system::Config>::AccountId;
pub type Balance = u32; pub type Balance = u32;
parameter_types! { parameter_types! {
@@ -48,30 +48,10 @@ impl frame_election_provider_support::ScoreProvider<AccountId> for StakingMock {
} }
} }
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime { 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 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 AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
} }
parameter_types! { parameter_types! {
+3 -3
View File
@@ -163,7 +163,7 @@ mod pallet {
assert_eq!(Bag::<Runtime>::get(10).unwrap(), Bag::new(Some(1), Some(3), 10)); assert_eq!(Bag::<Runtime>::get(10).unwrap(), Bag::new(Some(1), Some(3), 10));
assert_eq!(Bag::<Runtime>::get(1_000).unwrap(), Bag::new(Some(2), Some(2), 1_000)); assert_eq!(Bag::<Runtime>::get(1_000).unwrap(), Bag::new(Some(2), Some(2), 1_000));
assert_eq!(get_list_as_ids(), vec![2u32, 1, 4, 3]); assert_eq!(get_list_as_ids(), vec![2u64, 1, 4, 3]);
// when // when
StakingMock::set_score_of(&2, 10); StakingMock::set_score_of(&2, 10);
@@ -272,10 +272,10 @@ mod pallet {
// given // given
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![10, 11, 12])]); assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![10, 11, 12])]);
// 11 now has more weight than 10 and can be moved before it. // 11 now has more weight than 10 and can be moved before it.
StakingMock::set_score_of(&11u32, 17); StakingMock::set_score_of(&11u64, 17);
// when // when
assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11u32, 10)); assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11u64, 10));
// then // then
assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![11, 10, 12])]); assert_eq!(List::<Runtime>::get_bags(), vec![(20, vec![11, 10, 12])]);
+12 -7
View File
@@ -216,7 +216,7 @@ pub mod pallet {
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`]. /// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes { pub mod config_preludes {
use super::*; use super::*;
use frame_support::derive_impl; use frame_support::{derive_impl, traits::ConstU64};
pub struct TestDefaultConfig; pub struct TestDefaultConfig;
@@ -227,12 +227,17 @@ pub mod pallet {
impl DefaultConfig for TestDefaultConfig { impl DefaultConfig for TestDefaultConfig {
#[inject_runtime_type] #[inject_runtime_type]
type RuntimeEvent = (); type RuntimeEvent = ();
#[inject_runtime_type]
type RuntimeHoldReason = ();
type Balance = u64; type Balance = u64;
type ExistentialDeposit = ConstU64<1>;
type ReserveIdentifier = (); type ReserveIdentifier = ();
type FreezeIdentifier = (); type FreezeIdentifier = ();
type DustRemoval = ();
type MaxLocks = (); type MaxLocks = ();
type MaxReserves = (); type MaxReserves = ();
type MaxFreezes = (); type MaxFreezes = ();
@@ -249,6 +254,10 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self, I>> type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>; + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The overarching hold reason.
#[pallet::no_default_bounds]
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy;
/// Weight information for extrinsics in this pallet. /// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo; type WeightInfo: WeightInfo;
@@ -266,7 +275,7 @@ pub mod pallet {
+ FixedPointOperand; + FixedPointOperand;
/// Handler for the unbalanced reduction when removing a dust account. /// Handler for the unbalanced reduction when removing a dust account.
#[pallet::no_default] #[pallet::no_default_bounds]
type DustRemoval: OnUnbalanced<CreditOf<Self, I>>; type DustRemoval: OnUnbalanced<CreditOf<Self, I>>;
/// The minimum amount required to keep an account open. MUST BE GREATER THAN ZERO! /// The minimum amount required to keep an account open. MUST BE GREATER THAN ZERO!
@@ -278,7 +287,7 @@ pub mod pallet {
/// ///
/// Bottom line: Do yourself a favour and make it at least one! /// Bottom line: Do yourself a favour and make it at least one!
#[pallet::constant] #[pallet::constant]
#[pallet::no_default] #[pallet::no_default_bounds]
type ExistentialDeposit: Get<Self::Balance>; type ExistentialDeposit: Get<Self::Balance>;
/// The means of storing the balances of an account. /// The means of storing the balances of an account.
@@ -290,10 +299,6 @@ pub mod pallet {
/// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/` /// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/`
type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
/// The overarching hold reason.
#[pallet::no_default]
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy;
/// The ID type for freezes. /// The ID type for freezes.
type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
@@ -65,8 +65,7 @@ type Block = frame_system::mocking::MockBlockU32<Runtime>;
type Extrinsic = testing::TestXt<RuntimeCall, ()>; type Extrinsic = testing::TestXt<RuntimeCall, ()>;
frame_support::construct_runtime!( frame_support::construct_runtime!(
pub enum Runtime pub enum Runtime {
{
System: frame_system, System: frame_system,
ElectionProviderMultiPhase: pallet_election_provider_multi_phase, ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
Staking: pallet_staking, Staking: pallet_staking,
@@ -89,15 +88,8 @@ pub(crate) type Moment = u32;
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime { impl frame_system::Config for Runtime {
type Block = Block; type Block = Block;
type BlockHashCount = ConstU32<10>;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type OnSetCode = ();
type AccountData = pallet_balances::AccountData<Balance>; type AccountData = pallet_balances::AccountData<Balance>;
type BlockHashCount = ConstU32<10>;
} }
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
@@ -39,15 +39,7 @@ frame_support::construct_runtime!(
/// details. /// details.
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test { impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type Block = Block; type Block = Block;
type BlockHashCount = ConstU64<10>;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type OnSetCode = ();
type AccountData = pallet_balances::AccountData<u64>; type AccountData = pallet_balances::AccountData<u64>;
} }
@@ -17,7 +17,6 @@
use crate as pallet_template; use crate as pallet_template;
use frame_support::{derive_impl, sp_runtime::BuildStorage}; use frame_support::{derive_impl, sp_runtime::BuildStorage};
use sp_core::ConstU64;
type Block = frame_system::mocking::MockBlock<Test>; type Block = frame_system::mocking::MockBlock<Test>;
@@ -35,13 +34,6 @@ frame_support::construct_runtime!(
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test { impl frame_system::Config for Test {
type Block = Block; type Block = Block;
type BlockHashCount = ConstU64<10>;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type OnSetCode = ();
} }
impl pallet_template::Config for Test { impl pallet_template::Config for Test {
+5 -23
View File
@@ -17,7 +17,7 @@
use crate::{self as fast_unstake}; use crate::{self as fast_unstake};
use frame_support::{ use frame_support::{
assert_ok, assert_ok, derive_impl,
pallet_prelude::*, pallet_prelude::*,
parameter_types, parameter_types,
traits::{ConstU64, Currency}, traits::{ConstU64, Currency},
@@ -32,7 +32,6 @@ use pallet_staking::{Exposure, IndividualExposure, StakerStatus};
use sp_std::prelude::*; use sp_std::prelude::*;
pub type AccountId = u128; pub type AccountId = u128;
pub type Nonce = u32;
pub type BlockNumber = u64; pub type BlockNumber = u64;
pub type Balance = u128; pub type Balance = u128;
pub type T = Runtime; pub type T = Runtime;
@@ -44,30 +43,13 @@ parameter_types! {
); );
} }
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime { impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything; type Block = Block;
type BlockWeights = BlockWeights; type AccountData = pallet_balances::AccountData<Balance>;
type BlockLength = (); // we use U128 account id in order to get a better iteration order out of a map.
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 AccountId = AccountId;
type Lookup = IdentityLookup<Self::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 { impl pallet_timestamp::Config for Runtime {
+3 -13
View File
@@ -31,8 +31,7 @@ use sp_runtime::{BuildStorage, TokenError};
type Block = frame_system::mocking::MockBlockU32<Test>; type Block = frame_system::mocking::MockBlockU32<Test>;
frame_support::construct_runtime!( frame_support::construct_runtime!(
pub enum Test pub enum Test {
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>}, System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>}, Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>},
@@ -43,24 +42,15 @@ frame_support::construct_runtime!(
impl frame_system::Config for Test { impl frame_system::Config for Test {
type Block = Block; type Block = Block;
type BlockHashCount = ConstU32<250>; type BlockHashCount = ConstU32<250>;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type BaseCallFilter = TestBaseCallFilter;
type PalletInfo = PalletInfo;
type OnSetCode = ();
type AccountData = pallet_balances::AccountData<u64>; type AccountData = pallet_balances::AccountData<u64>;
// This pallet wishes to overwrite this.
type BaseCallFilter = TestBaseCallFilter;
} }
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
impl pallet_balances::Config for Test { impl pallet_balances::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = ();
type ReserveIdentifier = [u8; 8]; type ReserveIdentifier = [u8; 8];
type DustRemoval = ();
type AccountStore = System; type AccountStore = System;
type ExistentialDeposit = ConstU64<1>;
} }
pub struct TestBaseCallFilter; pub struct TestBaseCallFilter;
-11
View File
@@ -45,25 +45,14 @@ frame_support::construct_runtime!(
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test { impl frame_system::Config for Test {
type Block = Block; type Block = Block;
type BlockHashCount = ConstU64<250>;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type OnSetCode = ();
type BaseCallFilter = BaseFilter; type BaseCallFilter = BaseFilter;
type AccountData = pallet_balances::AccountData<u64>; type AccountData = pallet_balances::AccountData<u64>;
} }
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
impl pallet_balances::Config for Test { impl pallet_balances::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = ();
type ReserveIdentifier = [u8; 8]; type ReserveIdentifier = [u8; 8];
type DustRemoval = ();
type AccountStore = System; type AccountStore = System;
type ExistentialDeposit = ConstU64<1>;
} }
impl pallet_utility::Config for Test { impl pallet_utility::Config for Test {
@@ -877,6 +877,8 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream {
if item.ident != "RuntimeCall" && if item.ident != "RuntimeCall" &&
item.ident != "RuntimeEvent" && item.ident != "RuntimeEvent" &&
item.ident != "RuntimeOrigin" && item.ident != "RuntimeOrigin" &&
item.ident != "RuntimeHoldReason" &&
item.ident != "RuntimeFreezeReason" &&
item.ident != "PalletInfo" item.ident != "PalletInfo"
{ {
return syn::Error::new_spanned( return syn::Error::new_spanned(