Skip to content

Commit

Permalink
Replace simple parameter_types (paritytech#11254)
Browse files Browse the repository at this point in the history
* update bin/node-template/runtime/src/lib.rs

* update frame/contracts/src/tests.rs

* update frame/executive/src/lib.rs

* update frame/grandpa/src/mock.rs

* update frame/im-online/src/mock.rs

* update frame/offences/benchmarking/src/mock.rs

* update frame/recovery/src/mock.rs

* update frame/referenda/src/mock.rs

* update frame/session/benchmarking/src/mock.rs

* update frame/staking/src/mock.rs

* update frame/state-trie-migration/src/lib.rs

* update frame/support/test/compile_pass/src/lib.rs

* frame/treasury/src/tests.rs

* update frame/whitelist/src/mock.rs

* update frame/vesting/src/mock.rs

* update test-utils/runtime/src/lib.rs

* update bin/node-template/runtime/src/lib.rs

* Update frame/grandpa/src/mock.rs

Co-authored-by: Kian Paimani <[email protected]>

* resolve failed checks 1518659 & 1518669

* resolve format check

* backtrack to resolve compile error

* check --all --tests ✅

* cargo +nightly fmt ✅

Co-authored-by: Shawn Tabrizi <[email protected]>
Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: Keith Yeung <[email protected]>
  • Loading branch information
4 people authored Apr 29, 2022
1 parent 88731ed commit efe6d77
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 78 deletions.
12 changes: 5 additions & 7 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use sp_version::RuntimeVersion;
// A few exports that help ease life for downstream crates.
pub use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU128, ConstU32, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo},
traits::{
ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
Expand Down Expand Up @@ -132,8 +134,8 @@ pub fn native_version() -> NativeVersion {
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub const BlockHashCount: BlockNumber = 2400;
pub const Version: RuntimeVersion = VERSION;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
Expand Down Expand Up @@ -224,15 +226,11 @@ impl pallet_grandpa::Config for Runtime {
type MaxAuthorities = ConstU32<32>;
}

parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}

impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = ();
}

