Skip to content

Commit

Permalink
Moves all test runtimes to use derive_impl (paritytech#2409)
Browse files Browse the repository at this point in the history
Step in paritytech#171

This PR adds `derive_impl` on all `frame_system` config impls for mock
runtimes. The overridden configs are maintained as of now to ensure
minimal changes.

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
gupnik and ggwpez authored Nov 28, 2023
1 parent 15a18df commit a000ba2
Show file tree
Hide file tree
Showing 104 changed files with 376 additions and 238 deletions.
6 changes: 5 additions & 1 deletion substrate/bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate as pallet_template;
use frame_support::traits::{ConstU16, ConstU64};
use frame_support::{
derive_impl,
traits::{ConstU16, ConstU64},
};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Expand All @@ -17,6 +20,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ impl<Block: BlockT, BE: Backend<Block>> SubscriptionsInner<Block, BE> {
// blocks.
for hash in hashes.clone() {
if !sub.contains_block(hash) {
return Err(SubscriptionManagementError::BlockHashAbsent);
return Err(SubscriptionManagementError::BlockHashAbsent)
}
}

Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::*;
use crate as pallet_asset_conversion;

use frame_support::{
construct_runtime,
construct_runtime, derive_impl,
instances::{Instance1, Instance2},
ord_parameter_types, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64},
Expand All @@ -48,6 +48,7 @@ construct_runtime!(
}
);

#[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 = ();
Expand Down
6 changes: 5 additions & 1 deletion substrate/frame/asset-rate/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
//! The crate's mock.

use crate as pallet_asset_rate;
use frame_support::traits::{ConstU16, ConstU64};
use frame_support::{
derive_impl,
traits::{ConstU16, ConstU64},
};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Expand All @@ -36,6 +39,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate as pallet_assets;

use codec::Encode;
use frame_support::{
construct_runtime, parameter_types,
construct_runtime, derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64},
};
use sp_core::H256;
Expand All @@ -46,6 +46,7 @@ construct_runtime!(
type AccountId = u64;
type AssetId = u32;

#[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 = ();
Expand Down
6 changes: 5 additions & 1 deletion substrate/frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
use super::*;
use crate as pallet_atomic_swap;

use frame_support::traits::{ConstU32, ConstU64};
use frame_support::{
derive_impl,
traits::{ConstU32, ConstU64},
};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Expand All @@ -38,6 +41,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use crate as pallet_aura;
use frame_support::{
parameter_types,
derive_impl, parameter_types,
traits::{ConstU32, ConstU64, DisabledValidators},
};
use sp_consensus_aura::{ed25519::AuthorityId, AuthorityIndex};
Expand All @@ -41,6 +41,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod tests {
use super::*;
use crate as pallet_authority_discovery;
use frame_support::{
parameter_types,
derive_impl, parameter_types,
traits::{ConstU32, ConstU64},
};
use sp_application_crypto::Pair;
Expand Down Expand Up @@ -225,6 +225,7 @@ mod tests {
pub const Offset: BlockNumber = 0;
}

#[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 = ();
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use crate::{self as pallet_balances, AccountData, Config, CreditOf, Error, Pallet};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
assert_err, assert_noop, assert_ok, assert_storage_noop,
assert_err, assert_noop, assert_ok, assert_storage_noop, derive_impl,
dispatch::{DispatchInfo, GetDispatchInfo},
parameter_types,
traits::{
Expand Down Expand Up @@ -90,6 +90,8 @@ parameter_types! {
);
pub static ExistentialDeposit: u64 = 1;
}

#[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;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/benchmarking/pov/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ frame_benchmarking::benchmarks! {

#[cfg(test)]
mod mock {
use frame_support::derive_impl;
use sp_runtime::{testing::H256, BuildStorage};

type AccountId = u64;
Expand All @@ -354,6 +355,7 @@ mod mock {
}
);

#[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 = ();
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/benchmarking/pov/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ fn noop_is_free() {
}

mod mock {
use frame_support::derive_impl;
use sp_runtime::testing::H256;

type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -174,6 +175,7 @@ mod mock {
}
);

#[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 = ();
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/benchmarking/src/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ benchmarks! {

#[cfg(test)]
pub mod mock {
use frame_support::derive_impl;
use sp_runtime::{testing::H256, BuildStorage};

type AccountId = u64;
Expand All @@ -124,6 +125,7 @@ pub mod mock {
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#![cfg(test)]

use frame_support::{parameter_types, traits::ConstU32};
use frame_support::{derive_impl, parameter_types, traits::ConstU32};
use sp_runtime::{
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -75,6 +75,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/benchmarking/src/tests_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#![cfg(test)]

use frame_support::traits::ConstU32;
use frame_support::{derive_impl, traits::ConstU32};
use sp_runtime::{
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -85,6 +85,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::*;
use crate as pallet_bounties;

use frame_support::{
assert_noop, assert_ok, parameter_types,
assert_noop, assert_ok, derive_impl, parameter_types,
traits::{
tokens::{PayFromAccount, UnityAssetBalanceConversion},
ConstU32, ConstU64, OnInitialize,
Expand Down Expand Up @@ -59,6 +59,7 @@ parameter_types! {

type Balance = u64;

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/broker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use crate::{test_fungibles::TestFungibles, *};
use frame_support::{
assert_ok, ensure, ord_parameter_types, parameter_types,
assert_ok, derive_impl, ensure, ord_parameter_types, parameter_types,
traits::{
fungible::{Balanced, Credit, Inspect, ItemOf, Mutate},
nonfungible::Inspect as NftInspect,
Expand Down Expand Up @@ -47,6 +47,7 @@ frame_support::construct_runtime!(
}
);

#[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 = ();
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/child-bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::*;
use crate as pallet_child_bounties;

use frame_support::{
assert_noop, assert_ok, parameter_types,
assert_noop, assert_ok, derive_impl, parameter_types,
traits::{
tokens::{PayFromAccount, UnityAssetBalanceConversion},
ConstU32, ConstU64, OnInitialize,
Expand Down Expand Up @@ -62,6 +62,7 @@ parameter_types! {

type Balance = u64;

#[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 = ();
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use super::{Event as CollectiveEvent, *};
use crate as pallet_collective;
use frame_support::{
assert_noop, assert_ok,
assert_noop, assert_ok, derive_impl,
dispatch::Pays,
parameter_types,
traits::{ConstU32, ConstU64, StorageVersion},
Expand Down Expand Up @@ -90,6 +90,8 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(Weight::MAX);
pub static MaxProposalWeight: Weight = default_max_proposal_weight();
}

#[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;
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/contracts/mock-network/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
};
use core::marker::PhantomData;
use frame_support::{
construct_runtime, parameter_types,
construct_runtime, derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, Contains, ContainsPair, Everything, EverythingBut, Nothing},
weights::{
constants::{WEIGHT_PROOF_SIZE_PER_MB, WEIGHT_REF_TIME_PER_SECOND},
Expand Down Expand Up @@ -53,6 +53,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/contracts/mock-network/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Relay chain runtime mock.

use frame_support::{
construct_runtime, parameter_types,
construct_runtime, derive_impl, parameter_types,
traits::{Contains, Everything, Nothing},
weights::Weight,
};
Expand Down Expand Up @@ -47,6 +47,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use assert_matches::assert_matches;
use codec::Encode;
use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_err_with_weight, assert_noop, assert_ok,
derive_impl,
dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo},
parameter_types,
storage::child,
Expand Down Expand Up @@ -332,6 +333,8 @@ parameter_types! {
);
pub static ExistentialDeposit: u64 = 1;
}

#[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;
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/conviction-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::collections::BTreeMap;

use frame_support::{
assert_noop, assert_ok, parameter_types,
assert_noop, assert_ok, derive_impl, parameter_types,
traits::{ConstU32, ConstU64, Contains, Polling, VoteTally},
};
use sp_core::H256;
Expand Down Expand Up @@ -51,6 +51,7 @@ impl Contains<RuntimeCall> for BaseFilter {
}
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type BlockWeights = ();
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/core-fellowship/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::collections::BTreeMap;

use frame_support::{
assert_noop, assert_ok, ord_parameter_types,
assert_noop, assert_ok, derive_impl, ord_parameter_types,
pallet_prelude::Weight,
parameter_types,
traits::{tokens::GetSalary, ConstU32, ConstU64, Everything, IsInVec, TryMapSuccess},
Expand Down Expand Up @@ -50,6 +50,8 @@ parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1_000_000, u64::max_value()));
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
Expand Down
Loading

0 comments on commit a000ba2

Please sign in to comment.