Implement ResultQuery (#11257)

* Implement ResultQuery

* Fix test expectations

* Add more tests

* Fix test expectations

* Clean up some names

* Silence warnings

* Specify error type when supplying error type to ResultQuery

* cargo fmt

* Add support for type parameters in parameter_types macro

* Reduce deeply indented code

* Fixes

* Update test expectation

* Rewrite and document formula for calculating max storage size

* More docs

* cargo fmt

* formatting

Co-authored-by: parity-processbot <>
This commit is contained in:
Keith Yeung
2022-08-25 01:47:08 +08:00
committed by GitHub
parent 6aba2fdc99
commit edc8f7b409
16 changed files with 770 additions and 77 deletions
@@ -0,0 +1,21 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::error]
pub enum Error<T> {
NonExistentValue,
}
#[pallet::storage]
type Foo<T: Config> = StorageValue<_, u8, ResultQuery<Error::NonExistentValue>>;
}
fn main() {
}
@@ -0,0 +1,15 @@
error[E0107]: missing generics for enum `pallet::Error`
--> tests/pallet_ui/storage_result_query_missing_generics.rs:17:56
|
17 | type Foo<T: Config> = StorageValue<_, u8, ResultQuery<Error::NonExistentValue>>;
| ^^^^^ expected 1 generic argument
|
note: enum defined here, with 1 generic parameter: `T`
--> tests/pallet_ui/storage_result_query_missing_generics.rs:12:11
|
12 | pub enum Error<T> {
| ^^^^^ -
help: add missing generic argument
|
17 | type Foo<T: Config> = StorageValue<_, u8, ResultQuery<Error<T>::NonExistentValue>>;
| ~~~~~~~~
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::error]
pub enum Error<T> {
NonExistentValue,
SomeOtherError,
}
#[pallet::storage]
type Foo<T: Config> = StorageValue<_, u8, ResultQuery<Error<T>::NonExistentValue, SomeOtherError>>;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, unexpected number of generic arguments for ResultQuery, expected 1 type argument, found 2
--> tests/pallet_ui/storage_result_query_multiple_type_args.rs:19:56
|
19 | type Foo<T: Config> = StorageValue<_, u8, ResultQuery<Error<T>::NonExistentValue, SomeOtherError>>;
| ^^^^^
@@ -0,0 +1,16 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::storage]
type Foo<T: Config> = StorageValue<_, u8, ResultQuery<NonExistentValue>>;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, unexpected number of path segments for the generics in ResultQuery, expected a path with at least 2 segments, found 1
--> tests/pallet_ui/storage_result_query_no_defined_pallet_error.rs:12:56
|
12 | type Foo<T: Config> = StorageValue<_, u8, ResultQuery<NonExistentValue>>;
| ^^^^^^^^^^^^^^^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::error]
pub enum Error<T> {
NonExistentValue,
}
#[pallet::storage]
type Foo<T: Config> = StorageValue<_, u8, ResultQuery(NonExistentValue)>;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, unexpected generic args for ResultQuery, expected angle-bracketed arguments, found `(NonExistentValue)`
--> tests/pallet_ui/storage_result_query_parenthesized_generics.rs:18:55
|
18 | type Foo<T: Config> = StorageValue<_, u8, ResultQuery(NonExistentValue)>;
| ^^^^^^^^^^^^^^^^^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::error]
pub enum Error<T> {
NonExistentValue,
}
#[pallet::storage]
type Foo<T: Config> = StorageValue<_, u8, ResultQuery<'static>>;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, unexpected generic argument kind, expected a type path to a `PalletError` enum variant, found `'static`
--> tests/pallet_ui/storage_result_query_wrong_generic_kind.rs:18:56
|
18 | type Foo<T: Config> = StorageValue<_, u8, ResultQuery<'static>>;
| ^^^^^^^