Skip to content

Commit ef144b1

Browse files
bkonturbkchr
andauthored
Attempt to avoid specifying BlockHashCount for different mocking::{MockBlock, MockBlockU32, MockBlockU128} (#4543)
While doing some migration/rebase I came in to the situation, where I needed to change `mocking::MockBlock` to `mocking::MockBlockU32`: ``` #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for TestRuntime { type Block = frame_system::mocking::MockBlockU32<TestRuntime>; type AccountData = pallet_balances::AccountData<ThisChainBalance>; } ``` But actual `TestDefaultConfig` for `frame_system` is using `ConstU64` for `type BlockHashCount = frame_support::traits::ConstU64<10>;` [here](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/system/src/lib.rs#L303). Because of this, it force me to specify and add override for `type BlockHashCount = ConstU32<10>`. This PR tries to fix this with `TestBlockHashCount` implementation for `TestDefaultConfig` which supports `u32`, `u64` and `u128` as a `BlockNumber`. ### How to simulate error Just by removing `type BlockHashCount = ConstU32<250>;` [here](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/multisig/src/tests.rs#L44) ``` :~/parity/olkadot-sdk$ cargo test -p pallet-multisig Compiling pallet-multisig v28.0.0 (/home/bparity/parity/aaa/polkadot-sdk/substrate/frame/multisig) error[E0277]: the trait bound `ConstU64<10>: frame_support::traits::Get<u32>` is not satisfied --> substrate/frame/multisig/src/tests.rs:41:1 | 41 | #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `frame_support::traits::Get<u32>` is not implemented for `ConstU64<10>` | = help: the following other types implement trait `frame_support::traits::Get<T>`: <ConstU64<T> as frame_support::traits::Get<u64>> <ConstU64<T> as frame_support::traits::Get<std::option::Option<u64>>> note: required by a bound in `frame_system::Config::BlockHashCount` --> /home/bparity/parity/aaa/polkadot-sdk/substrate/frame/system/src/lib.rs:535:24 | 535 | type BlockHashCount: Get<BlockNumberFor<Self>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Config::BlockHashCount` = note: this error originates in the attribute macro `derive_impl` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens_verbatim` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. error: could not compile `pallet-multisig` (lib test) due to 1 previous error ``` ## For reviewers: (If there is a better solution, please let me know!) The first commit contains actual attempt to fix the problem: 3c5499e. The second commit is just removal of `BlockHashCount` from all other places where not needed by default. Closes: #1657 --------- Co-authored-by: Bastian Köcher <[email protected]>
1 parent 700d591 commit ef144b1

File tree

60 files changed

+30
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+30
-150
lines changed

bridges/bin/runtime-common/src/mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ impl frame_system::Config for TestRuntime {
148148
type AccountId = ThisChainAccountId;
149149
type Block = ThisChainBlock;
150150
type AccountData = pallet_balances::AccountData<ThisChainBalance>;
151-
type BlockHashCount = ConstU32<250>;
152151
}
153152

154153
impl pallet_utility::Config for TestRuntime {

bridges/snowbridge/pallets/inbound-queue/src/mock.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ frame_support::construct_runtime!(
4343
pub type Signature = MultiSignature;
4444
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
4545

46-
parameter_types! {
47-
pub const BlockHashCount: u64 = 250;
48-
}
49-
5046
type Balance = u128;
5147

5248
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
@@ -60,7 +56,6 @@ impl frame_system::Config for Test {
6056
type AccountId = AccountId;
6157
type Lookup = IdentityLookup<Self::AccountId>;
6258
type RuntimeEvent = RuntimeEvent;
63-
type BlockHashCount = BlockHashCount;
6459
type PalletInfo = PalletInfo;
6560
type AccountData = pallet_balances::AccountData<u128>;
6661
type Nonce = u64;

bridges/snowbridge/pallets/outbound-queue/src/mock.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ frame_support::construct_runtime!(
3333
}
3434
);
3535

36-
parameter_types! {
37-
pub const BlockHashCount: u64 = 250;
38-
}
39-
4036
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
4137
impl frame_system::Config for Test {
4238
type BaseCallFilter = Everything;
@@ -48,7 +44,6 @@ impl frame_system::Config for Test {
4844
type AccountId = AccountId;
4945
type Lookup = IdentityLookup<Self::AccountId>;
5046
type RuntimeEvent = RuntimeEvent;
51-
type BlockHashCount = BlockHashCount;
5247
type PalletInfo = PalletInfo;
5348
type Nonce = u64;
5449
type Block = Block;

bridges/snowbridge/pallets/system/src/mock.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate as snowbridge_system;
44
use frame_support::{
55
derive_impl, parameter_types,
6-
traits::{tokens::fungible::Mutate, ConstU128, ConstU64, ConstU8},
6+
traits::{tokens::fungible::Mutate, ConstU128, ConstU8},
77
weights::IdentityFee,
88
PalletId,
99
};
@@ -106,7 +106,6 @@ impl frame_system::Config for Test {
106106
type AccountId = AccountId;
107107
type Lookup = IdentityLookup<Self::AccountId>;
108108
type RuntimeEvent = RuntimeEvent;
109-
type BlockHashCount = ConstU64<250>;
110109
type PalletInfo = PalletInfo;
111110
type AccountData = pallet_balances::AccountData<u128>;
112111
type Nonce = u64;

cumulus/pallets/collator-selection/src/mock.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ frame_support::construct_runtime!(
4646
);
4747

4848
parameter_types! {
49-
pub const BlockHashCount: u64 = 250;
5049
pub const SS58Prefix: u8 = 42;
5150
}
5251

@@ -65,7 +64,6 @@ impl system::Config for Test {
6564
type Lookup = IdentityLookup<Self::AccountId>;
6665
type Block = Block;
6766
type RuntimeEvent = RuntimeEvent;
68-
type BlockHashCount = BlockHashCount;
6967
type Version = ();
7068
type PalletInfo = PalletInfo;
7169
type AccountData = pallet_balances::AccountData<u64>;

cumulus/pallets/parachain-system/src/mock.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ frame_support::construct_runtime!(
5555
);
5656

5757
parameter_types! {
58-
pub const BlockHashCount: u64 = 250;
5958
pub Version: RuntimeVersion = RuntimeVersion {
6059
spec_name: sp_version::create_runtime_str!("test"),
6160
impl_name: sp_version::create_runtime_str!("system-test"),
@@ -74,7 +73,6 @@ parameter_types! {
7473
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
7574
impl frame_system::Config for Test {
7675
type Block = Block;
77-
type BlockHashCount = BlockHashCount;
7876
type Version = Version;
7977
type OnSetCode = ParachainSetCode<Self>;
8078
}

cumulus/pallets/xcmp-queue/src/mock.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ frame_support::construct_runtime!(
5252
);
5353

5454
parameter_types! {
55-
pub const BlockHashCount: u64 = 250;
5655
pub const SS58Prefix: u8 = 42;
5756
}
5857

@@ -73,7 +72,6 @@ impl frame_system::Config for Test {
7372
type Lookup = IdentityLookup<Self::AccountId>;
7473
type Block = Block;
7574
type RuntimeEvent = RuntimeEvent;
76-
type BlockHashCount = BlockHashCount;
7775
type Version = ();
7876
type PalletInfo = PalletInfo;
7977
type AccountData = pallet_balances::AccountData<u64>;

cumulus/parachains/common/src/impls.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ mod tests {
222222
);
223223

224224
parameter_types! {
225-
pub const BlockHashCount: u64 = 250;
226225
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
227226
pub const AvailableBlockRatio: Perbill = Perbill::one();
228227
pub const MaxReserves: u32 = 50;
@@ -240,7 +239,6 @@ mod tests {
240239
type Lookup = IdentityLookup<Self::AccountId>;
241240
type Block = Block;
242241
type RuntimeEvent = RuntimeEvent;
243-
type BlockHashCount = BlockHashCount;
244242
type BlockLength = BlockLength;
245243
type BlockWeights = ();
246244
type DbWeight = ();

cumulus/parachains/pallets/collective-content/src/mock.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
pub use crate as pallet_collective_content;
1919
use crate::WeightInfo;
2020
use frame_support::{
21-
derive_impl, ord_parameter_types, parameter_types,
22-
traits::{ConstU32, ConstU64},
23-
weights::Weight,
21+
derive_impl, ord_parameter_types, parameter_types, traits::ConstU32, weights::Weight,
2422
};
2523
use frame_system::EnsureSignedBy;
2624
use sp_runtime::{traits::IdentityLookup, BuildStorage};
@@ -70,7 +68,6 @@ impl frame_system::Config for Test {
7068
type AccountId = AccountId;
7169
type Lookup = IdentityLookup<Self::AccountId>;
7270
type RuntimeEvent = RuntimeEvent;
73-
type BlockHashCount = ConstU64<250>;
7471
type Version = ();
7572
type PalletInfo = PalletInfo;
7673
type AccountData = ();

polkadot/runtime/common/src/assigned_slots/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,6 @@ mod tests {
671671
type OverarchingCall = RuntimeCall;
672672
}
673673

674-
parameter_types! {
675-
pub const BlockHashCount: u32 = 250;
676-
}
677-
678674
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
679675
impl frame_system::Config for Test {
680676
type BaseCallFilter = frame_support::traits::Everything;
@@ -689,7 +685,6 @@ mod tests {
689685
type Lookup = IdentityLookup<Self::AccountId>;
690686
type Block = Block;
691687
type RuntimeEvent = RuntimeEvent;
692-
type BlockHashCount = BlockHashCount;
693688
type DbWeight = ();
694689
type Version = ();
695690
type PalletInfo = PalletInfo;

0 commit comments

Comments
 (0)