Skip to content

Commit

Permalink
Attempt to avoid specifying BlockHashCount for different `mocking::…
Browse files Browse the repository at this point in the history
…{MockBlock, MockBlockU32, MockBlockU128}`.
  • Loading branch information
bkontur committed May 22, 2024
1 parent b06306c commit 3c5499e
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,29 @@ pub mod pallet {
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::{inject_runtime_type, DefaultConfig};
use frame_support::derive_impl;
use frame_support::{derive_impl, traits::Get};

/// A predefined adapter that covers `BlockNumberFor<T>` for `Config::Block::BlockNumber` of
/// the types `u32`, `u64`, and `u128`.
///
/// NOTE: Avoids overriding `BlockHashCount` when using `mocking::{MockBlock, MockBlockU32,
/// MockBlockU128}`.
pub struct TestBlockHashCount<C: Get<u32>>(sp_std::marker::PhantomData<C>);
impl<C: Get<u32>> Get<u32> for TestBlockHashCount<C> {
fn get() -> u32 {
C::get()
}
}
impl<C: Get<u32>> Get<u64> for TestBlockHashCount<C> {
fn get() -> u64 {
C::get().into()
}
}
impl<C: Get<u32>> Get<u128> for TestBlockHashCount<C> {
fn get() -> u128 {
C::get().into()
}
}

/// Provides a viable default config that can be used with
/// [`derive_impl`](`frame_support::derive_impl`) to derive a testing pallet config
Expand Down Expand Up @@ -300,7 +322,7 @@ pub mod pallet {
#[inject_runtime_type]
type RuntimeTask = ();
type BaseCallFilter = frame_support::traits::Everything;
type BlockHashCount = frame_support::traits::ConstU64<10>;
type BlockHashCount = TestBlockHashCount<frame_support::traits::ConstU32<10>>;
type OnSetCode = ();
type SingleBlockMigrations = ();
type MultiBlockMigrator = ();
Expand Down Expand Up @@ -397,7 +419,7 @@ pub mod pallet {

/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
/// Using 256 as default.
type BlockHashCount = frame_support::traits::ConstU32<256>;
type BlockHashCount = TestBlockHashCount<frame_support::traits::ConstU32<256>>;

/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
Expand Down

0 comments on commit 3c5499e

Please sign in to comment.