Emit error when construct_runtime imports a non-existent pallet part (#8949)

* Emit error when construct_runtime imports a non-existent Call part

* Reword and display pallet name when emitting part not found error

* Migrate decl_outer_dispatch to a proc macro

* Rename calls.rs to call.rs

* Create new construct_runtime_v2 macro

* Add UI test for importing non-existent call part in construct_runtime

* Emit error when construct_runtime imports a non-existent Config part

* Emit error when construct_runtime imports a non-existent Event part

* Migrate decl_outer_inherent to a proc macro

* Emit error when construct_runtime imports a non-existent Inherent part

* Migrate decl_outer_validate_unsigned to a proc macro

* Emit error when construct_runtime imports a non-existent ValidateUnsigned part

* impl for old macro

* fix line width

* add doc

* hide macroes and use unique counter everywhere

* Remove construct_runtime_v2

* Encapsulate pallet part check macros in a module

* Fix macro definitions in dummy part checker

* Tag ProvideInherent impl with #[pallet::inherent] properly for authorship pallet

* Remove Call part from pallets that do not define it

* Add Call part unit tests

* Remove undefined Call part import from offences pallet

* Add tests for expand_outer_inherent

* Remove Call part from pallets that do not define them

* Remove Call part imports from pallets that do not have it defined

* Remove Call part import of the offences pallet from grandpa pallet mocks

* Update frame/support/test/tests/pallet.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Remove Call part imports for pallets that do not define them

* Move inherent tests to inherent_expand

* Add unit tests for expand_outer_validate_unsigned

* Add newline at the end of file

* fix ui test

* Small prayer to RNGsus for fixing CI

* Remove Call part from construct_runtime for randomness collective flip pallet

* Remove Call part import for randomness collective flip pallet

* Summon Laplace's demon instead of praying to RNGsus

* Update test expectations

* fix ui test and make sure it's flaky

* Revert "fix ui test and make sure it's flaky"

This reverts commit 362b6881389c911ef8d9ef85d71c9463f5694b20.

* Comment out test instead of putting it in conditional compilation

* Update UI test expectations

* Update UI test expectations

* Emit error when construct_runtime imports a non-existent Origin part

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Denis P <denis.pisarev@parity.io>
This commit is contained in:
Keith Yeung
2021-06-15 20:44:22 -07:00
committed by GitHub
parent 7dd38e3aec
commit 58e837fcd3
47 changed files with 1934 additions and 197 deletions
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Call},
}
}
fn main() {}
@@ -0,0 +1,49 @@
error: `Pallet` does not have #[pallet::call] defined, perhaps you should remove `Call` from construct_runtime?
--> $DIR/undefined_call_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_call_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_call_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_call_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Event},
}
}
fn main() {}
@@ -0,0 +1,101 @@
error: `Pallet` does not have #[pallet::event] defined, perhaps you should remove `Event` from construct_runtime?
--> $DIR/undefined_event_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_event_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: could not find `Event` in `pallet`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ could not find `Event` in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0412]: cannot find type `Event` in module `pallet`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::Event;
|
error[E0412]: cannot find type `Event` in module `pallet`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
1 | use crate::Event;
|
1 | use frame_system::Event;
|
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_event_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Config},
}
}
fn main() {}
@@ -0,0 +1,67 @@
error: `Pallet` does not have #[pallet::genesis_config] defined, perhaps you should remove `Config` from construct_runtime?
--> $DIR/undefined_genesis_config_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_genesis_config_part.rs:28:17
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_genesis_config_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0412]: cannot find type `GenesisConfig` in module `pallet`
--> $DIR/undefined_genesis_config_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
|
1 | use frame_system::GenesisConfig;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_genesis_config_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Inherent},
}
}
fn main() {}
@@ -0,0 +1,49 @@
error: `Pallet` does not have #[pallet::inherent] defined, perhaps you should remove `Inherent` from construct_runtime?
--> $DIR/undefined_inherent_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_inherent_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_inherent_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_inherent_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Origin},
}
}
fn main() {}
@@ -0,0 +1,87 @@
error: `Pallet` does not have #[pallet::origin] defined, perhaps you should remove `Origin` from construct_runtime?
--> $DIR/undefined_origin_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_origin_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_origin_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0412]: cannot find type `Origin` in module `pallet`
--> $DIR/undefined_origin_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this type alias
|
1 | use frame_system::Origin;
|
error[E0412]: cannot find type `Origin` in module `pallet`
--> $DIR/undefined_origin_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
1 | use crate::Origin;
|
1 | use frame_system::Origin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_origin_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, ValidateUnsigned},
}
}
fn main() {}
@@ -0,0 +1,49 @@
error: `Pallet` does not have #[pallet::validate_unsigned] defined, perhaps you should remove `ValidateUnsigned` from construct_runtime?
--> $DIR/undefined_validate_unsigned_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_validate_unsigned_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_validate_unsigned_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_validate_unsigned_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`