From 4fd3f1a9d1515a4385c64603e116e5c03da41333 Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 22 Nov 2024 14:51:58 -0800 Subject: [PATCH 1/2] frame::prelude --- Cargo.lock | 6 +---- .../frame/authority-discovery/Cargo.toml | 18 +++---------- .../frame/authority-discovery/src/lib.rs | 27 ++++++++++++------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02d7da8f7657..d5f3fbcea703 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11957,16 +11957,12 @@ dependencies = [ name = "pallet-authority-discovery" version = "28.0.0" dependencies = [ - "frame-support 28.0.0", - "frame-system 28.0.0", "pallet-session 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", "sp-application-crypto 30.0.0", "sp-authority-discovery 26.0.0", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/authority-discovery/Cargo.toml b/substrate/frame/authority-discovery/Cargo.toml index 01f574a262ad..45117e0fdf05 100644 --- a/substrate/frame/authority-discovery/Cargo.toml +++ b/substrate/frame/authority-discovery/Cargo.toml @@ -20,36 +20,24 @@ codec = { features = [ "derive", ], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } pallet-session = { features = [ "historical", ], workspace = true } sp-application-crypto = { workspace = true } sp-authority-discovery = { workspace = true } -sp-runtime = { workspace = true } - -[dev-dependencies] -sp-core = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-support/std", - "frame-system/std", + "frame/std", "pallet-session/std", "scale-info/std", "sp-application-crypto/std", "sp-authority-discovery/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-session/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/authority-discovery/src/lib.rs b/substrate/frame/authority-discovery/src/lib.rs index 220b39292b57..98808b0e5f6f 100644 --- a/substrate/frame/authority-discovery/src/lib.rs +++ b/substrate/frame/authority-discovery/src/lib.rs @@ -26,18 +26,23 @@ extern crate alloc; use alloc::vec::Vec; +use frame::{prelude::*, traits::{Get, OneSessionHandler}, deps::frame_support::WeakBoundedVec, derive::DefaultNoBound}; +/* use frame_support::{ traits::{Get, OneSessionHandler}, WeakBoundedVec, }; +*/ use sp_authority_discovery::AuthorityId; pub use pallet::*; -#[frame_support::pallet] +// #[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; + // use frame_support::pallet_prelude::*; + // use frame::deps::frame_support::pallet_prelude::*; #[pallet::pallet] pub struct Pallet(_); @@ -59,7 +64,7 @@ pub mod pallet { pub(super) type NextKeys = StorageValue<_, WeakBoundedVec, ValueQuery>; - #[derive(frame_support::DefaultNoBound)] + #[derive(DefaultNoBound)] #[pallet::genesis_config] pub struct GenesisConfig { pub keys: Vec, @@ -113,7 +118,7 @@ impl Pallet { } } -impl sp_runtime::BoundToRuntimeAppPublic for Pallet { +impl frame::deps::sp_runtime::BoundToRuntimeAppPublic for Pallet { type Public = AuthorityId; } @@ -171,9 +176,12 @@ mod tests { use super::*; use crate as pallet_authority_discovery; use alloc::vec; - use frame_support::{derive_impl, parameter_types, traits::ConstU32}; + + //use frame_support::{derive_impl, parameter_types, traits::ConstU32}; use sp_application_crypto::Pair; use sp_authority_discovery::AuthorityPair; + use frame::{testing_prelude::TestExternalities, traits::{ConvertInto, IdentityLookup, OpaqueKeys, ConstU32}, runtime::{prelude::{construct_runtime, parameter_types, derive_impl}, testing_prelude::BuildStorage}, deps::sp_runtime::KeyTypeId, arithmetic::Perbill}; + /* use sp_core::crypto::key_types; use sp_io::TestExternalities; use sp_runtime::{ @@ -181,10 +189,11 @@ mod tests { traits::{ConvertInto, IdentityLookup, OpaqueKeys}, BuildStorage, KeyTypeId, Perbill, }; + */ type Block = frame_system::mocking::MockBlock; - frame_support::construct_runtime!( + construct_runtime!( pub enum Test { System: frame_system, @@ -203,7 +212,7 @@ mod tests { impl pallet_session::Config for Test { type SessionManager = (); - type Keys = UintAuthorityId; + type Keys = frame::deps::sp_runtime::testing::UintAuthorityId; type ShouldEndSession = pallet_session::PeriodicSessions; type SessionHandler = TestSessionHandler; type RuntimeEvent = RuntimeEvent; @@ -234,7 +243,7 @@ mod tests { pub struct TestSessionHandler; impl pallet_session::SessionHandler for TestSessionHandler { - const KEY_TYPE_IDS: &'static [KeyTypeId] = &[key_types::DUMMY]; + const KEY_TYPE_IDS: &'static [KeyTypeId] = &[frame::deps::sp_core::crypto::key_types::DUMMY]; fn on_new_session( _changed: bool, @@ -308,7 +317,7 @@ mod tests { let mut externalities = TestExternalities::new(t); externalities.execute_with(|| { - use frame_support::traits::OneSessionHandler; + use frame::deps::frame_support::traits::OneSessionHandler; AuthorityDiscovery::on_genesis_session( first_authorities.iter().map(|id| (id, id.clone())), From 9129887a3acd30ed4f3259eb78ea2afc9b729c20 Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 22 Nov 2024 18:36:43 -0800 Subject: [PATCH 2/2] cargo fmt --- .../frame/authority-discovery/src/lib.rs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/substrate/frame/authority-discovery/src/lib.rs b/substrate/frame/authority-discovery/src/lib.rs index 98808b0e5f6f..593a0003f0c9 100644 --- a/substrate/frame/authority-discovery/src/lib.rs +++ b/substrate/frame/authority-discovery/src/lib.rs @@ -26,13 +26,12 @@ extern crate alloc; use alloc::vec::Vec; -use frame::{prelude::*, traits::{Get, OneSessionHandler}, deps::frame_support::WeakBoundedVec, derive::DefaultNoBound}; -/* -use frame_support::{ +use frame::{ + deps::frame_support::WeakBoundedVec, + derive::DefaultNoBound, + prelude::*, traits::{Get, OneSessionHandler}, - WeakBoundedVec, }; -*/ use sp_authority_discovery::AuthorityId; pub use pallet::*; @@ -41,8 +40,6 @@ pub use pallet::*; #[frame::pallet] pub mod pallet { use super::*; - // use frame_support::pallet_prelude::*; - // use frame::deps::frame_support::pallet_prelude::*; #[pallet::pallet] pub struct Pallet(_); @@ -176,20 +173,18 @@ mod tests { use super::*; use crate as pallet_authority_discovery; use alloc::vec; - - //use frame_support::{derive_impl, parameter_types, traits::ConstU32}; + use frame::{ + arithmetic::Perbill, + deps::sp_runtime::KeyTypeId, + runtime::{ + prelude::{construct_runtime, derive_impl, parameter_types}, + testing_prelude::BuildStorage, + }, + testing_prelude::TestExternalities, + traits::{ConstU32, ConvertInto, IdentityLookup, OpaqueKeys}, + }; use sp_application_crypto::Pair; use sp_authority_discovery::AuthorityPair; - use frame::{testing_prelude::TestExternalities, traits::{ConvertInto, IdentityLookup, OpaqueKeys, ConstU32}, runtime::{prelude::{construct_runtime, parameter_types, derive_impl}, testing_prelude::BuildStorage}, deps::sp_runtime::KeyTypeId, arithmetic::Perbill}; - /* - use sp_core::crypto::key_types; - use sp_io::TestExternalities; - use sp_runtime::{ - testing::UintAuthorityId, - traits::{ConvertInto, IdentityLookup, OpaqueKeys}, - BuildStorage, KeyTypeId, Perbill, - }; - */ type Block = frame_system::mocking::MockBlock; @@ -243,7 +238,8 @@ mod tests { pub struct TestSessionHandler; impl pallet_session::SessionHandler for TestSessionHandler { - const KEY_TYPE_IDS: &'static [KeyTypeId] = &[frame::deps::sp_core::crypto::key_types::DUMMY]; + const KEY_TYPE_IDS: &'static [KeyTypeId] = + &[frame::deps::sp_core::crypto::key_types::DUMMY]; fn on_new_session( _changed: bool,