diff --git a/Cargo.lock b/Cargo.lock index 0a22179eb3d7..c586ac398ea2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14431,13 +14431,9 @@ name = "pallet-paged-list" version = "0.6.0" dependencies = [ "docify", - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", "sp-metadata-ir 0.6.0", "sp-runtime 31.0.1", ] diff --git a/substrate/frame/paged-list/Cargo.toml b/substrate/frame/paged-list/Cargo.toml index da029bdd7423..ac88df5636c8 100644 --- a/substrate/frame/paged-list/Cargo.toml +++ b/substrate/frame/paged-list/Cargo.toml @@ -18,13 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive"], workspace = true } docify = { workspace = true } scale-info = { features = ["derive"], workspace = true } - -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } - -sp-core = { workspace = true } -sp-io = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } sp-metadata-ir = { optional = true, workspace = true } sp-runtime = { workspace = true } @@ -33,27 +27,16 @@ default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-metadata-ir/std", - "sp-runtime/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", + "frame/try-runtime", ] frame-metadata = ["sp-metadata-ir"] diff --git a/substrate/frame/paged-list/src/lib.rs b/substrate/frame/paged-list/src/lib.rs index ed68dac63beb..0eabb2b1a567 100644 --- a/substrate/frame/paged-list/src/lib.rs +++ b/substrate/frame/paged-list/src/lib.rs @@ -72,16 +72,12 @@ mod tests; extern crate alloc; use codec::FullCodec; -use frame_support::{ - pallet_prelude::StorageList, - traits::{PalletInfoAccess, StorageInstance}, -}; +use frame::{prelude::*, traits::StorageInstance}; pub use paged_list::StoragePagedList; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; #[pallet::pallet] pub struct Pallet(_); diff --git a/substrate/frame/paged-list/src/mock.rs b/substrate/frame/paged-list/src/mock.rs index 3e4903200c3d..7d43ba77bbfc 100644 --- a/substrate/frame/paged-list/src/mock.rs +++ b/substrate/frame/paged-list/src/mock.rs @@ -20,13 +20,12 @@ #![cfg(feature = "std")] use crate::{paged_list::StoragePagedListMeta, Config, ListPrefix}; -use frame_support::derive_impl; -use sp_runtime::{traits::IdentityLookup, BuildStorage}; +use frame::testing_prelude::*; type Block = frame_system::mocking::MockBlock; // Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, PagedList: crate, @@ -43,7 +42,7 @@ impl frame_system::Config for Test { type RuntimeEvent = RuntimeEvent; } -frame_support::parameter_types! { +parameter_types! { pub storage ValuesPerNewPage: u32 = 5; pub const MaxPages: Option = Some(20); } @@ -62,7 +61,7 @@ pub type MetaOf = StoragePagedListMeta, ::Value, ::ValuesPerNewPage>; /// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestExternalities { frame_system::GenesisConfig::::default().build_storage().unwrap().into() } diff --git a/substrate/frame/paged-list/src/paged_list.rs b/substrate/frame/paged-list/src/paged_list.rs index bbd889e25218..9e572ba30b7e 100644 --- a/substrate/frame/paged-list/src/paged_list.rs +++ b/substrate/frame/paged-list/src/paged_list.rs @@ -26,13 +26,11 @@ use alloc::vec::Vec; use codec::{Decode, Encode, EncodeLike, FullCodec}; use core::marker::PhantomData; -use frame_support::{ - defensive, - storage::StoragePrefixedContainer, - traits::{Get, StorageInstance}, - CloneNoBound, DebugNoBound, DefaultNoBound, EqNoBound, PartialEqNoBound, + +use frame::{ + runtime::prelude::storage::StoragePrefixedContainer, testing_prelude::*, + traits::StorageInstance, }; -use sp_runtime::traits::Saturating; pub type PageIndex = u32; pub type ValueIndex = u32; @@ -60,10 +58,10 @@ pub type ValueIndex = u32; /// as long as there are elements in the page and there are pages in storage. All elements of a page /// are loaded once a page is read from storage. Iteration then happens on the cached elements. This /// reduces the number of storage `read` calls on the overlay. **Appending** to the list happens by -/// appending to the last page by utilizing [`sp_io::storage::append`]. It allows to directly extend +/// appending to the last page by utilizing [`append`]. It allows to directly extend /// the elements of `values` vector of the page without loading the whole vector from storage. A new /// page is instantiated once [`Page::next`] overflows `ValuesPerNewPage`. Its vector will also be -/// created through [`sp_io::storage::append`]. **Draining** advances the internal indices identical +/// created through [`append`]. **Draining** advances the internal indices identical /// to Iteration. It additionally persists the increments to storage and thereby 'drains' elements. /// Completely drained pages are deleted from storage. /// @@ -111,7 +109,7 @@ pub struct StoragePagedListMeta { _phantom: PhantomData<(Prefix, Value, ValuesPerNewPage)>, } -impl frame_support::storage::StorageAppender +impl storage::StorageAppender for StoragePagedListMeta where Prefix: StorageInstance, @@ -135,7 +133,7 @@ where pub fn from_storage() -> Option { let key = Self::key(); - sp_io::storage::get(&key).and_then(|raw| Self::decode(&mut &raw[..]).ok()) + get(&key).and_then(|raw| Self::decode(&mut &raw[..]).ok()) } pub fn key() -> Vec { @@ -153,13 +151,13 @@ where } let key = page_key::(self.last_page); self.last_page_len.saturating_inc(); - sp_io::storage::append(&key, item.encode()); + append(&key, item.encode()); self.store(); } pub fn store(&self) { let key = Self::key(); - self.using_encoded(|enc| sp_io::storage::set(&key, enc)); + self.using_encoded(|enc| set(&key, enc)); } pub fn reset(&mut self) { @@ -168,7 +166,7 @@ where } pub fn delete() { - sp_io::storage::clear(&Self::key()); + clear(&Self::key()); } } @@ -187,8 +185,7 @@ impl Page { value_index: ValueIndex, ) -> Option { let key = page_key::(index); - let values = sp_io::storage::get(&key) - .and_then(|raw| alloc::vec::Vec::::decode(&mut &raw[..]).ok())?; + let values = get(&key).and_then(|raw| alloc::vec::Vec::::decode(&mut &raw[..]).ok())?; if values.is_empty() { // Don't create empty pages. return None @@ -213,7 +210,7 @@ impl Page { // Does not live under `Page` since it does not require the `Value` generic. pub(crate) fn delete_page(index: PageIndex) { let key = page_key::(index); - sp_io::storage::clear(&key); + clear(&key); } /// Storage key of a page with `index`. @@ -311,7 +308,7 @@ where } } -impl frame_support::storage::StorageList +impl storage::StorageList for StoragePagedList where Prefix: StorageInstance, @@ -355,13 +352,13 @@ where /// Return the elements of the list. #[cfg(test)] fn as_vec() -> Vec { - >::iter().collect() + >::iter().collect() } /// Return and remove the elements of the list. #[cfg(test)] fn as_drained_vec() -> Vec { - >::drain().collect() + >::drain().collect() } } @@ -407,11 +404,6 @@ where #[allow(dead_code)] pub(crate) mod mock { pub use super::*; - pub use frame_support::parameter_types; - #[cfg(test)] - pub use frame_support::{storage::StorageList as _, StorageNoopGuard}; - #[cfg(test)] - pub use sp_io::TestExternalities; parameter_types! { pub const ValuesPerNewPage: u32 = 5; @@ -499,13 +491,13 @@ mod tests { TestExternalities::default().execute_with(|| { List::append_many(0..9); - assert!(sp_io::storage::exists(&page_key::(0))); - assert!(sp_io::storage::exists(&page_key::(1))); + assert!(exists(&page_key::(0))); + assert!(exists(&page_key::(1))); assert_eq!(List::drain().take(5).count(), 5); // Page 0 is eagerly removed. - assert!(!sp_io::storage::exists(&page_key::(0))); - assert!(sp_io::storage::exists(&page_key::(1))); + assert!(!exists(&page_key::(0))); + assert!(exists(&page_key::(1))); }); } @@ -516,16 +508,16 @@ mod tests { List::append_many(0..9); let key = page_key::(0); - let raw = sp_io::storage::get(&key).expect("Page should be present"); + let raw = get(&key).expect("Page should be present"); let as_vec = Vec::::decode(&mut &raw[..]).unwrap(); assert_eq!(as_vec.len(), 5, "First page contains 5"); let key = page_key::(1); - let raw = sp_io::storage::get(&key).expect("Page should be present"); + let raw = get(&key).expect("Page should be present"); let as_vec = Vec::::decode(&mut &raw[..]).unwrap(); assert_eq!(as_vec.len(), 4, "Second page contains 4"); - let meta = sp_io::storage::get(&meta_key::()).expect("Meta should be present"); + let meta = get(&meta_key::()).expect("Meta should be present"); let meta: StoragePagedListMeta = Decode::decode(&mut &meta[..]).unwrap(); assert_eq!(meta.first_page, 0); diff --git a/substrate/frame/paged-list/src/tests.rs b/substrate/frame/paged-list/src/tests.rs index becb4b23508e..259fe2165fbd 100644 --- a/substrate/frame/paged-list/src/tests.rs +++ b/substrate/frame/paged-list/src/tests.rs @@ -21,7 +21,10 @@ #![cfg(test)] use crate::{mock::*, *}; -use frame_support::storage::{StorageList, StoragePrefixedContainer}; +use frame::{ + prelude::storage::{StorageAppender, StoragePrefixedContainer}, + testing_prelude::*, +}; #[docify::export] #[test] @@ -46,7 +49,6 @@ fn append_many_works() { #[docify::export] #[test] fn appender_works() { - use frame_support::storage::StorageAppender; test_closure(|| { let mut appender = PagedList::appender(); diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 15601ebde1f2..eeb3d3839f56 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -205,6 +205,7 @@ pub mod prelude { pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; pub use frame_support::traits::{ Contains, EstimateNextSessionRotation, IsSubType, OnRuntimeUpgrade, OneSessionHandler, + PalletInfoAccess, }; /// Pallet prelude of `frame-system`. @@ -228,8 +229,8 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, - Saturating, StaticLookup, TrailingZeroInput, + BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, IdentityLookup, + SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, }; /// Other runtime types and traits @@ -319,7 +320,7 @@ pub mod testing_prelude { /// Other helper macros from `frame_support` that help with asserting in tests. pub use frame_support::{ assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok, - assert_storage_noop, storage_alias, + assert_storage_noop, defensive, storage_alias, StorageNoopGuard, }; pub use frame_system::{self, mocking::*}; @@ -329,6 +330,8 @@ pub mod testing_prelude { pub use sp_io::TestExternalities as TestState; + pub use sp_io::storage::*; + /// Commonly used runtime traits for testing. pub use sp_runtime::traits::BadOrigin; }