Skip to content

Commit

Permalink
frame::prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
runcomet committed Nov 22, 2024
1 parent 09757a4 commit 4fd3f1a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
6 changes: 1 addition & 5 deletions Cargo.lock

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

18 changes: 3 additions & 15 deletions substrate/frame/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
27 changes: 18 additions & 9 deletions substrate/frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_);
Expand All @@ -59,7 +64,7 @@ pub mod pallet {
pub(super) type NextKeys<T: Config> =
StorageValue<_, WeakBoundedVec<AuthorityId, T::MaxAuthorities>, ValueQuery>;

#[derive(frame_support::DefaultNoBound)]
#[derive(DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub keys: Vec<AuthorityId>,
Expand Down Expand Up @@ -113,7 +118,7 @@ impl<T: Config> Pallet<T> {
}
}

impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Pallet<T> {
impl<T: Config> frame::deps::sp_runtime::BoundToRuntimeAppPublic for Pallet<T> {
type Public = AuthorityId;
}

Expand Down Expand Up @@ -171,20 +176,24 @@ 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::{
testing::UintAuthorityId,
traits::{ConvertInto, IdentityLookup, OpaqueKeys},
BuildStorage, KeyTypeId, Perbill,
};
*/

type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand All @@ -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<Period, Offset>;
type SessionHandler = TestSessionHandler;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -234,7 +243,7 @@ mod tests {

pub struct TestSessionHandler;
impl pallet_session::SessionHandler<AuthorityId> 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<Ks: OpaqueKeys>(
_changed: bool,
Expand Down Expand Up @@ -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())),
Expand Down

0 comments on commit 4fd3f1a

Please sign in to comment.