Skip to content

Commit

Permalink
migrate pallet-society to use umbrella crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathy-bajo committed Jan 20, 2025
1 parent 06f5d48 commit 5217ab0
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 85 deletions.
10 changes: 2 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
29 changes: 4 additions & 25 deletions substrate/frame/society/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
14 changes: 7 additions & 7 deletions substrate/frame/society/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -510,10 +508,12 @@ mod benchmarks {

impl_benchmark_test_suite!(
Society,
sp_io::TestExternalities::from(
<frame_system::GenesisConfig::<crate::mock::Test> as sp_runtime::BuildStorage>::build_storage(
&frame_system::GenesisConfig::default()).unwrap()
),
TestState::from(
<frame_system::GenesisConfig::<crate::mock::Test> as BuildStorage>::build_storage(
&frame_system::GenesisConfig::default()
)
.unwrap()
),
crate::mock::Test
);
}
26 changes: 4 additions & 22 deletions substrate/frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -469,7 +451,7 @@ pub type GroupParamsFor<T, I> = GroupParams<BalanceOf<T, I>>;

pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;

Expand Down Expand Up @@ -792,7 +774,7 @@ pub mod pallet {
}

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub pot: BalanceOf<T, I>,
}
Expand Down
7 changes: 2 additions & 5 deletions substrate/frame/society/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<T, I, PastPayouts> = frame_support::migrations::VersionedMigration<
pub type MigrateToV2<T, I, PastPayouts> = VersionedMigration<
0,
2,
VersionUncheckedMigrateToV2<T, I, PastPayouts>,
Expand Down
11 changes: 3 additions & 8 deletions substrate/frame/society/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
type Block = MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
5 changes: 2 additions & 3 deletions substrate/frame/society/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/society/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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)]
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5217ab0

Please sign in to comment.