Warn on missing pallet::call_index (#12894)

* Warn on missing call_index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Suppress camel case warning

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Simplify code

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Disallow warnings in pallet-ui tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add pallet UI test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update Pallet UI

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use module instead of function

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update pallet-ui

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2022-12-15 11:38:21 +01:00
committed by GitHub
parent 619714243b
commit 9ac1bbe402
12 changed files with 115 additions and 27 deletions
@@ -27,6 +27,9 @@ fn pallet_ui() {
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");
// Deny all warnings since we emit warnings as part of a Pallet's UI.
std::env::set_var("RUSTFLAGS", "--deny warnings");
let t = trybuild::TestCases::new();
t.compile_fail("tests/pallet_ui/*.rs");
t.pass("tests/pallet_ui/pass/*.rs");
@@ -17,7 +17,8 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
#[pallet::call_index(0)]
pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
@@ -1,21 +1,21 @@
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
--> tests/pallet_ui/call_argument_invalid_bound.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound.rs:21:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
= note: required for `&<T as pallet::Config>::Bar` to implement `std::fmt::Debug`
= note: required for the cast from `&<T as pallet::Config>::Bar` to the object type `dyn std::fmt::Debug`
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> tests/pallet_ui/call_argument_invalid_bound.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound.rs:21:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> tests/pallet_ui/call_argument_invalid_bound.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound.rs:21:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^
@@ -17,7 +17,8 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
#[pallet::call_index(0)]
pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
@@ -1,27 +1,27 @@
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:21:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
= note: required for `&<T as pallet::Config>::Bar` to implement `std::fmt::Debug`
= note: required for the cast from `&<T as pallet::Config>::Bar` to the object type `dyn std::fmt::Debug`
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:21:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:21:36
|
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^
error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeEncode` is not satisfied
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:20:36
--> tests/pallet_ui/call_argument_invalid_bound_2.rs:21:36
|
1 | / #[frame_support::pallet]
2 | | mod pallet {
@@ -32,8 +32,8 @@ error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeEncode` is
17 | | #[pallet::call]
| |__________________- required by a bound introduced by this call
...
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::Bar`
21 | pub fn foo(origin: OriginFor<T>, _bar: T::Bar) -> DispatchResultWithPostInfo {
| ^^^^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::Bar`
|
= note: required for `<T as pallet::Config>::Bar` to implement `Encode`
@@ -19,7 +19,8 @@ mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
#[pallet::call_index(0)]
pub fn foo(origin: OriginFor<T>, _bar: Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
@@ -1,8 +1,8 @@
error[E0277]: `Bar` doesn't implement `std::fmt::Debug`
--> tests/pallet_ui/call_argument_invalid_bound_3.rs:22:36
--> tests/pallet_ui/call_argument_invalid_bound_3.rs:23:36
|
22 | pub fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^ `Bar` cannot be formatted using `{:?}`
23 | pub fn foo(origin: OriginFor<T>, _bar: Bar) -> DispatchResultWithPostInfo {
| ^^^^ `Bar` cannot be formatted using `{:?}`
|
= help: the trait `std::fmt::Debug` is not implemented for `Bar`
= note: add `#[derive(Debug)]` to `Bar` or manually `impl std::fmt::Debug for Bar`
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::DispatchResult;
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)]
pub fn foo(_: OriginFor<T>) -> DispatchResult {
Ok(())
}
}
}
fn main() {
}
@@ -0,0 +1,12 @@
error: use of deprecated struct `pallet::warnings::foo`:
Implicit call indices are deprecated in favour of explicit ones.
Please ensure that all calls have the `pallet::call_index` attribute or that the
`dev-mode` of the pallet is enabled. For more info see:
<https://github.com/paritytech/substrate/pull/12891> and
<https://github.com/paritytech/substrate/pull/11381>.
--> tests/pallet_ui/call_missing_index.rs:15:10
|
15 | pub fn foo(_: OriginFor<T>) -> DispatchResult {
| ^^^
|
= note: `-D deprecated` implied by `-D warnings`
@@ -1,3 +1,16 @@
error: use of deprecated struct `pallet::warnings::my_call`:
Implicit call indices are deprecated in favour of explicit ones.
Please ensure that all calls have the `pallet::call_index` attribute or that the
`dev-mode` of the pallet is enabled. For more info see:
<https://github.com/paritytech/substrate/pull/12891> and
<https://github.com/paritytech/substrate/pull/11381>.
--> tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs:25:10
|
25 | pub fn my_call(_origin: OriginFor<T>) -> DispatchResult {
| ^^^^^^^
|
= note: `-D deprecated` implied by `-D warnings`
error[E0277]: the trait bound `Vec<u8>: MaxEncodedLen` is not satisfied
--> tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs:11:12
|