Expand Down
6 changes: 1 addition & 5 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,13 @@ impl pallet_utility::Config for Test {
type WeightInfo = ();
}
parameter_types! {
pub const MaxValueSize: u32 = 16_384;
pub const DeletionWeightLimit: Weight = 500_000_000_000;
pub const MaxCodeSize: u32 = 2 * 1024;
pub MySchedule: Schedule<Test> = {
let mut schedule = <Schedule<Test>>::default();
// We want stack height to be always enabled for tests so that this
// instrumentation path is always tested implicitly.
schedule.limits.stack_height = Some(512);
schedule
};
pub const TransactionByteFee: u64 = 0;
pub static DepositPerByte: BalanceOf<Test> = 1;
pub const DepositPerItem: BalanceOf<Test> = 2;
}
Expand Down Expand Up @@ -286,7 +282,7 @@ impl Config for Test {
type WeightInfo = ();
type ChainExtension = TestExtension;
type DeletionQueueDepth = ConstU32<1024>;
type DeletionWeightLimit = DeletionWeightLimit;
type DeletionWeightLimit = ConstU64<500_000_000_000>;
type Schedule = MySchedule;
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
Expand Down
5 changes: 1 addition & 4 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,11 @@ mod tests {
}

type Balance = u64;
parameter_types! {
pub const ExistentialDeposit: Balance = 1;
}
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type MaxLocks = ();
type MaxReserves = ();
Expand Down
6 changes: 1 addition & 5 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ pallet_staking_reward_curve::build! {
parameter_types! {
pub const SessionsPerEra: SessionIndex = 3;
pub const BondingDuration: EraIndex = 3;
pub const SlashDeferDuration: EraIndex = 0;
pub const AttestationPeriod: u64 = 100;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const ElectionLookahead: u64 = 0;
pub const StakingUnsignedPriority: u64 = u64::MAX / 2;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

Expand All @@ -199,7 +195,7 @@ impl pallet_staking::Config for Test {
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
type SlashDeferDuration = ();
type SlashCancelOrigin = frame_system::EnsureRoot<Self::AccountId>;
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
Expand Down
6 changes: 1 addition & 5 deletions frame/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,13 @@ impl frame_support::traits::EstimateNextSessionRotation<u64> for TestNextSession
}
}

parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
}

impl Config for Runtime {
type AuthorityId = UintAuthorityId;
type Event = Event;
type ValidatorSet = Historical;
type NextSessionRotation = TestNextSessionRotation;
type ReportUnresponsiveness = OffenceHandler;
type UnsignedPriority = UnsignedPriority;
type UnsignedPriority = ConstU64<{ 1 << 20 }>;
type WeightInfo = ();
type MaxKeys = ConstU32<10_000>;
type MaxPeerInHeartbeats = ConstU32<10_000>;
Expand Down
6 changes: 2 additions & 4 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@ impl frame_system::Config for Test {
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
}

impl pallet_balances::Config for Test {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = Balance;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU64<10>;
type AccountStore = System;
type WeightInfo = ();
}
Expand Down
26 changes: 7 additions & 19 deletions frame/referenda/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use frame_support::{
ConstU32, ConstU64, Contains, EqualPrivilegeOnly, OnInitialize, OriginTrait, Polling,
PreimageRecipient, SortedMembers,
},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use sp_core::H256;
Expand Down Expand Up @@ -62,7 +61,6 @@ impl Contains<Call> for BaseFilter {
}

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1_000_000);
}
Expand All @@ -81,7 +79,7 @@ impl frame_system::Config for Test {
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
Expand All @@ -101,42 +99,32 @@ impl pallet_preimage::Config for Test {
type BaseDeposit = ();
type ByteDeposit = ();
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = 2_000_000_000_000;
}
impl pallet_scheduler::Config for Test {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type MaximumWeight = ConstU64<2_000_000_000_000>;
type ScheduleOrigin = EnsureRoot<u64>;
type MaxScheduledPerBlock = ConstU32<100>;
type WeightInfo = ();
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type PreimageProvider = Preimage;
type NoPreimagePostponement = ConstU64<10>;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const MaxLocks: u32 = 10;
}
impl pallet_balances::Config for Test {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type MaxLocks = MaxLocks;
type MaxLocks = ConstU32<10>;
type Balance = u64;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type WeightInfo = ();
}
parameter_types! {
pub static AlarmInterval: u64 = 1;
pub const SubmissionDeposit: u64 = 2;
pub const MaxQueued: u32 = 3;
pub const UndecidingTimeout: u64 = 20;
}
ord_parameter_types! {
pub const One: u64 = 1;
Expand Down Expand Up @@ -228,9 +216,9 @@ impl Config for Test {
type Slash = ();
type Votes = u32;
type Tally = Tally;
type SubmissionDeposit = SubmissionDeposit;
type MaxQueued = MaxQueued;
type UndecidingTimeout = UndecidingTimeout;
type SubmissionDeposit = ConstU64<2>;
type MaxQueued = ConstU32<3>;
type UndecidingTimeout = ConstU64<20>;
type AlarmInterval = AlarmInterval;
type Tracks = TestTracksInfo;
}
Expand Down
6 changes: 2 additions & 4 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ impl frame_system::Config for Test {
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
}

impl pallet_balances::Config for Test {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = Balance;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU64<10>;
type AccountStore = System;
type WeightInfo = ();
}
Expand Down
14 changes: 7 additions & 7 deletions frame/state-trie-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,10 @@ mod benchmarks {
mod mock {
use super::*;
use crate as pallet_state_trie_migration;
use frame_support::{parameter_types, traits::Hooks};
use frame_support::{
parameter_types,
traits::{ConstU32, ConstU64, Hooks},
};
use frame_system::{EnsureRoot, EnsureSigned};
use sp_core::{
storage::{ChildInfo, StateVersion},
Expand Down Expand Up @@ -1008,7 +1011,6 @@ mod mock {
);

parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const SS58Prefix: u8 = 42;
}

Expand All @@ -1026,7 +1028,7 @@ mod mock {
type Lookup = IdentityLookup<Self::AccountId>;
type Header = sp_runtime::generic::Header<Self::BlockNumber, BlakeTwo256>;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU32<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
Expand All @@ -1036,12 +1038,10 @@ mod mock {
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}

parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const OffchainRepeat: u32 = 1;
pub const SignedDepositPerItem: u64 = 1;
pub const SignedDepositBase: u64 = 5;
}
Expand All @@ -1050,7 +1050,7 @@ mod mock {
type Balance = u64;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type MaxLocks = ();
type MaxReserves = ();
Expand Down
5 changes: 2 additions & 3 deletions frame/support/test/compile_pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU16, ConstU32},
traits::{ConstU16, ConstU32, ConstU64},
};
use sp_core::{sr25519, H256};
use sp_runtime::{
Expand All @@ -50,7 +50,6 @@ pub type BlockNumber = u64;
pub type Index = u64;

parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const Version: RuntimeVersion = VERSION;
}

Expand All @@ -63,7 +62,7 @@ impl frame_system::Config for Runtime {
type Hashing = BlakeTwo256;
type Header = Header;
type Lookup = IdentityLookup<Self::AccountId>;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU64<2400>;
type Version = Version;
type AccountData = ();
type Origin = Origin;
Expand Down
5 changes: 1 addition & 4 deletions frame/treasury/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const Burn: Permill = Permill::from_percent(50);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const BountyUpdatePeriod: u32 = 20;
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
pub const BountyValueMinimum: u64 = 1;
pub const MaxApprovals: u32 = 100;
}
impl Config for Test {
Expand All @@ -121,7 +118,7 @@ impl Config for Test {
type BurnDestination = (); // Just gets burned.
type WeightInfo = ();
type SpendFunds = ();
type MaxApprovals = MaxApprovals;
type MaxApprovals = ConstU32<100>;
}

pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
13 changes: 4 additions & 9 deletions frame/whitelist/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use crate as pallet_whitelist;

use frame_support::{
parameter_types,
construct_runtime, parameter_types,
traits::{ConstU32, ConstU64, Nothing},
};
use frame_system::EnsureRoot;
Expand All @@ -36,7 +36,7 @@ use sp_runtime::{
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
Expand All @@ -49,7 +49,7 @@ frame_support::construct_runtime!(
}
);

frame_support::parameter_types! {
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
Expand Down Expand Up @@ -92,16 +92,11 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
}

parameter_types! {
// Taken from Polkadot as reference.
pub const PreimageMaxSize: u32 = 4096 * 1024;
}

impl pallet_preimage::Config for Test {
type Event = Event;
type Currency = Balances;
type ManagerOrigin = EnsureRoot<Self::AccountId>;
type MaxSize = PreimageMaxSize;
type MaxSize = ConstU32<{ 4096 * 1024 }>; // PreimageMaxSize Taken from Polkadot as reference.
type BaseDeposit = ConstU64<1>;
type ByteDeposit = ConstU64<1>;
type WeightInfo = ();
Expand Down
Loading

0 comments on commit efe6d77

Please sign in to comment.