Skip to content

Commit

Permalink
switch default MockBlock to be u32
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma committed Sep 20, 2023
1 parent 49b6757 commit b304cfd
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use crate as pallet_alliance;

use super::*;

type BlockNumber = u64;
type BlockNumber = u32;
type AccountId = u64;

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
type Extrinsic = testing::TestXt<RuntimeCall, ()>;

frame_support::construct_runtime!(
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/multisig/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use frame_support::{
};
use sp_runtime::{BuildStorage, TokenError};

type Block = frame_system::mocking::MockBlockU32<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/state-trie-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ mod mock {
BuildStorage, StorageChild,
};

type Block = frame_system::mocking::MockBlockU32<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
}
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Config for Test {
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<10>;
type BlockHashCount = ConstU32<10>;
type DbWeight = DbWeight;
type Version = Version;
type PalletInfo = PalletInfo;
Expand Down
9 changes: 6 additions & 3 deletions substrate/frame/system/src/mocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ pub type MockUncheckedExtrinsic<T, Signature = (), Extra = ()> = 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<T> = generic::Block<
generic::Header<u64, sp_runtime::traits::BlakeTwo256>,
generic::Header<u32, sp_runtime::traits::BlakeTwo256>,
MockUncheckedExtrinsic<T>,
>;

/// An implementation of `sp_runtime::traits::Block` to be used in tests with u32 BlockNumber type.
pub type MockBlockU32<T> = generic::Block<
/// An implementation of `sp_runtime::traits::Block` to be used in tests with u64 BlockNumber type.
pub type MockBlockU64<T> = generic::Block<
generic::Header<u32, sp_runtime::traits::BlakeTwo256>,
MockUncheckedExtrinsic<T>,
>;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit b304cfd

Please sign in to comment.