pallet macro: always generate storage info on pallet struct (#9246)

* always implement storage info on Pallet

* fix UI test

* Fold span computation into trait and method computation

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Guillaume Thiolliere
2021-07-05 13:23:43 +02:00
committed by GitHub
parent f93074d086
commit f96c5df754
13 changed files with 338 additions and 35 deletions
@@ -397,6 +397,9 @@ pub mod pallet2 {
{
}
#[pallet::storage]
pub type SomeValue<T: Config> = StorageValue<_, Vec<u32>>;
#[pallet::event]
pub enum Event {
/// Something
@@ -1247,4 +1250,15 @@ fn test_storage_info() {
},
],
);
assert_eq!(
Example2::storage_info(),
vec![
StorageInfo {
prefix: prefix(b"Example2", b"SomeValue"),
max_values: Some(1),
max_size: None,
},
],
);
}
@@ -31,3 +31,37 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12
|
9 | #[pallet::pallet]
| ^^^^^^ the trait `WrapperTypeDecode` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `Decode` for `Bar`
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `partial_storage_info`
error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12
|
9 | #[pallet::pallet]
| ^^^^^^ the trait `EncodeLike` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `partial_storage_info`
error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12
|
9 | #[pallet::pallet]
| ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `Bar`
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `partial_storage_info`
@@ -31,3 +31,37 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `StorageValueMetadata` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `frame_support::storage::types::StorageValueMetadata::NAME`
error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12
|
9 | #[pallet::pallet]
| ^^^^^^ the trait `WrapperTypeDecode` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `Decode` for `Bar`
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `partial_storage_info`
error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12
|
9 | #[pallet::pallet]
| ^^^^^^ the trait `EncodeLike` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `partial_storage_info`
error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied
--> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12
|
9 | #[pallet::pallet]
| ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `Bar`
= note: required because of the requirements on the impl of `FullEncode` for `Bar`
= note: required because of the requirements on the impl of `FullCodec` for `Bar`
= note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo<T>, Bar>`
= note: required by `partial_storage_info`