This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow renaming storage item prefixes (#9016)
* Implement parsing for #[pallet::storage_name] on storage items * Rename storage prefix when a #[pallet::storage_name] is supplied * Fix test_storage_info * Rename storage_name to storage_prefix * Check for duplicates when renaming storage prefixes * Allow only string literals for storage_prefix renames * Use proper spans for attribute errors * Check for valid identifiers when parsing storage prefix renames
- Loading branch information
Showing
13 changed files
with
288 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
frame/support/test/tests/pallet_ui/duplicate_storage_prefix.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::StorageValue; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
#[pallet::generate_store(trait Store)] | ||
pub struct Pallet<T>(core::marker::PhantomData<T>); | ||
|
||
#[pallet::storage] | ||
type Foo<T> = StorageValue<_, u8>; | ||
|
||
#[pallet::storage] | ||
#[pallet::storage_prefix = "Foo"] | ||
type NotFoo<T> = StorageValue<_, u16>; | ||
} | ||
|
||
fn main() { | ||
} |
17 changes: 17 additions & 0 deletions
17
frame/support/test/tests/pallet_ui/duplicate_storage_prefix.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: Duplicate storage prefixes found for `Foo` | ||
--> $DIR/duplicate_storage_prefix.rs:16:32 | ||
| | ||
16 | #[pallet::storage_prefix = "Foo"] | ||
| ^^^^^ | ||
|
||
error[E0412]: cannot find type `_GeneratedPrefixForStorageFoo` in this scope | ||
--> $DIR/duplicate_storage_prefix.rs:13:7 | ||
| | ||
13 | type Foo<T> = StorageValue<_, u8>; | ||
| ^^^ not found in this scope | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/duplicate_storage_prefix.rs:17:35 | ||
| | ||
17 | type NotFoo<T> = StorageValue<_, u16>; | ||
| ^ not allowed in type signatures |
21 changes: 21 additions & 0 deletions
21
frame/support/test/tests/pallet_ui/storage_invalid_attribute.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::Hooks; | ||
use frame_system::pallet_prelude::BlockNumberFor; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> {} | ||
|
||
#[pallet::storage] | ||
#[pallet::generate_store(pub trait Store)] | ||
type Foo<T> = StorageValue<u8, u8>; | ||
} | ||
|
||
fn main() { | ||
} |
5 changes: 5 additions & 0 deletions
5
frame/support/test/tests/pallet_ui/storage_invalid_attribute.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: expected `getter` or `storage_prefix` | ||
--> $DIR/storage_invalid_attribute.rs:16:12 | ||
| | ||
16 | #[pallet::generate_store(pub trait Store)] | ||
| ^^^^^^^^^^^^^^ |
18 changes: 18 additions & 0 deletions
18
frame/support/test/tests/pallet_ui/storage_invalid_rename_value.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::Hooks; | ||
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::storage] | ||
#[pallet::storage_prefix = "pub"] | ||
type Foo<T> = StorageValue<_, u8>; | ||
} | ||
|
||
fn main() { | ||
} |
5 changes: 5 additions & 0 deletions
5
frame/support/test/tests/pallet_ui/storage_invalid_rename_value.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `pub` is not a valid identifier | ||
--> $DIR/storage_invalid_rename_value.rs:13:29 | ||
| | ||
13 | #[pallet::storage_prefix = "pub"] | ||
| ^^^^^ |
Oops, something went wrong.