From 49b67572ec63f3d64984545f7710cb5e86f2ec7b Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 19 Sep 2023 17:15:56 +0200 Subject: [PATCH 1/9] migrate alliance, fast-unstake and bags list to use derive-impl --- substrate/frame/alliance/src/mock.rs | 27 +++--------------- substrate/frame/bags-list/src/mock.rs | 26 ++--------------- substrate/frame/bags-list/src/tests.rs | 6 ++-- .../test-staking-e2e/src/mock.rs | 8 ------ .../frame/examples/kitchensink/src/tests.rs | 8 ------ substrate/frame/examples/split/src/mock.rs | 7 ----- substrate/frame/fast-unstake/src/mock.rs | 28 ++++--------------- 7 files changed, 15 insertions(+), 95 deletions(-) diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index f04e7e414ed9..6cca209fba38 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -26,7 +26,7 @@ pub use sp_runtime::{ use sp_std::convert::{TryFrom, TryInto}; 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}, BoundedVec, }; @@ -45,30 +45,11 @@ parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = 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 { - 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; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type AccountData = pallet_balances::AccountData; } parameter_types! { diff --git a/substrate/frame/bags-list/src/mock.rs b/substrate/frame/bags-list/src/mock.rs index ae50adabd508..9946a2198ac4 100644 --- a/substrate/frame/bags-list/src/mock.rs +++ b/substrate/frame/bags-list/src/mock.rs @@ -20,11 +20,11 @@ use super::*; use crate::{self as bags_list}; use frame_election_provider_support::VoteWeight; -use frame_support::parameter_types; +use frame_support::{derive_impl, parameter_types}; use sp_runtime::BuildStorage; use std::collections::HashMap; -pub type AccountId = u32; +pub type AccountId = ::AccountId; pub type Balance = u32; parameter_types! { @@ -48,30 +48,10 @@ impl frame_election_provider_support::ScoreProvider for StakingMock { } } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] 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; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type DbWeight = (); - type BlockLength = (); - type BlockWeights = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { diff --git a/substrate/frame/bags-list/src/tests.rs b/substrate/frame/bags-list/src/tests.rs index 9e8508698d8e..2012cc3d014f 100644 --- a/substrate/frame/bags-list/src/tests.rs +++ b/substrate/frame/bags-list/src/tests.rs @@ -163,7 +163,7 @@ mod pallet { assert_eq!(Bag::::get(10).unwrap(), Bag::new(Some(1), Some(3), 10)); assert_eq!(Bag::::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 StakingMock::set_score_of(&2, 10); @@ -272,10 +272,10 @@ mod pallet { // given assert_eq!(List::::get_bags(), vec![(20, vec![10, 11, 12])]); // 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 - assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11u32, 10)); + assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11, 10)); // then assert_eq!(List::::get_bags(), vec![(20, vec![11, 10, 12])]); diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index ec646c311978..f45b52cdd825 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -89,14 +89,6 @@ pub(crate) type Moment = u32; #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { 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; } diff --git a/substrate/frame/examples/kitchensink/src/tests.rs b/substrate/frame/examples/kitchensink/src/tests.rs index b2af7c8983f5..abded83e4820 100644 --- a/substrate/frame/examples/kitchensink/src/tests.rs +++ b/substrate/frame/examples/kitchensink/src/tests.rs @@ -39,15 +39,7 @@ frame_support::construct_runtime!( /// details. #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; 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; } diff --git a/substrate/frame/examples/split/src/mock.rs b/substrate/frame/examples/split/src/mock.rs index bee3633ef68f..4e4f66475a2e 100644 --- a/substrate/frame/examples/split/src/mock.rs +++ b/substrate/frame/examples/split/src/mock.rs @@ -35,13 +35,6 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { 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 { diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index dc24a823c0db..91945a6b1b97 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -17,7 +17,7 @@ use crate::{self as fast_unstake}; use frame_support::{ - assert_ok, + assert_ok, derive_impl, pallet_prelude::*, parameter_types, traits::{ConstU64, Currency}, @@ -32,7 +32,6 @@ use pallet_staking::{Exposure, IndividualExposure, StakerStatus}; use sp_std::prelude::*; pub type AccountId = u128; -pub type Nonce = u32; pub type BlockNumber = u64; pub type Balance = u128; 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 { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = BlockWeights; - type BlockLength = (); - 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 Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + // we use U128 account id in this pallet for a good reason. + type AccountId = AccountId; + type Lookup = IdentityLookup; } impl pallet_timestamp::Config for Runtime { From e9b56265ee133bba665036d12eace96570c2120b Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:00:34 +0200 Subject: [PATCH 2/9] Update substrate/frame/alliance/src/mock.rs Co-authored-by: Adrian Catangiu --- substrate/frame/alliance/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 6cca209fba38..82dbbe9c0bb9 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -49,7 +49,7 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { type Block = Block; - type AccountData = pallet_balances::AccountData; + type AccountData = pallet_balances::AccountData; } parameter_types! { From b304cfd9cad3b5db2fa39e2f48b64ea6d7e77bf5 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 20 Sep 2023 13:47:16 +0200 Subject: [PATCH 3/9] switch default MockBlock to be u32 --- substrate/frame/alliance/src/mock.rs | 2 +- .../test-staking-e2e/src/mock.rs | 2 +- substrate/frame/fast-unstake/src/mock.rs | 4 ++-- substrate/frame/multisig/src/tests.rs | 2 +- substrate/frame/state-trie-migration/src/lib.rs | 2 +- substrate/frame/system/src/lib.rs | 2 +- substrate/frame/system/src/mock.rs | 2 +- substrate/frame/system/src/mocking.rs | 9 ++++++--- substrate/frame/system/src/tests.rs | 2 +- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 6cca209fba38..7ed2057a1642 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -37,7 +37,7 @@ pub use crate as pallet_alliance; use super::*; -type BlockNumber = u64; +type BlockNumber = u32; type AccountId = u64; parameter_types! { diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index f45b52cdd825..a5d9c0242506 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -61,7 +61,7 @@ use crate::{log, log_current_time}; pub const INIT_TIMESTAMP: BlockNumber = 30_000; pub const BLOCK_TIME: BlockNumber = 1000; -type Block = frame_system::mocking::MockBlockU32; +type Block = frame_system::mocking::MockBlock; type Extrinsic = testing::TestXt; frame_support::construct_runtime!( diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index 91945a6b1b97..e2a718604e4c 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -32,7 +32,7 @@ use pallet_staking::{Exposure, IndividualExposure, StakerStatus}; use sp_std::prelude::*; pub type AccountId = u128; -pub type BlockNumber = u64; +pub type BlockNumber = u32; pub type Balance = u128; pub type T = Runtime; @@ -311,7 +311,7 @@ impl ExtBuilder { } } -pub(crate) fn run_to_block(n: u64, on_idle: bool) { +pub(crate) fn run_to_block(n: BlockNumber, on_idle: bool) { let current_block = System::block_number(); assert!(n > current_block); while System::block_number() < n { diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index e7fc5b3e4aae..e3058f7b9a8c 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -28,7 +28,7 @@ use frame_support::{ }; use sp_runtime::{BuildStorage, TokenError}; -type Block = frame_system::mocking::MockBlockU32; +type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( pub enum Test diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 3e69b219bb52..632e5871dead 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1065,7 +1065,7 @@ mod mock { BuildStorage, StorageChild, }; - type Block = frame_system::mocking::MockBlockU32; + type Block = frame_system::mocking::MockBlock; // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 84b6dc031457..e8df85345cb2 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -241,7 +241,7 @@ pub mod pallet { #[inject_runtime_type] type PalletInfo = (); type BaseCallFilter = frame_support::traits::Everything; - type BlockHashCount = frame_support::traits::ConstU64<10>; + type BlockHashCount = frame_support::traits::ConstU32<10>; type OnSetCode = (); } } diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index c016ea9e1cd1..110b3dd858f1 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -98,7 +98,7 @@ impl Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<10>; + type BlockHashCount = ConstU32<10>; type DbWeight = DbWeight; type Version = Version; type PalletInfo = PalletInfo; diff --git a/substrate/frame/system/src/mocking.rs b/substrate/frame/system/src/mocking.rs index 833309e05ecc..d0dd66052b1b 100644 --- a/substrate/frame/system/src/mocking.rs +++ b/substrate/frame/system/src/mocking.rs @@ -28,13 +28,16 @@ pub type MockUncheckedExtrinsic = generic::Unchec >; /// An implementation of `sp_runtime::traits::Block` to be used in tests. +/// +/// This is preferred as the default block type, since the "real block type" that is commonly used +/// in production (e.g. Polkadot) is also u32. pub type MockBlock = generic::Block< - generic::Header, + generic::Header, MockUncheckedExtrinsic, >; -/// An implementation of `sp_runtime::traits::Block` to be used in tests with u32 BlockNumber type. -pub type MockBlockU32 = generic::Block< +/// An implementation of `sp_runtime::traits::Block` to be used in tests with u64 BlockNumber type. +pub type MockBlockU64 = generic::Block< generic::Header, MockUncheckedExtrinsic, >; diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index 165df688b1c2..8fdb23b06aa3 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -512,7 +512,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() { #[test] fn deposit_event_topics() { new_test_ext().execute_with(|| { - const BLOCK_NUMBER: u64 = 1; + const BLOCK_NUMBER: u32 = 1; System::reset_events(); System::initialize(&BLOCK_NUMBER, &[0u8; 32].into(), &Default::default()); From a319f936d9eb5ec4b927b01d93d5cabf21dbe510 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 20 Sep 2023 15:23:39 +0200 Subject: [PATCH 4/9] Revert "switch default MockBlock to be u32" This reverts commit b304cfd9cad3b5db2fa39e2f48b64ea6d7e77bf5. --- substrate/frame/alliance/src/mock.rs | 2 +- .../test-staking-e2e/src/mock.rs | 2 +- substrate/frame/fast-unstake/src/mock.rs | 4 ++-- substrate/frame/multisig/src/tests.rs | 2 +- substrate/frame/state-trie-migration/src/lib.rs | 2 +- substrate/frame/system/src/lib.rs | 2 +- substrate/frame/system/src/mock.rs | 2 +- substrate/frame/system/src/mocking.rs | 9 +++------ substrate/frame/system/src/tests.rs | 2 +- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index eb9be7a4a117..82dbbe9c0bb9 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -37,7 +37,7 @@ pub use crate as pallet_alliance; use super::*; -type BlockNumber = u32; +type BlockNumber = u64; type AccountId = u64; parameter_types! { diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index a5d9c0242506..f45b52cdd825 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -61,7 +61,7 @@ use crate::{log, log_current_time}; pub const INIT_TIMESTAMP: BlockNumber = 30_000; pub const BLOCK_TIME: BlockNumber = 1000; -type Block = frame_system::mocking::MockBlock; +type Block = frame_system::mocking::MockBlockU32; type Extrinsic = testing::TestXt; frame_support::construct_runtime!( diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index e2a718604e4c..91945a6b1b97 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -32,7 +32,7 @@ use pallet_staking::{Exposure, IndividualExposure, StakerStatus}; use sp_std::prelude::*; pub type AccountId = u128; -pub type BlockNumber = u32; +pub type BlockNumber = u64; pub type Balance = u128; pub type T = Runtime; @@ -311,7 +311,7 @@ impl ExtBuilder { } } -pub(crate) fn run_to_block(n: BlockNumber, on_idle: bool) { +pub(crate) fn run_to_block(n: u64, on_idle: bool) { let current_block = System::block_number(); assert!(n > current_block); while System::block_number() < n { diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index e3058f7b9a8c..e7fc5b3e4aae 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -28,7 +28,7 @@ use frame_support::{ }; use sp_runtime::{BuildStorage, TokenError}; -type Block = frame_system::mocking::MockBlock; +type Block = frame_system::mocking::MockBlockU32; frame_support::construct_runtime!( pub enum Test diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 632e5871dead..3e69b219bb52 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1065,7 +1065,7 @@ mod mock { BuildStorage, StorageChild, }; - type Block = frame_system::mocking::MockBlock; + type Block = frame_system::mocking::MockBlockU32; // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index e8df85345cb2..84b6dc031457 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -241,7 +241,7 @@ pub mod pallet { #[inject_runtime_type] type PalletInfo = (); type BaseCallFilter = frame_support::traits::Everything; - type BlockHashCount = frame_support::traits::ConstU32<10>; + type BlockHashCount = frame_support::traits::ConstU64<10>; type OnSetCode = (); } } diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index 110b3dd858f1..c016ea9e1cd1 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -98,7 +98,7 @@ impl Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU32<10>; + type BlockHashCount = ConstU64<10>; type DbWeight = DbWeight; type Version = Version; type PalletInfo = PalletInfo; diff --git a/substrate/frame/system/src/mocking.rs b/substrate/frame/system/src/mocking.rs index d0dd66052b1b..833309e05ecc 100644 --- a/substrate/frame/system/src/mocking.rs +++ b/substrate/frame/system/src/mocking.rs @@ -28,16 +28,13 @@ pub type MockUncheckedExtrinsic = generic::Unchec >; /// An implementation of `sp_runtime::traits::Block` to be used in tests. -/// -/// This is preferred as the default block type, since the "real block type" that is commonly used -/// in production (e.g. Polkadot) is also u32. pub type MockBlock = generic::Block< - generic::Header, + generic::Header, MockUncheckedExtrinsic, >; -/// An implementation of `sp_runtime::traits::Block` to be used in tests with u64 BlockNumber type. -pub type MockBlockU64 = generic::Block< +/// An implementation of `sp_runtime::traits::Block` to be used in tests with u32 BlockNumber type. +pub type MockBlockU32 = generic::Block< generic::Header, MockUncheckedExtrinsic, >; diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index 8fdb23b06aa3..165df688b1c2 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -512,7 +512,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() { #[test] fn deposit_event_topics() { new_test_ext().execute_with(|| { - const BLOCK_NUMBER: u32 = 1; + const BLOCK_NUMBER: u64 = 1; System::reset_events(); System::initialize(&BLOCK_NUMBER, &[0u8; 32].into(), &Default::default()); From 97f953e16fea79c75489ce1aa0029fef10a4feda Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 20 Sep 2023 15:37:21 +0200 Subject: [PATCH 5/9] update --- substrate/frame/balances/src/lib.rs | 19 ++++++++++++------- substrate/frame/multisig/src/tests.rs | 13 ++----------- substrate/frame/proxy/src/tests.rs | 11 ----------- substrate/frame/support/procedural/src/lib.rs | 2 ++ 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index 5da6600d8796..a2cacc45369a 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -216,7 +216,7 @@ pub mod pallet { /// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`]. pub mod config_preludes { use super::*; - use frame_support::derive_impl; + use frame_support::{derive_impl, traits::ConstU64}; pub struct TestDefaultConfig; @@ -227,12 +227,17 @@ pub mod pallet { impl DefaultConfig for TestDefaultConfig { #[inject_runtime_type] type RuntimeEvent = (); + #[inject_runtime_type] + type RuntimeHoldReason = (); type Balance = u64; + type ExistentialDeposit = ConstU64<1>; type ReserveIdentifier = (); type FreezeIdentifier = (); + type DustRemoval = (); + type MaxLocks = (); type MaxReserves = (); type MaxFreezes = (); @@ -249,6 +254,10 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The overarching hold reason. + #[pallet::no_default_bounds] + type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; @@ -266,7 +275,7 @@ pub mod pallet { + FixedPointOperand; /// Handler for the unbalanced reduction when removing a dust account. - #[pallet::no_default] + #[pallet::no_default_bounds] type DustRemoval: OnUnbalanced>; /// 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! #[pallet::constant] - #[pallet::no_default] + #[pallet::no_default_bounds] type ExistentialDeposit: Get; /// 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/` 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. type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index e7fc5b3e4aae..afb8cb27b7e3 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -43,24 +43,15 @@ frame_support::construct_runtime!( impl frame_system::Config for Test { type Block = Block; 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; + // This pallet wishes to overwrite this. + type BaseCallFilter = TestBaseCallFilter; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeHoldReason = (); type ReserveIdentifier = [u8; 8]; - type DustRemoval = (); type AccountStore = System; - type ExistentialDeposit = ConstU64<1>; } pub struct TestBaseCallFilter; diff --git a/substrate/frame/proxy/src/tests.rs b/substrate/frame/proxy/src/tests.rs index 0667be6e1e52..89bd8b68f091 100644 --- a/substrate/frame/proxy/src/tests.rs +++ b/substrate/frame/proxy/src/tests.rs @@ -45,25 +45,14 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { 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 AccountData = pallet_balances::AccountData; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeHoldReason = (); type ReserveIdentifier = [u8; 8]; - type DustRemoval = (); type AccountStore = System; - type ExistentialDeposit = ConstU64<1>; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index 9957cf1cff85..62f503d117dc 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -877,6 +877,8 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream { if item.ident != "RuntimeCall" && item.ident != "RuntimeEvent" && item.ident != "RuntimeOrigin" && + item.ident != "RuntimeHoldReason" && + item.ident != "RuntimeFreezeReason" && item.ident != "PalletInfo" { return syn::Error::new_spanned( From e652c54680b575bfe2aaea794c79f37e5cd505ce Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 20 Sep 2023 15:41:52 +0200 Subject: [PATCH 6/9] update XCM builder as well --- polkadot/xcm/xcm-builder/src/tests/pay/mock.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index c663b0a4d76f..5b6fa3ee5a0b 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -49,22 +49,12 @@ construct_runtime!( } ); -parameter_types! { - pub const BlockHashCount: BlockNumber = 250; -} - #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { 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; type AccountId = AccountId; + type BlockHashCount = ConstU32<256>; type Lookup = sp_runtime::traits::IdentityLookup; } From bfcb62da9a6668496198a6eab5f5322a1d658e16 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 25 Sep 2023 09:51:51 +0200 Subject: [PATCH 7/9] update --- .../test-staking-e2e/src/mock.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index f45b52cdd825..2e3cb15f9a43 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -65,8 +65,7 @@ type Block = frame_system::mocking::MockBlockU32; type Extrinsic = testing::TestXt; frame_support::construct_runtime!( - pub enum Runtime - { + pub enum Runtime { System: frame_system, ElectionProviderMultiPhase: pallet_election_provider_multi_phase, Staking: pallet_staking, @@ -90,6 +89,7 @@ pub(crate) type Moment = u32; impl frame_system::Config for Runtime { type Block = Block; type AccountData = pallet_balances::AccountData; + type BlockHashCount = ConstU32<10>; } const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); From 8f9935929543e08d49f7878a882d295cf918668b Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Tue, 26 Sep 2023 21:09:24 +0200 Subject: [PATCH 8/9] Update substrate/frame/bags-list/src/tests.rs Co-authored-by: Keith Yeung --- substrate/frame/bags-list/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/bags-list/src/tests.rs b/substrate/frame/bags-list/src/tests.rs index 2012cc3d014f..0b382a4fcefa 100644 --- a/substrate/frame/bags-list/src/tests.rs +++ b/substrate/frame/bags-list/src/tests.rs @@ -275,7 +275,7 @@ mod pallet { StakingMock::set_score_of(&11u64, 17); // when - assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11, 10)); + assert_ok!(BagsList::put_in_front_of_other(RuntimeOrigin::signed(42), 11u64, 10)); // then assert_eq!(List::::get_bags(), vec![(20, vec![11, 10, 12])]); From 581e218b3a9c777e90b1b7e89af9dfc7fb312beb Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 26 Sep 2023 21:54:26 +0200 Subject: [PATCH 9/9] fix --- substrate/frame/examples/split/src/mock.rs | 1 - substrate/frame/fast-unstake/src/mock.rs | 2 +- substrate/frame/multisig/src/tests.rs | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/frame/examples/split/src/mock.rs b/substrate/frame/examples/split/src/mock.rs index 4e4f66475a2e..caab4f1ae902 100644 --- a/substrate/frame/examples/split/src/mock.rs +++ b/substrate/frame/examples/split/src/mock.rs @@ -17,7 +17,6 @@ use crate as pallet_template; use frame_support::{derive_impl, sp_runtime::BuildStorage}; -use sp_core::ConstU64; type Block = frame_system::mocking::MockBlock; diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index 91945a6b1b97..cf274c784f9f 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -47,7 +47,7 @@ parameter_types! { impl frame_system::Config for Runtime { type Block = Block; type AccountData = pallet_balances::AccountData; - // we use U128 account id in this pallet for a good reason. + // we use U128 account id in order to get a better iteration order out of a map. type AccountId = AccountId; type Lookup = IdentityLookup; } diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index afb8cb27b7e3..179827255291 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -31,8 +31,7 @@ use sp_runtime::{BuildStorage, TokenError}; type Block = frame_system::mocking::MockBlockU32; frame_support::construct_runtime!( - pub enum Test - { + pub enum Test { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Multisig: pallet_multisig::{Pallet, Call, Storage, Event},