From 5217ab0cfb7ce784d3b3aa736c4bc050325998a8 Mon Sep 17 00:00:00 2001 From: Nathy-bajo Date: Mon, 20 Jan 2025 12:51:02 +0100 Subject: [PATCH] migrate pallet-society to use umbrella crate --- Cargo.lock | 10 ++----- substrate/frame/Cargo.toml | 2 ++ substrate/frame/society/Cargo.toml | 29 +++------------------ substrate/frame/society/src/benchmarking.rs | 14 +++++----- substrate/frame/society/src/lib.rs | 26 +++--------------- substrate/frame/society/src/migrations.rs | 7 ++--- substrate/frame/society/src/mock.rs | 11 +++----- substrate/frame/society/src/tests.rs | 5 ++-- substrate/frame/society/src/weights.rs | 2 +- substrate/frame/src/lib.rs | 23 +++++++++++----- 10 files changed, 44 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9a139f30744..4f71ae0293b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15406,20 +15406,13 @@ dependencies = [ name = "pallet-society" version = "28.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-support-test", - "frame-system 28.0.0", "log", "pallet-balances 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "rand_chacha", "scale-info", "sp-arithmetic 23.0.0", - "sp-core 28.0.0", - "sp-crypto-hashing 0.1.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] @@ -19414,6 +19407,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..498f6268fbe9 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -48,6 +48,7 @@ sp-session = { optional = true, workspace = true } sp-storage = { optional = true, workspace = true } sp-transaction-pool = { optional = true, workspace = true } sp-version = { optional = true, workspace = true } +sp-crypto-hashing = { optional = true, workspace = true } frame-executive = { optional = true, workspace = true } frame-system-rpc-runtime-api = { optional = true, workspace = true } @@ -111,6 +112,7 @@ std = [ "sp-storage/std", "sp-transaction-pool?/std", "sp-version?/std", + "sp-crypto-hashing/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/substrate/frame/society/Cargo.toml b/substrate/frame/society/Cargo.toml index d5860518fdda..05868643ce5c 100644 --- a/substrate/frame/society/Cargo.toml +++ b/substrate/frame/society/Cargo.toml @@ -17,53 +17,32 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } +frame = { workspace = true, features = ["runtime"] } log = { workspace = true } rand_chacha = { workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } sp-arithmetic = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } [dev-dependencies] -frame-support-test = { workspace = true } pallet-balances = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } -sp-crypto-hashing = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support-test/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-balances/std", "rand_chacha/std", "scale-info/std", "sp-arithmetic/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", ] runtime-benchmarks = [ - "frame-benchmarking", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support-test/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/society/src/benchmarking.rs b/substrate/frame/society/src/benchmarking.rs index dc8e3cab775f..6641a476f0fc 100644 --- a/substrate/frame/society/src/benchmarking.rs +++ b/substrate/frame/society/src/benchmarking.rs @@ -21,11 +21,9 @@ use super::*; -use frame_benchmarking::v2::*; -use frame_system::RawOrigin; +use frame::benchmarking::prelude::{RawOrigin, *}; use alloc::vec; -use sp_runtime::traits::Bounded; use crate::Pallet as Society; @@ -510,10 +508,12 @@ mod benchmarks { impl_benchmark_test_suite!( Society, - sp_io::TestExternalities::from( - as sp_runtime::BuildStorage>::build_storage( - &frame_system::GenesisConfig::default()).unwrap() - ), + TestState::from( + as BuildStorage>::build_storage( + &frame_system::GenesisConfig::default() + ) + .unwrap() + ), crate::mock::Test ); } diff --git a/substrate/frame/society/src/lib.rs b/substrate/frame/society/src/lib.rs index b893bb6fba7d..900f67d4cb95 100644 --- a/substrate/frame/society/src/lib.rs +++ b/substrate/frame/society/src/lib.rs @@ -260,31 +260,13 @@ pub mod migrations; extern crate alloc; use alloc::vec::Vec; -use frame_support::{ - impl_ensure_origin_with_arg_ignoring_arg, - pallet_prelude::*, - storage::KeyLenOf, - traits::{ - BalanceStatus, Currency, EnsureOrigin, EnsureOriginWithArg, - ExistenceRequirement::AllowDeath, Imbalance, OnUnbalanced, Randomness, ReservableCurrency, - StorageVersion, - }, - PalletId, -}; -use frame_system::pallet_prelude::*; + +use frame::prelude::*; use rand_chacha::{ rand_core::{RngCore, SeedableRng}, ChaChaRng, }; use scale_info::TypeInfo; -use sp_runtime::{ - traits::{ - AccountIdConversion, CheckedAdd, CheckedSub, Hash, Saturating, StaticLookup, - TrailingZeroInput, Zero, - }, - ArithmeticError::Overflow, - Percent, RuntimeDebug, -}; pub use weights::WeightInfo; @@ -469,7 +451,7 @@ pub type GroupParamsFor = GroupParams>; pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; @@ -792,7 +774,7 @@ pub mod pallet { } #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub pot: BalanceOf, } diff --git a/substrate/frame/society/src/migrations.rs b/substrate/frame/society/src/migrations.rs index 396ed787c784..c1ed90e9e31d 100644 --- a/substrate/frame/society/src/migrations.rs +++ b/substrate/frame/society/src/migrations.rs @@ -20,10 +20,7 @@ use super::*; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode}; -use frame_support::traits::{Defensive, DefensiveOption, Instance, UncheckedOnRuntimeUpgrade}; - -#[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; +use frame::try_runtime::TryRuntimeError; /// The log target. const TARGET: &'static str = "runtime::society::migration"; @@ -96,7 +93,7 @@ impl< /// [`VersionUncheckedMigrateToV2`] wrapped in a [`frame_support::migrations::VersionedMigration`], /// ensuring the migration is only performed when on-chain version is 0. -pub type MigrateToV2 = frame_support::migrations::VersionedMigration< +pub type MigrateToV2 = VersionedMigration< 0, 2, VersionUncheckedMigrateToV2, diff --git a/substrate/frame/society/src/mock.rs b/substrate/frame/society/src/mock.rs index 8cb5dc823753..2b02ed029c7e 100644 --- a/substrate/frame/society/src/mock.rs +++ b/substrate/frame/society/src/mock.rs @@ -20,19 +20,14 @@ use super::*; use crate as pallet_society; -use frame_support::{ - assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types, - traits::{ConstU32, ConstU64}, -}; +use frame::testing_prelude::*; use frame_support_test::TestRandomness; -use frame_system::EnsureSignedBy; -use sp_runtime::{traits::IdentityLookup, BuildStorage}; use RuntimeOrigin as Origin; -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, diff --git a/substrate/frame/society/src/tests.rs b/substrate/frame/society/src/tests.rs index 22832f18b6fe..50791127484d 100644 --- a/substrate/frame/society/src/tests.rs +++ b/substrate/frame/society/src/tests.rs @@ -21,9 +21,8 @@ use super::*; use migrations::v0; use mock::*; -use frame_support::{assert_noop, assert_ok}; -use sp_crypto_hashing::blake2_256; -use sp_runtime::traits::BadOrigin; +use frame::testing_prelude::*; +use frame::deps::sp_crypto_hashing::blake2_256; use BidKind::*; use VouchingStatus::*; diff --git a/substrate/frame/society/src/weights.rs b/substrate/frame/society/src/weights.rs index f6f59d20d659..77645d996fac 100644 --- a/substrate/frame/society/src/weights.rs +++ b/substrate/frame/society/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_society`. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 18c7bd123944..c1668cecabfe 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -203,11 +203,16 @@ pub mod prelude { #[doc(no_inline)] pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; pub use frame_support::{ - defensive, defensive_assert, + defensive, defensive_assert, impl_ensure_origin_with_arg_ignoring_arg, + storage::KeyLenOf, traits::{ - Contains, EitherOf, EstimateNextSessionRotation, IsSubType, MapSuccess, NoOpPoll, - OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, + BalanceStatus, Contains, Currency, Defensive, DefensiveOption, EitherOf, EnsureOrigin, + EnsureOriginWithArg, EstimateNextSessionRotation, ExistenceRequirement::AllowDeath, + Imbalance, Instance, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OnUnbalanced, + OneSessionHandler, Randomness, RankedMembers, RankedMembersSwapHandler, + ReservableCurrency, StorageVersion, UncheckedOnRuntimeUpgrade, }, + PalletId, }; /// Pallet prelude of `frame-system`. @@ -230,9 +235,14 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] - pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy, - ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, + pub use sp_runtime::{ + traits::{ + AccountIdConversion, BlockNumberProvider, Bounded, CheckedAdd, CheckedSub, Convert, + DispatchInfoOf, Dispatchable, Hash, ReduceBy, ReplaceWithDefault, SaturatedConversion, + Saturating, StaticLookup, TrailingZeroInput, Zero, + }, + ArithmeticError::Overflow, + BuildStorage, Percent, RuntimeDebug, }; /// Other error/result types for runtime #[doc(no_inline)] @@ -568,6 +578,7 @@ pub mod deps { pub use sp_core; pub use sp_io; pub use sp_runtime; + pub use sp_crypto_hashing; pub use codec; pub use scale_info;