diff --git a/Cargo.lock b/Cargo.lock index 397d0c7fe823..5405ea8b2213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11900,19 +11900,13 @@ name = "pallet-alliance" version = "27.0.0" dependencies = [ "array-bytes", - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-balances 28.0.0", "pallet-collective 28.0.0", "pallet-identity 29.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-crypto-hashing 0.1.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] @@ -19443,6 +19437,7 @@ dependencies = [ "sp-consensus-aura 0.32.0", "sp-consensus-grandpa 13.0.0", "sp-core 28.0.0", + "sp-crypto-hashing 0.1.0", "sp-genesis-builder 0.8.0", "sp-inherents 26.0.0", "sp-io 30.0.0", diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 8fc0d8468430..9e4714fbe1c7 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -40,6 +40,7 @@ sp-api = { optional = true, workspace = true } sp-block-builder = { optional = true, workspace = true } sp-consensus-aura = { optional = true, workspace = true } sp-consensus-grandpa = { optional = true, workspace = true } +sp-crypto-hashing = { optional = true, workspace = true } sp-genesis-builder = { optional = true, workspace = true } sp-inherents = { optional = true, workspace = true } sp-keyring = { optional = true, workspace = true } @@ -75,6 +76,7 @@ runtime = [ "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", + "sp-crypto-hashing", "sp-genesis-builder", "sp-inherents", "sp-keyring", @@ -101,6 +103,7 @@ std = [ "sp-consensus-aura?/std", "sp-consensus-grandpa?/std", "sp-core/std", + "sp-crypto-hashing?/std", "sp-genesis-builder?/std", "sp-inherents?/std", "sp-io/std", @@ -117,6 +120,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", + "sp-crypto-hashing", "sp-runtime/runtime-benchmarks", ] try-runtime = [ diff --git a/substrate/frame/alliance/Cargo.toml b/substrate/frame/alliance/Cargo.toml index 9d21b9e964c9..f1ed4c8b2c34 100644 --- a/substrate/frame/alliance/Cargo.toml +++ b/substrate/frame/alliance/Cargo.toml @@ -17,62 +17,39 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] array-bytes = { optional = true, workspace = true, default-features = true } -log = { workspace = true } - codec = { features = ["derive"], workspace = true } -scale-info = { features = ["derive"], workspace = true } - -sp-core = { workspace = true } -sp-crypto-hashing = { optional = true, workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } - -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } - +frame = { workspace = true, features = ["runtime"] } +log = { workspace = true } pallet-collective = { optional = true, workspace = true } pallet-identity = { workspace = true } +scale-info = { features = ["derive"], workspace = true } [dev-dependencies] array-bytes = { workspace = true, default-features = true } pallet-balances = { workspace = true, default-features = true } pallet-collective = { workspace = true, default-features = true } -sp-crypto-hashing = { workspace = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-balances/std", "pallet-collective?/std", "pallet-identity/std", "scale-info/std", - "sp-core/std", - "sp-crypto-hashing?/std", - "sp-io/std", - "sp-runtime/std", ] runtime-benchmarks = [ "array-bytes", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-identity/runtime-benchmarks", - "sp-crypto-hashing", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", "pallet-collective?/try-runtime", "pallet-identity/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index 09e2045555b6..faa072e09079 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -19,25 +19,20 @@ #![cfg(feature = "runtime-benchmarks")] -use core::{cmp, mem::size_of}; -use sp_runtime::traits::{Bounded, Hash, StaticLookup}; - -use frame_benchmarking::{account, v2::*, BenchmarkError}; -use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}; -use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin}; - use super::{Call as AllianceCall, Pallet as Alliance, *}; +use core::{cmp, mem::size_of}; +use frame::benchmarking::prelude::{frame_system::Pallet as System, RawOrigin as SystemOrigin, *}; const SEED: u32 = 0; const MAX_BYTES: u32 = 1_024; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { - frame_system::Pallet::::assert_last_event(generic_event.into()); + System::::assert_last_event(generic_event.into()); } fn cid(input: impl AsRef<[u8]>) -> Cid { - let result = sp_crypto_hashing::sha2_256(input.as_ref()); + let result = frame::deps::sp_crypto_hashing::sha2_256(input.as_ref()); Cid::new_v0(result) } @@ -193,7 +188,7 @@ mod benchmarks { // Whitelist voter account from further DB operations. let voter_key = frame_system::Account::::hashed_key_for(&voter); - frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into()); + add_to_whitelist(voter_key.into()); #[extrinsic_call] _(SystemOrigin::Signed(voter), last_hash, index, approve); @@ -264,7 +259,7 @@ mod benchmarks { // Whitelist voter account from further DB operations. let voter_key = frame_system::Account::::hashed_key_for(&voter); - frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into()); + add_to_whitelist(voter_key.into()); #[extrinsic_call] close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage); diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index be65f49e6e4e..6bf37ec2be6c 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -98,21 +98,9 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::pallet_prelude::*; -use frame_system::pallet_prelude::*; -use sp_runtime::{ - traits::{Dispatchable, Saturating, StaticLookup, Zero}, - DispatchError, RuntimeDebug, -}; - -use frame_support::{ - dispatch::{DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, PostDispatchInfo}, - ensure, - traits::{ - ChangeMembers, Currency, Get, InitializeMembers, IsSubType, OnUnbalanced, - ReservableCurrency, - }, - weights::Weight, +use frame::{ + prelude::*, + traits::{Currency, OnUnbalanced, ReservableCurrency}, }; use scale_info::TypeInfo; @@ -215,7 +203,7 @@ type UnscrupulousItemOf = type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; @@ -399,7 +387,7 @@ pub mod pallet { } #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub fellows: Vec, pub allies: Vec, diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index b4ecc1819447..414a6152d17d 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,8 +16,9 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -use frame_support::{pallet_prelude::*, storage::migration, traits::OnRuntimeUpgrade}; +use frame::runtime::prelude::*; use log; +use storage::migration; /// The in-code storage version. pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); @@ -163,6 +164,7 @@ pub(crate) mod v1_to_v2 { mod test { use super::*; use crate::{mock::*, MemberRole, Members}; + use frame::testing_prelude::*; #[test] fn migration_v1_to_v2_works() { diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 625cabf3457f..000c4f65d0ac 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -16,19 +16,7 @@ // limitations under the License. //! Test utilities - -pub use sp_core::H256; -use sp_runtime::traits::Hash; -pub use sp_runtime::{ - traits::{BlakeTwo256, IdentifyAccount, Lazy, Verify}, - BuildStorage, -}; - -pub use frame_support::{ - assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types, - traits::EitherOfDiverse, BoundedVec, -}; -use frame_system::{EnsureRoot, EnsureSignedBy}; +use frame::{testing_prelude::*, traits::Lazy}; use pallet_identity::{ legacy::{IdentityField, IdentityInfo}, Data, IdentityOf, Judgement, SuperOf, @@ -63,7 +51,7 @@ parameter_types! { pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS; pub const MaxProposals: u32 = 100; pub const MaxMembers: u32 = 100; - pub MaxProposalWeight: Weight = sp_runtime::Perbill::from_percent(50) * BlockWeights::get().max_block; + pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block; } type AllianceCollective = pallet_collective::Instance1; impl pallet_collective::Config for Test { @@ -237,7 +225,7 @@ impl Config for Test { type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -268,7 +256,7 @@ pub(super) fn test_identity_info_deposit() -> : byte_deposit * test_identity_info().encoded_size() as u64 + basic_deposit } -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { @@ -295,7 +283,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .assimilate_storage(&mut t) .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); + let mut ext = TestExternalities::new(t); ext.execute_with(|| { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1)); @@ -372,12 +360,12 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } #[cfg(feature = "runtime-benchmarks")] -pub fn new_bench_ext() -> sp_io::TestExternalities { +pub fn new_bench_ext() -> TestExternalities { RuntimeGenesisConfig::default().build_storage().unwrap().into() } pub fn test_cid() -> Cid { - let result = sp_crypto_hashing::sha2_256(b"hello world"); + let result = frame::deps::sp_crypto_hashing::sha2_256(b"hello world"); Cid::new_v0(result) } diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index 2397ebfe7db4..1b7e62714669 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -17,12 +17,9 @@ //! Tests for the alliance pallet. -use frame_support::{assert_noop, assert_ok}; -use frame_system::{EventRecord, Phase}; -use sp_runtime::traits::BadOrigin; - use super::*; use crate::{self as alliance, mock::*}; +use frame::testing_prelude::*; type AllianceMotionEvent = pallet_collective::Event; diff --git a/substrate/frame/alliance/src/types.rs b/substrate/frame/alliance/src/types.rs index 75b949c19b32..917537082b8d 100644 --- a/substrate/frame/alliance/src/types.rs +++ b/substrate/frame/alliance/src/types.rs @@ -17,9 +17,8 @@ use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{traits::ConstU32, BoundedVec}; +use frame::runtime::prelude::*; use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; /// A Multihash instance that only supports the basic functionality and no hashing. #[derive( diff --git a/substrate/frame/alliance/src/weights.rs b/substrate/frame/alliance/src/weights.rs index dff60ec20cde..b06a0913a5b9 100644 --- a/substrate/frame/alliance/src/weights.rs +++ b/substrate/frame/alliance/src/weights.rs @@ -46,7 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_alliance`. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 1c4b2ed5b821..5b590ded397d 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -202,10 +202,13 @@ pub mod prelude { /// Dispatch types from `frame-support`, other fundamental traits #[doc(no_inline)] pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; - pub use frame_support::traits::{ - Contains, EitherOf, EstimateNextSessionRotation, Everything, IsSubType, MapSuccess, - NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, - VariantCount, VariantCountOf, + pub use frame_support::{ + defensive, defensive_assert, + traits::{ + Contains, EitherOf, EstimateNextSessionRotation, Everything, IsSubType, MapSuccess, + NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, + UnfilteredDispatchable, VariantCount, VariantCountOf, + }, }; /// Pallet prelude of `frame-system`. @@ -220,8 +223,8 @@ pub mod prelude { #[doc(no_inline)] pub use super::derive::*; - /// All hashing related things - pub use super::hashing::*; + /// All crypto related things. + pub use super::cryptography::*; /// All account related things. pub use super::account::*; @@ -242,7 +245,8 @@ pub mod prelude { /// Other error/result types for runtime #[doc(no_inline)] pub use sp_runtime::{ - BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + BoundToRuntimeAppPublic, DispatchError, DispatchErrorWithPostInfo, DispatchResultWithInfo, + TokenError, }; } @@ -355,6 +359,9 @@ pub mod runtime { pub mod prelude { pub use crate::prelude::*; + /// Testing includes event cheking. + pub use crate::event::*; + /// All of the types related to the FRAME runtime executive. pub use frame_executive::*; @@ -537,6 +544,11 @@ pub mod arithmetic { pub use sp_arithmetic::{traits::*, *}; } +/// Event checking system for mock runtimes. +pub mod event { + pub use frame_system::{EventRecord, Phase}; +} + /// All derive macros used in frame. /// /// This is already part of the [`prelude`]. @@ -551,9 +563,13 @@ pub mod derive { pub use sp_runtime::RuntimeDebug; } -pub mod hashing { - pub use sp_core::{hashing::*, H160, H256, H512, U256, U512}; - pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; +pub mod cryptography { + pub use sp_core::{ + crypto::{VrfPublic, VrfSecret, Wraps}, + hashing::*, + Pair, H160, H256, H512, U256, U512, + }; + pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256, Verify}; } /// All account management related traits. @@ -598,6 +614,8 @@ pub mod deps { #[cfg(feature = "runtime")] pub use sp_consensus_grandpa; #[cfg(feature = "runtime")] + pub use sp_crypto_hashing; + #[cfg(feature = "runtime")] pub use sp_genesis_builder; #[cfg(feature = "runtime")] pub use sp_inherents;