From 0c1278a13895b341d7cf716575888bffc80a9ef7 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Fri, 1 Apr 2022 11:15:46 +1300 Subject: [PATCH 1/3] WIP Refactor parameter-types --- auction/src/mock.rs | 8 ++------ authority/src/mock.rs | 5 ++--- currencies/src/mock.rs | 19 +++++-------------- gradually-update/src/mock.rs | 23 ++++++----------------- nft/src/mock.rs | 17 ++++------------- oracle/src/mock.rs | 17 ++++------------- rewards/src/mock.rs | 8 ++------ 7 files changed, 25 insertions(+), 72 deletions(-) diff --git a/auction/src/mock.rs b/auction/src/mock.rs index bcd31e331..cd75918f8 100644 --- a/auction/src/mock.rs +++ b/auction/src/mock.rs @@ -3,17 +3,13 @@ #![cfg(test)] use super::*; -use frame_support::{construct_runtime, parameter_types, traits::Everything}; +use frame_support::{construct_runtime, traits::{Everything, ConstU64}}; use orml_traits::OnNewBidResult; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; use crate as auction; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - pub type AccountId = u128; pub type Balance = u64; pub type BlockNumber = u64; @@ -30,7 +26,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); diff --git a/authority/src/mock.rs b/authority/src/mock.rs index 54aa0bcfc..f6b6c9de0 100644 --- a/authority/src/mock.rs +++ b/authority/src/mock.rs @@ -6,7 +6,7 @@ use super::*; use codec::{Decode, Encode}; use frame_support::{ parameter_types, - traits::{EqualPrivilegeOnly, Everything}, + traits::{EqualPrivilegeOnly, Everything, ConstU64}, weights::Weight, }; use frame_system::{ensure_root, ensure_signed, EnsureRoot}; @@ -23,7 +23,6 @@ pub type AccountId = u128; pub type BlockNumber = u64; parameter_types! { - pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights::simple_max(2_000_000_000_000); } @@ -39,7 +38,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); diff --git a/currencies/src/mock.rs b/currencies/src/mock.rs index 5d47b60fa..3839ec144 100644 --- a/currencies/src/mock.rs +++ b/currencies/src/mock.rs @@ -4,8 +4,8 @@ use super::*; use frame_support::{ - construct_runtime, parameter_types, - traits::{Everything, Nothing}, + construct_runtime, parameter_types, + traits::{Everything, Nothing, ConstU32, ConstU64,}, PalletId, }; use orml_traits::parameter_type_with_key; @@ -18,10 +18,6 @@ use sp_runtime::{ use crate as currencies; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - pub type AccountId = AccountId32; impl frame_system::Config for Runtime { type Origin = Origin; @@ -34,7 +30,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -53,15 +49,11 @@ impl frame_system::Config for Runtime { type CurrencyId = u32; type Balance = u64; -parameter_types! { - pub const ExistentialDeposit: u64 = 2; -} - impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type Event = Event; - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU64<2>; type AccountStore = frame_system::Pallet; type MaxLocks = (); type MaxReserves = (); @@ -77,7 +69,6 @@ parameter_type_with_key! { parameter_types! { pub DustAccount: AccountId = PalletId(*b"orml/dst").into_account(); - pub MaxLocks: u32 = 100_000; } impl orml_tokens::Config for Runtime { @@ -88,7 +79,7 @@ impl orml_tokens::Config for Runtime { type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; type OnDust = orml_tokens::TransferDust; - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<100_000>; type DustRemovalWhitelist = Nothing; } diff --git a/gradually-update/src/mock.rs b/gradually-update/src/mock.rs index 3bd038bf0..4a8c89c0f 100644 --- a/gradually-update/src/mock.rs +++ b/gradually-update/src/mock.rs @@ -3,16 +3,12 @@ #![cfg(test)] use super::*; -use frame_support::{construct_runtime, parameter_types, traits::Everything}; +use frame_support::{construct_runtime, traits::{Everything, ConstU32, ConstU64}}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; use crate as gradually_update; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - pub type AccountId = u128; pub type BlockNumber = u64; @@ -27,7 +23,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -43,21 +39,14 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -parameter_types! { - pub const UpdateFrequency: BlockNumber = 10; - pub MaxGraduallyUpdate: u32 = 3; - pub MaxStorageKeyBytes: u32 = 100_000; - pub MaxStorageValueBytes: u32 = 100_000; -} - impl Config for Runtime { type Event = Event; - type UpdateFrequency = UpdateFrequency; + type UpdateFrequency = ConstU64<10>; type DispatchOrigin = frame_system::EnsureRoot; type WeightInfo = (); - type MaxGraduallyUpdate = MaxGraduallyUpdate; - type MaxStorageKeyBytes = MaxStorageKeyBytes; - type MaxStorageValueBytes = MaxStorageValueBytes; + type MaxGraduallyUpdate = ConstU32<3>; + type MaxStorageKeyBytes = ConstU32<100_000>; + type MaxStorageValueBytes = ConstU32<100_000>; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/nft/src/mock.rs b/nft/src/mock.rs index 733dc24da..280069aa0 100644 --- a/nft/src/mock.rs +++ b/nft/src/mock.rs @@ -2,7 +2,7 @@ #![cfg(test)] -use frame_support::{construct_runtime, parameter_types, traits::Everything}; +use frame_support::{construct_runtime, traits::{Everything, ConstU32, ConstU64}}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; @@ -10,10 +10,6 @@ use super::*; use crate as nft; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - pub type AccountId = u128; pub type BlockNumber = u64; @@ -28,7 +24,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -44,18 +40,13 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -parameter_types! { - pub const MaxClassMetadata: u32 = 1; - pub const MaxTokenMetadata: u32 = 1; -} - impl Config for Runtime { type ClassId = u64; type TokenId = u64; type ClassData = (); type TokenData = (); - type MaxClassMetadata = MaxClassMetadata; - type MaxTokenMetadata = MaxTokenMetadata; + type MaxClassMetadata = ConstU32<1>; + type MaxTokenMetadata = ConstU32<1>; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/oracle/src/mock.rs b/oracle/src/mock.rs index 7a8a948c6..0aa89ef33 100644 --- a/oracle/src/mock.rs +++ b/oracle/src/mock.rs @@ -4,7 +4,7 @@ use super::*; use frame_support::{ construct_runtime, parameter_types, - traits::{Everything, SortedMembers}, + traits::{Everything, SortedMembers, ConstU32, ConstU64}, }; use sp_core::H256; use sp_runtime::{ @@ -22,9 +22,6 @@ pub type AccountId = u128; type Key = u32; type Value = u32; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} impl frame_system::Config for Test { type Origin = Origin; type Call = Call; @@ -36,7 +33,7 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -72,8 +69,6 @@ impl Timestamp { } parameter_types! { - pub const MinimumCount: u32 = 3; - pub const ExpiresIn: u32 = 600; pub const RootOperatorAccountId: AccountId = 4; pub static OracleMembers: Vec = vec![1, 2, 3]; } @@ -86,21 +81,17 @@ impl SortedMembers for Members { } } -parameter_types! { - pub const MaxHasDispatchedSize: u32 = 100; -} - impl Config for Test { type Event = Event; type OnNewData = (); - type CombineData = DefaultCombineData; + type CombineData = DefaultCombineData, ConstU32<600>>; type Time = Timestamp; type OracleKey = Key; type OracleValue = Value; type RootOperatorAccountId = RootOperatorAccountId; type Members = Members; type WeightInfo = (); - type MaxHasDispatchedSize = MaxHasDispatchedSize; + type MaxHasDispatchedSize = ConstU32<100>; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/rewards/src/mock.rs b/rewards/src/mock.rs index 7f9d10b8d..19b02913f 100644 --- a/rewards/src/mock.rs +++ b/rewards/src/mock.rs @@ -3,7 +3,7 @@ #![cfg(test)] use super::*; -use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::constants::RocksDbWeight}; +use frame_support::{construct_runtime, parameter_types, traits::{Everything, ConstU32, ConstU64, ConstU128}, weights::constants::RocksDbWeight}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; use sp_std::cell::RefCell; @@ -25,10 +25,6 @@ pub const DOT_POOL: PoolId = 1; pub const NATIVE_COIN: CurrencyId = 0; pub const STABLE_COIN: CurrencyId = 1; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - impl frame_system::Config for Runtime { type Origin = Origin; type Index = u64; @@ -40,7 +36,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); From aaad4d3f4a21a0fc60398ad9e41fea801bb233e9 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Fri, 1 Apr 2022 15:28:09 +1300 Subject: [PATCH 2/3] Replaced parameter_types! with ConstU types --- auction/src/mock.rs | 5 +++- authority/src/mock.rs | 2 +- currencies/src/mock.rs | 4 +-- gradually-update/src/mock.rs | 5 +++- nft/src/mock.rs | 5 +++- oracle/src/mock.rs | 2 +- rewards/src/mock.rs | 6 +++- tokens/src/mock.rs | 33 ++++++++-------------- unknown-tokens/src/mock.rs | 11 ++++---- vesting/src/mock.rs | 20 ++++---------- weight-meter/src/mock.rs | 14 ++-------- xtokens/src/mock/para.rs | 36 +++++++----------------- xtokens/src/mock/para_relative_view.rs | 36 +++++++----------------- xtokens/src/mock/relay.rs | 38 ++++++-------------------- 14 files changed, 75 insertions(+), 142 deletions(-) diff --git a/auction/src/mock.rs b/auction/src/mock.rs index cd75918f8..12568fdd8 100644 --- a/auction/src/mock.rs +++ b/auction/src/mock.rs @@ -3,7 +3,10 @@ #![cfg(test)] use super::*; -use frame_support::{construct_runtime, traits::{Everything, ConstU64}}; +use frame_support::{ + construct_runtime, + traits::{ConstU64, Everything}, +}; use orml_traits::OnNewBidResult; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; diff --git a/authority/src/mock.rs b/authority/src/mock.rs index f6b6c9de0..72333bf2d 100644 --- a/authority/src/mock.rs +++ b/authority/src/mock.rs @@ -6,7 +6,7 @@ use super::*; use codec::{Decode, Encode}; use frame_support::{ parameter_types, - traits::{EqualPrivilegeOnly, Everything, ConstU64}, + traits::{ConstU64, EqualPrivilegeOnly, Everything}, weights::Weight, }; use frame_system::{ensure_root, ensure_signed, EnsureRoot}; diff --git a/currencies/src/mock.rs b/currencies/src/mock.rs index 3839ec144..5702bbfe9 100644 --- a/currencies/src/mock.rs +++ b/currencies/src/mock.rs @@ -4,8 +4,8 @@ use super::*; use frame_support::{ - construct_runtime, parameter_types, - traits::{Everything, Nothing, ConstU32, ConstU64,}, + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64, Everything, Nothing}, PalletId, }; use orml_traits::parameter_type_with_key; diff --git a/gradually-update/src/mock.rs b/gradually-update/src/mock.rs index 4a8c89c0f..3ebbb8152 100644 --- a/gradually-update/src/mock.rs +++ b/gradually-update/src/mock.rs @@ -3,7 +3,10 @@ #![cfg(test)] use super::*; -use frame_support::{construct_runtime, traits::{Everything, ConstU32, ConstU64}}; +use frame_support::{ + construct_runtime, + traits::{ConstU32, ConstU64, Everything}, +}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; diff --git a/nft/src/mock.rs b/nft/src/mock.rs index 280069aa0..d384cab4b 100644 --- a/nft/src/mock.rs +++ b/nft/src/mock.rs @@ -2,7 +2,10 @@ #![cfg(test)] -use frame_support::{construct_runtime, traits::{Everything, ConstU32, ConstU64}}; +use frame_support::{ + construct_runtime, + traits::{ConstU32, ConstU64, Everything}, +}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; diff --git a/oracle/src/mock.rs b/oracle/src/mock.rs index 0aa89ef33..6c36a834f 100644 --- a/oracle/src/mock.rs +++ b/oracle/src/mock.rs @@ -4,7 +4,7 @@ use super::*; use frame_support::{ construct_runtime, parameter_types, - traits::{Everything, SortedMembers, ConstU32, ConstU64}, + traits::{ConstU32, ConstU64, Everything, SortedMembers}, }; use sp_core::H256; use sp_runtime::{ diff --git a/rewards/src/mock.rs b/rewards/src/mock.rs index 19b02913f..26a1f3c26 100644 --- a/rewards/src/mock.rs +++ b/rewards/src/mock.rs @@ -3,7 +3,11 @@ #![cfg(test)] use super::*; -use frame_support::{construct_runtime, parameter_types, traits::{Everything, ConstU32, ConstU64, ConstU128}, weights::constants::RocksDbWeight}; +use frame_support::{ + construct_runtime, + traits::{ConstU64, Everything}, + weights::constants::RocksDbWeight, +}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup}; use sp_std::cell::RefCell; diff --git a/tokens/src/mock.rs b/tokens/src/mock.rs index 8935bd9e2..fd878e3dc 100644 --- a/tokens/src/mock.rs +++ b/tokens/src/mock.rs @@ -5,7 +5,10 @@ use super::*; use frame_support::{ construct_runtime, parameter_types, - traits::{ChangeMembers, ContainsLengthBound, Everything, GenesisBuild, SaturatingCurrencyToVote, SortedMembers}, + traits::{ + ChangeMembers, ConstU32, ConstU64, ContainsLengthBound, Everything, GenesisBuild, SaturatingCurrencyToVote, + SortedMembers, + }, PalletId, }; use orml_traits::parameter_type_with_key; @@ -35,10 +38,6 @@ pub const ID_3: LockIdentifier = *b"3 "; use crate as tokens; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - impl frame_system::Config for Runtime { type Origin = Origin; type Call = Call; @@ -50,7 +49,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -179,13 +178,6 @@ impl ChangeMembers for TestChangeMembers { parameter_types! { pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; - pub const CandidacyBond: u64 = 3; - pub const VotingBond: u64 = 2; - pub const DesiredMembers: u32 = 2; - pub const DesiredRunnersUp: u32 = 2; - pub const TermDuration: u64 = 5; - pub const VotingBondBase: u64 = 2; - pub const VotingBondFactor: u64 = 0; } impl pallet_elections_phragmen::Config for Runtime { @@ -195,12 +187,12 @@ impl pallet_elections_phragmen::Config for Runtime { type CurrencyToVote = SaturatingCurrencyToVote; type ChangeMembers = TestChangeMembers; type InitializeMembers = (); - type CandidacyBond = CandidacyBond; - type VotingBondBase = VotingBondBase; - type VotingBondFactor = VotingBondFactor; - type TermDuration = TermDuration; - type DesiredMembers = DesiredMembers; - type DesiredRunnersUp = DesiredRunnersUp; + type CandidacyBond = ConstU64<3>; + type VotingBondBase = ConstU64<2>; + type VotingBondFactor = ConstU64<0>; + type TermDuration = ConstU64<5>; + type DesiredMembers = ConstU32<2>; + type DesiredRunnersUp = ConstU32<2>; type LoserCandidate = (); type KickedMember = (); type WeightInfo = (); @@ -226,7 +218,6 @@ parameter_type_with_key! { parameter_types! { pub DustReceiver: AccountId = PalletId(*b"orml/dst").into_account(); - pub MaxLocks: u32 = 2; } impl Config for Runtime { @@ -237,7 +228,7 @@ impl Config for Runtime { type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; type OnDust = TransferDust; - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<2>; type DustRemovalWhitelist = MockDustRemovalWhitelist; } pub type TreasuryCurrencyAdapter = ::Currency; diff --git a/unknown-tokens/src/mock.rs b/unknown-tokens/src/mock.rs index b30e00efc..6edf639fa 100644 --- a/unknown-tokens/src/mock.rs +++ b/unknown-tokens/src/mock.rs @@ -5,16 +5,15 @@ use super::*; use crate as unknown_tokens; -use frame_support::{construct_runtime, parameter_types, traits::Everything}; +use frame_support::{ + construct_runtime, + traits::{ConstU64, Everything}, +}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; pub type AccountId = AccountId32; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - impl frame_system::Config for Runtime { type Origin = Origin; type Call = Call; @@ -26,7 +25,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); diff --git a/vesting/src/mock.rs b/vesting/src/mock.rs index 5c321148f..c05874ea5 100644 --- a/vesting/src/mock.rs +++ b/vesting/src/mock.rs @@ -5,7 +5,7 @@ use super::*; use frame_support::{ construct_runtime, parameter_types, - traits::{EnsureOrigin, Everything}, + traits::{ConstU32, ConstU64, EnsureOrigin, Everything}, }; use frame_system::RawOrigin; use sp_core::H256; @@ -13,10 +13,6 @@ use sp_runtime::{testing::Header, traits::IdentityLookup}; use crate as vesting; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - pub type AccountId = u128; impl frame_system::Config for Runtime { type Origin = Origin; @@ -29,7 +25,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -47,15 +43,11 @@ impl frame_system::Config for Runtime { type Balance = u64; -parameter_types! { - pub const ExistentialDeposit: u64 = 1; -} - impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type Event = Event; - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU64<1>; type AccountStore = frame_system::Pallet; type MaxLocks = (); type MaxReserves = (); @@ -84,8 +76,6 @@ impl EnsureOrigin for EnsureAliceOrBob { } parameter_types! { - pub const MaxVestingSchedule: u32 = 2; - pub const MinVestedTransfer: u64 = 5; pub static MockBlockNumberProvider: u64 = 0; } @@ -100,10 +90,10 @@ impl BlockNumberProvider for MockBlockNumberProvider { impl Config for Runtime { type Event = Event; type Currency = PalletBalances; - type MinVestedTransfer = MinVestedTransfer; + type MinVestedTransfer = ConstU64<5>; type VestedTransferOrigin = EnsureAliceOrBob; type WeightInfo = (); - type MaxVestingSchedules = MaxVestingSchedule; + type MaxVestingSchedules = ConstU32<2>; type BlockNumberProvider = MockBlockNumberProvider; } diff --git a/weight-meter/src/mock.rs b/weight-meter/src/mock.rs index 1cef5292a..2487e062b 100644 --- a/weight-meter/src/mock.rs +++ b/weight-meter/src/mock.rs @@ -130,15 +130,11 @@ pub mod test_module { } use frame_support::sp_runtime::traits::IdentityLookup; -use frame_support::traits::Everything; +use frame_support::traits::{ConstU128, ConstU64, Everything}; use sp_runtime::testing::{Header, H256}; pub type BlockNumber = u64; -frame_support::parameter_types! { - pub const BlockHashCount: u64 = 250; -} - type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; type Balance = u128; @@ -154,7 +150,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -170,15 +166,11 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -frame_support::parameter_types! { - pub const ExistentialDeposit: u64 = 1; -} - impl pallet_balances::Config for Runtime { type Balance = Balance; type Event = Event; type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128<1>; type AccountStore = frame_system::Pallet; type MaxLocks = (); type MaxReserves = (); diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index d80f5ebbc..ffa1de796 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -3,7 +3,7 @@ use crate as orml_xtokens; use frame_support::{ construct_runtime, match_type, parameter_types, - traits::{Everything, Get, Nothing}, + traits::{ConstU128, ConstU32, ConstU64, Everything, Get, Nothing}, weights::{constants::WEIGHT_PER_SECOND, Weight}, }; use frame_system::EnsureRoot; @@ -30,10 +30,6 @@ use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset} pub type AccountId = AccountId32; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - impl frame_system::Config for Runtime { type Origin = Origin; type Call = Call; @@ -45,7 +41,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -61,21 +57,15 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<50>; type Balance = Balance; type Event = Event; type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); - type MaxReserves = MaxReserves; + type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; } @@ -93,7 +83,7 @@ impl orml_tokens::Config for Runtime { type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; type OnDust = (); - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<50>; type DustRemovalWhitelist = Everything; } @@ -125,11 +115,6 @@ pub type XcmOriginToCallOrigin = ( XcmPassthrough, ); -parameter_types! { - pub const UnitWeightCost: Weight = 10; - pub const MaxInstructions: u32 = 100; -} - pub type LocalAssetTransactor = MultiCurrencyAdapter< Tokens, (), @@ -197,7 +182,7 @@ impl Config for XcmConfig { type IsTeleporter = (); type LocationInverter = LocationInverter; type Barrier = Barrier; - type Weigher = FixedWeightBounds; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; type Trader = AllTokensAreCreatedEqualToWeight; type ResponseHandler = (); type AssetTrap = PolkadotXcm; @@ -247,7 +232,7 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; type LocationInverter = LocationInverter; type Origin = Origin; type Call = Call; @@ -268,7 +253,6 @@ impl Convert for AccountIdToMultiLocation { parameter_types! { pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); - pub const BaseXcmWeight: Weight = 100_000_000; pub const MaxAssetsForTransfer: usize = 3; } @@ -304,8 +288,8 @@ impl orml_xtokens::Config for Runtime { type MultiLocationsFilter = ParentOrParachains; type MinXcmFee = ParachainMinFee; type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; + type BaseXcmWeight = ConstU64<100_000_000>; type LocationInverter = LocationInverter; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = AbsoluteReserveProvider; diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index fe0155d41..5c611c65c 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -3,7 +3,7 @@ use crate as orml_xtokens; use frame_support::{ construct_runtime, match_type, parameter_types, - traits::{Everything, Nothing}, + traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing}, weights::{constants::WEIGHT_PER_SECOND, Weight}, }; use frame_system::EnsureRoot; @@ -33,10 +33,6 @@ use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset} pub type AccountId = AccountId32; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - impl frame_system::Config for Runtime { type Origin = Origin; type Call = Call; @@ -48,7 +44,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -64,21 +60,15 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<50>; type Balance = Balance; type Event = Event; type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); - type MaxReserves = MaxReserves; + type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; } @@ -96,7 +86,7 @@ impl orml_tokens::Config for Runtime { type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; type OnDust = (); - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<50>; type DustRemovalWhitelist = Everything; } @@ -128,11 +118,6 @@ pub type XcmOriginToCallOrigin = ( XcmPassthrough, ); -parameter_types! { - pub const UnitWeightCost: Weight = 10; - pub const MaxInstructions: u32 = 100; -} - pub type LocalAssetTransactor = MultiCurrencyAdapter< Tokens, (), @@ -200,7 +185,7 @@ impl Config for XcmConfig { type IsTeleporter = (); type LocationInverter = LocationInverter; type Barrier = Barrier; - type Weigher = FixedWeightBounds; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; type Trader = AllTokensAreCreatedEqualToWeight; type ResponseHandler = (); type AssetTrap = PolkadotXcm; @@ -250,7 +235,7 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; type LocationInverter = LocationInverter; type Origin = Origin; type Call = Call; @@ -335,7 +320,6 @@ impl Convert> for RelativeCurrencyIdConvert { parameter_types! { pub SelfLocation: MultiLocation = MultiLocation::here(); - pub const BaseXcmWeight: Weight = 100_000_000; pub const MaxAssetsForTransfer: usize = 2; } @@ -371,8 +355,8 @@ impl orml_xtokens::Config for Runtime { type MultiLocationsFilter = ParentOrParachains; type MinXcmFee = ParachainMinFee; type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; + type BaseXcmWeight = ConstU64<100_000_000>; type LocationInverter = LocationInverter; type MaxAssetsForTransfer = MaxAssetsForTransfer; type ReserveProvider = RelativeReserveProvider; diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index 57d0d1e42..a07b76665 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -1,7 +1,7 @@ use frame_support::{ construct_runtime, parameter_types, - traits::Everything, - weights::{IdentityFee, Weight}, + traits::{ConstU128, ConstU32, ConstU64, Everything}, + weights::IdentityFee, }; use frame_system::EnsureRoot; use sp_core::H256; @@ -20,10 +20,6 @@ use xcm_executor::{Config, XcmExecutor}; pub type AccountId = AccountId32; pub type Balance = u128; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - impl frame_system::Config for Runtime { type Origin = Origin; type Call = Call; @@ -35,7 +31,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Header = Header; type Event = Event; - type BlockHashCount = BlockHashCount; + type BlockHashCount = ConstU64<250>; type BlockWeights = (); type BlockLength = (); type Version = (); @@ -51,21 +47,15 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<50>; type Balance = Balance; type Event = Event; type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); - type MaxReserves = MaxReserves; + type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; } @@ -79,7 +69,6 @@ parameter_types! { pub const KsmLocation: MultiLocation = Here.into(); pub const KusamaNetwork: NetworkId = NetworkId::Kusama; pub Ancestry: MultiLocation = Here.into(); - pub UnitWeightCost: Weight = 1; } pub type SovereignAccountOf = ( @@ -96,11 +85,6 @@ type LocalOriginConverter = ( SignedAccountId32AsNative, ); -parameter_types! { - pub const BaseXcmWeight: Weight = 10; - pub const MaxInstructions: u32 = 100; -} - pub type XcmRouter = super::RelayChainXcmRouter; pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); @@ -114,7 +98,7 @@ impl Config for XcmConfig { type IsTeleporter = (); type LocationInverter = LocationInverter; type Barrier = Barrier; - type Weigher = FixedWeightBounds; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; type Trader = UsingComponents, KsmLocation, AccountId, Balances, ()>; type ResponseHandler = (); type AssetTrap = (); @@ -134,7 +118,7 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; + type Weigher = FixedWeightBounds, Call, ConstU32<100>>; type LocationInverter = LocationInverter; type Origin = Origin; type Call = Call; @@ -142,14 +126,10 @@ impl pallet_xcm::Config for Runtime { type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; } -parameter_types! { - pub const FirstMessageFactorPercent: u64 = 100; -} - impl ump::Config for Runtime { type Event = Event; type UmpSink = ump::XcmSink, Runtime>; - type FirstMessageFactorPercent = FirstMessageFactorPercent; + type FirstMessageFactorPercent = ConstU64<100>; type ExecuteOverweightOrigin = EnsureRoot; } From 653f2f17adc3087e2f53019edb4470348ae6b5c3 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Fri, 1 Apr 2022 16:47:33 +1300 Subject: [PATCH 3/3] Replaced paramter types with ConstU types --- auction/src/mock.rs | 2 +- authority/src/mock.rs | 2 +- bencher/test/src/mock.rs | 2 +- benchmarking/src/tests.rs | 7 +++++-- currencies/src/mock.rs | 2 +- gradually-update/src/mock.rs | 2 +- nft/src/mock.rs | 2 +- oracle/src/mock.rs | 2 +- rewards/src/mock.rs | 2 +- tokens/src/mock.rs | 2 +- unknown-tokens/src/mock.rs | 2 +- vesting/src/mock.rs | 2 +- weight-meter/src/mock.rs | 4 ++-- xtokens/src/mock/para.rs | 2 +- xtokens/src/mock/para_relative_view.rs | 2 +- xtokens/src/mock/relay.rs | 2 +- 16 files changed, 21 insertions(+), 18 deletions(-) diff --git a/auction/src/mock.rs b/auction/src/mock.rs index 12568fdd8..d115118f7 100644 --- a/auction/src/mock.rs +++ b/auction/src/mock.rs @@ -42,7 +42,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } pub struct Handler; diff --git a/authority/src/mock.rs b/authority/src/mock.rs index 72333bf2d..1335f0447 100644 --- a/authority/src/mock.rs +++ b/authority/src/mock.rs @@ -51,7 +51,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } parameter_types! { diff --git a/bencher/test/src/mock.rs b/bencher/test/src/mock.rs index 0e63bad11..0c18524ba 100644 --- a/bencher/test/src/mock.rs +++ b/bencher/test/src/mock.rs @@ -54,7 +54,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl crate::pallet::Config for Runtime {} diff --git a/benchmarking/src/tests.rs b/benchmarking/src/tests.rs index a1f8109ab..1f05926e2 100644 --- a/benchmarking/src/tests.rs +++ b/benchmarking/src/tests.rs @@ -4,7 +4,10 @@ use super::*; use frame_benchmarking::account; -use frame_support::{assert_err, assert_ok, construct_runtime, ensure, traits::Everything}; +use frame_support::{ + assert_err, assert_ok, construct_runtime, ensure, + traits::{ConstU32, Everything}, +}; use frame_system::RawOrigin; use sp_runtime::{ testing::{Header, H256}, @@ -72,7 +75,7 @@ impl frame_system::Config for Test { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl Config for Test {} diff --git a/currencies/src/mock.rs b/currencies/src/mock.rs index 5702bbfe9..8596d193b 100644 --- a/currencies/src/mock.rs +++ b/currencies/src/mock.rs @@ -43,7 +43,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } type CurrencyId = u32; diff --git a/gradually-update/src/mock.rs b/gradually-update/src/mock.rs index 3ebbb8152..fc86b9809 100644 --- a/gradually-update/src/mock.rs +++ b/gradually-update/src/mock.rs @@ -39,7 +39,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl Config for Runtime { diff --git a/nft/src/mock.rs b/nft/src/mock.rs index d384cab4b..6ab0e83f6 100644 --- a/nft/src/mock.rs +++ b/nft/src/mock.rs @@ -40,7 +40,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl Config for Runtime { diff --git a/oracle/src/mock.rs b/oracle/src/mock.rs index 6c36a834f..279855402 100644 --- a/oracle/src/mock.rs +++ b/oracle/src/mock.rs @@ -46,7 +46,7 @@ impl frame_system::Config for Test { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } thread_local! { diff --git a/rewards/src/mock.rs b/rewards/src/mock.rs index 26a1f3c26..8a88ed4cd 100644 --- a/rewards/src/mock.rs +++ b/rewards/src/mock.rs @@ -53,7 +53,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } thread_local! { diff --git a/tokens/src/mock.rs b/tokens/src/mock.rs index fd878e3dc..41c50146e 100644 --- a/tokens/src/mock.rs +++ b/tokens/src/mock.rs @@ -62,7 +62,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } thread_local! { diff --git a/unknown-tokens/src/mock.rs b/unknown-tokens/src/mock.rs index 6edf639fa..4ca58bed1 100644 --- a/unknown-tokens/src/mock.rs +++ b/unknown-tokens/src/mock.rs @@ -38,7 +38,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl Config for Runtime { diff --git a/vesting/src/mock.rs b/vesting/src/mock.rs index c05874ea5..dae1b5f91 100644 --- a/vesting/src/mock.rs +++ b/vesting/src/mock.rs @@ -38,7 +38,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } type Balance = u64; diff --git a/weight-meter/src/mock.rs b/weight-meter/src/mock.rs index 2487e062b..ee3e40a95 100644 --- a/weight-meter/src/mock.rs +++ b/weight-meter/src/mock.rs @@ -130,7 +130,7 @@ pub mod test_module { } use frame_support::sp_runtime::traits::IdentityLookup; -use frame_support::traits::{ConstU128, ConstU64, Everything}; +use frame_support::traits::{ConstU128, ConstU32, ConstU64, Everything}; use sp_runtime::testing::{Header, H256}; pub type BlockNumber = u64; @@ -163,7 +163,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index ffa1de796..502821411 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -54,7 +54,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index 5c611c65c..b8b0a0da2 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -57,7 +57,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime { diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index a07b76665..dd88718fe 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -44,7 +44,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Runtime {