Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pallet-paged-list to umbrella crate #6931

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Cargo.lock

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

25 changes: 4 additions & 21 deletions substrate/frame/paged-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,24 @@ 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-runtime = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
sp-metadata-ir = { optional = true, workspace = true }

[features]
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"]
7 changes: 3 additions & 4 deletions substrate/frame/paged-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ mod tests;
extern crate alloc;

use codec::FullCodec;
use frame_support::{
pallet_prelude::StorageList,
use frame::{
prelude::*,
traits::{PalletInfoAccess, 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<T, I = ()>(_);
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/paged-list/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, traits::IdentityLookup};

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

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
construct_runtime!(
pub enum Test {
System: frame_system,
PagedList: crate,
Expand All @@ -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<u32> = Some(20);
}
Expand All @@ -62,7 +61,7 @@ pub type MetaOf<T, I> =
StoragePagedListMeta<ListPrefix<T, I>, <T as Config>::Value, <T as Config>::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::<Test>::default().build_storage().unwrap().into()
}

Expand Down
29 changes: 12 additions & 17 deletions substrate/frame/paged-list/src/paged_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
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::{
deps::{frame_support, sp_io},
Krayt78 marked this conversation as resolved.
Show resolved Hide resolved
runtime::prelude::storage::{storage_noop_guard::StorageNoopGuard, StoragePrefixedContainer},

Check failure on line 32 in substrate/frame/paged-list/src/paged_list.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

unused import: `storage_noop_guard::StorageNoopGuard`
testing_prelude::*,
traits::{Get, Saturating, StorageInstance},
Krayt78 marked this conversation as resolved.
Show resolved Hide resolved
};
use sp_runtime::traits::Saturating;

pub type PageIndex = u32;
pub type ValueIndex = u32;
Expand Down Expand Up @@ -60,10 +60,10 @@
/// 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.
///
Expand Down Expand Up @@ -111,7 +111,7 @@
_phantom: PhantomData<(Prefix, Value, ValuesPerNewPage)>,
}

impl<Prefix, Value, ValuesPerNewPage> frame_support::storage::StorageAppender<Value>
impl<Prefix, Value, ValuesPerNewPage> storage::StorageAppender<Value>
for StoragePagedListMeta<Prefix, Value, ValuesPerNewPage>
where
Prefix: StorageInstance,
Expand Down Expand Up @@ -311,7 +311,7 @@
}
}

impl<Prefix, Value, ValuesPerNewPage> frame_support::storage::StorageList<Value>
impl<Prefix, Value, ValuesPerNewPage> storage::StorageList<Value>
for StoragePagedList<Prefix, Value, ValuesPerNewPage>
where
Prefix: StorageInstance,
Expand Down Expand Up @@ -355,13 +355,13 @@
/// Return the elements of the list.
#[cfg(test)]
fn as_vec() -> Vec<Value> {
<Self as frame_support::storage::StorageList<_>>::iter().collect()
<Self as storage::StorageList<_>>::iter().collect()
}

/// Return and remove the elements of the list.
#[cfg(test)]
fn as_drained_vec() -> Vec<Value> {
<Self as frame_support::storage::StorageList<_>>::drain().collect()
<Self as storage::StorageList<_>>::drain().collect()
}
}

Expand Down Expand Up @@ -407,11 +407,6 @@
#[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;
Expand Down
6 changes: 4 additions & 2 deletions substrate/frame/paged-list/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,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,
};

pub use frame_system::{self, mocking::*};
Expand Down
Loading