From b304cfd9cad3b5db2fa39e2f48b64ea6d7e77bf5 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 20 Sep 2023 13:47:16 +0200 Subject: [PATCH] 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 6cca209fba38d..7ed2057a1642d 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 f45b52cdd8257..a5d9c0242506c 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 91945a6b1b97e..e2a718604e4c9 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 e7fc5b3e4aaea..e3058f7b9a8c6 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 3e69b219bb527..632e5871dead0 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 84b6dc031457d..e8df85345cb20 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 c016ea9e1cd14..110b3dd858f16 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 833309e05ecc9..d0dd66052b1b7 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 165df688b1c2c..8fdb23b06aa38 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());