This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce #[pallet::call_index] attribute to dispatchables (paritytec…
…h#11381) * Introduce #[pallet::call_index] attribute to dispatchables * cargo fmt * Add more docs and prevent duplicates of call indices * Add UI test for conflicting call indices * cargo fmt Co-authored-by: parity-processbot <>
- Loading branch information
1 parent
489a595
commit 1723c43
Showing
11 changed files
with
208 additions
and
18 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
24 changes: 24 additions & 0 deletions
24
frame/support/test/tests/pallet_ui/call_conflicting_indices.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,24 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::DispatchResultWithPostInfo; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(core::marker::PhantomData<T>); | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::weight(0)] | ||
#[pallet::call_index(10)] | ||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
|
||
#[pallet::weight(0)] | ||
#[pallet::call_index(10)] | ||
pub fn bar(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
11 changes: 11 additions & 0 deletions
11
frame/support/test/tests/pallet_ui/call_conflicting_indices.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,11 @@ | ||
error: Call indices are conflicting: Both functions foo and bar are at index 10 | ||
--> tests/pallet_ui/call_conflicting_indices.rs:15:10 | ||
| | ||
15 | pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
| ^^^ | ||
|
||
error: Call indices are conflicting: Both functions foo and bar are at index 10 | ||
--> tests/pallet_ui/call_conflicting_indices.rs:19:10 | ||
| | ||
19 | pub fn bar(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
| ^^^ |
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,20 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::DispatchResultWithPostInfo; | ||
use frame_system::pallet_prelude::OriginFor; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(core::marker::PhantomData<T>); | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::weird_attr] | ||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
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 `weight` or `call_index` | ||
--> tests/pallet_ui/call_invalid_attr.rs:14:13 | ||
| | ||
14 | #[pallet::weird_attr] | ||
| ^^^^^^^^^^ |
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::DispatchResultWithPostInfo; | ||
use frame_system::pallet_prelude::OriginFor; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(core::marker::PhantomData<T>); | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::weight(0)] | ||
#[pallet::call_index(256)] | ||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
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: number too large to fit in target type | ||
--> tests/pallet_ui/call_invalid_index.rs:15:24 | ||
| | ||
15 | #[pallet::call_index(256)] | ||
| ^^^ |
22 changes: 22 additions & 0 deletions
22
frame/support/test/tests/pallet_ui/call_multiple_call_index.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,22 @@ | ||
#[frame_support::pallet] | ||
mod pallet { | ||
use frame_support::pallet_prelude::DispatchResultWithPostInfo; | ||
use frame_system::pallet_prelude::OriginFor; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(core::marker::PhantomData<T>); | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::weight(0)] | ||
#[pallet::call_index(1)] | ||
#[pallet::call_index(2)] | ||
pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
5 changes: 5 additions & 0 deletions
5
frame/support/test/tests/pallet_ui/call_multiple_call_index.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: Invalid pallet::call, too many call_index attributes given | ||
--> tests/pallet_ui/call_multiple_call_index.rs:17:7 | ||
| | ||
17 | pub fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {} | ||
| ^^ |