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
@@ -172,6 +172,22 @@ pub mod module3 {
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Err(Error::<T>::Something.into())
}
#[weight = 0]
pub fn aux_1(_origin, #[compact] _data: u32) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 0]
pub fn aux_2(_origin, _data: i32, #[compact] _data2: u32) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 0]
fn aux_3(_origin, _data: i32, _data2: String) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 3]
fn aux_4(_origin) -> frame_support::dispatch::DispatchResult { unreachable!() }
#[weight = (5, frame_support::weights::DispatchClass::Operational)]
fn operational(_origin) { unreachable!() }
}
}
@@ -465,6 +481,100 @@ fn call_codec() {
assert_eq!(Call::Module1_9(module1::Call::fail()).encode()[0], 13);
}
#[test]
fn call_compact_attr() {
use codec::Encode;
let call: module3::Call<Runtime> = module3::Call::aux_1(1);
let encoded = call.encode();
assert_eq!(2, encoded.len());
assert_eq!(vec![1, 4], encoded);
let call: module3::Call<Runtime> = module3::Call::aux_2(1, 2);
let encoded = call.encode();
assert_eq!(6, encoded.len());
assert_eq!(vec![2, 1, 0, 0, 0, 8], encoded);
}
#[test]
fn call_encode_is_correct_and_decode_works() {
use codec::{Decode, Encode};
let call: module3::Call<Runtime> = module3::Call::fail();
let encoded = call.encode();
assert_eq!(vec![0], encoded);
let decoded = module3::Call::<Runtime>::decode(&mut &encoded[..]).unwrap();
assert_eq!(decoded, call);
let call: module3::Call<Runtime> = module3::Call::aux_3(32, "hello".into());
let encoded = call.encode();
assert_eq!(vec![3, 32, 0, 0, 0, 20, 104, 101, 108, 108, 111], encoded);
let decoded = module3::Call::<Runtime>::decode(&mut &encoded[..]).unwrap();
assert_eq!(decoded, call);
}
#[test]
fn call_weight_should_attach_to_call_enum() {
use frame_support::{
dispatch::{DispatchInfo, GetDispatchInfo},
weights::{DispatchClass, Pays},
};
// operational.
assert_eq!(
module3::Call::<Runtime>::operational().get_dispatch_info(),
DispatchInfo { weight: 5, class: DispatchClass::Operational, pays_fee: Pays::Yes },
);
// custom basic
assert_eq!(
module3::Call::<Runtime>::aux_4().get_dispatch_info(),
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes },
);
}
#[test]
fn call_name() {
use frame_support::dispatch::GetCallName;
let name = module3::Call::<Runtime>::aux_4().get_call_name();
assert_eq!("aux_4", name);
}
#[test]
fn call_metadata() {
use frame_support::dispatch::{CallMetadata, GetCallMetadata};
let call = Call::Module3(module3::Call::<Runtime>::aux_4());
let metadata = call.get_call_metadata();
let expected = CallMetadata { function_name: "aux_4".into(), pallet_name: "Module3".into() };
assert_eq!(metadata, expected);
}
#[test]
fn get_call_names() {
use frame_support::dispatch::GetCallName;
let call_names = module3::Call::<Runtime>::get_call_names();
assert_eq!(["fail", "aux_1", "aux_2", "aux_3", "aux_4", "operational"], call_names);
}
#[test]
fn get_module_names() {
use frame_support::dispatch::GetCallMetadata;
let module_names = Call::get_module_names();
assert_eq!([
"System", "Module1_1", "Module2", "Module1_2", "NestedModule3", "Module3",
"Module1_4", "Module1_6", "Module1_7", "Module1_8", "Module1_9",
], module_names);
}
#[test]
fn call_subtype_conversion() {
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
let call = Call::Module3(module3::Call::<Runtime>::fail());
let subcall: Option<&CallableCallFor<Module3, Runtime>> = call.is_sub_type();
let subcall_none: Option<&CallableCallFor<Module2, Runtime>> = call.is_sub_type();
assert_eq!(Some(&module3::Call::<Runtime>::fail()), subcall);
assert_eq!(None, subcall_none);
let from = Call::from(subcall.unwrap().clone());
assert_eq!(from, call);
}
#[test]
fn test_metadata() {
use frame_metadata::*;
@@ -601,6 +711,54 @@ fn test_metadata() {
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_1"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("Compact<u32>"),
},
]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_2"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("i32"),
},
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data2"),
ty: DecodeDifferent::Encode("Compact<u32>"),
},
]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_3"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("i32"),
},
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data2"),
ty: DecodeDifferent::Encode("String"),
},
]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_4"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("operational"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
]))),
event: Some(DecodeDifferent::Encode(FnEncode(|| &[
EventMetadata {
@@ -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`
+175 -5
View File
@@ -304,10 +304,13 @@ pub mod pallet {
type Call = Call<T>;
fn validate_unsigned(
_source: TransactionSource,
_call: &Self::Call
call: &Self::Call
) -> TransactionValidity {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType5); // Test for where clause
if matches!(call, Call::foo_transactional(_)) {
return Ok(ValidTransaction::default());
}
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
}
}
@@ -324,22 +327,40 @@ pub mod pallet {
fn create_inherent(_data: &InherentData) -> Option<Self::Call> {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType6); // Test for where clause
unimplemented!();
Some(Call::foo_no_post_info())
}
fn is_inherent(_call: &Self::Call) -> bool {
unimplemented!();
fn is_inherent(call: &Self::Call) -> bool {
matches!(call, Call::foo_no_post_info() | Call::foo(..))
}
fn check_inherent(call: &Self::Call, _: &InherentData) -> Result<(), Self::Error> {
match call {
Call::foo_no_post_info() => Ok(()),
Call::foo(0, 0) => Err(InherentError::Fatal),
Call::foo(..) => Ok(()),
_ => unreachable!("other calls are not inherents"),
}
}
fn is_inherent_required(d: &InherentData) -> Result<Option<Self::Error>, Self::Error> {
match d.get_data::<bool>(b"required") {
Ok(Some(true)) => Ok(Some(InherentError::Fatal)),
Ok(Some(false)) | Ok(None) => Ok(None),
Err(_) => unreachable!("should not happen in tests"),
}
}
}
#[derive(codec::Encode, sp_runtime::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(codec::Decode))]
pub enum InherentError {
Fatal,
}
impl frame_support::inherent::IsFatalError for InherentError {
fn is_fatal_error(&self) -> bool {
unimplemented!();
matches!(self, InherentError::Fatal)
}
}
@@ -538,6 +559,155 @@ fn instance_expand() {
let _: pallet::__InherentHiddenInstance = ();
}
#[test]
fn inherent_expand() {
use frame_support::{
inherent::{BlockT, InherentData},
traits::EnsureInherentsAreFirst,
};
use sp_core::Hasher;
use sp_runtime::{traits::{BlakeTwo256, Header}, Digest};
let inherents = InherentData::new().create_extrinsics();
let expected = vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
];
assert_eq!(expected, inherents);
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 0)), signature: None },
],
);
assert!(InherentData::new().check_extrinsics(&block).ok());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(0, 0)), signature: None },
],
);
assert!(InherentData::new().check_extrinsics(&block).fatal_error());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
],
);
let mut inherent = InherentData::new();
inherent.put_data(*b"required", &true).unwrap();
assert!(inherent.check_extrinsics(&block).fatal_error());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: Some((1, (), ())) },
],
);
let mut inherent = InherentData::new();
inherent.put_data(*b"required", &true).unwrap();
assert!(inherent.check_extrinsics(&block).fatal_error());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 1)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
],
);
assert!(Runtime::ensure_inherents_are_first(&block).is_ok());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 1)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
],
);
assert_eq!(Runtime::ensure_inherents_are_first(&block).err().unwrap(), 2);
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 1)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 0)), signature: Some((1, (), ())) },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
],
);
assert_eq!(Runtime::ensure_inherents_are_first(&block).err().unwrap(), 2);
}
#[test]
fn validate_unsigned_expand() {
use frame_support::pallet_prelude::{
InvalidTransaction, TransactionSource, TransactionValidityError, ValidTransaction, ValidateUnsigned,
};
let call = pallet::Call::<Runtime>::foo_no_post_info();
let validity = pallet::Pallet::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call));
let call = pallet::Call::<Runtime>::foo_transactional(0);
let validity = pallet::Pallet::validate_unsigned(TransactionSource::External, &call).unwrap();
assert_eq!(validity, ValidTransaction::default());
}
#[test]
fn trait_store_expand() {
TestExternalities::default().execute_with(|| {
@@ -306,8 +306,8 @@ frame_support::construct_runtime!(
Instance1Example: pallet::<Instance1>::{
Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned
},
Example2: pallet2::{Pallet, Call, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Pallet, Call, Event<T>, Config<T>, Storage},
Example2: pallet2::{Pallet, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Pallet, Event<T>, Config<T>, Storage},
}
);
@@ -1,27 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, StorageNMap, Twox64Concat, NMapKey};
use frame_system::pallet_prelude::BlockNumberFor;
// #[frame_support::pallet]
// mod pallet {
// use frame_support::pallet_prelude::{Hooks, StorageNMap, Twox64Concat, NMapKey};
// use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
// #[pallet::config]
// pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_storage_info]
pub struct Pallet<T>(core::marker::PhantomData<T>);
// #[pallet::pallet]
// #[pallet::generate_storage_info]
// pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
// #[pallet::hooks]
// impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
// #[pallet::call]
// impl<T: Config> Pallet<T> {}
#[derive(codec::Encode, codec::Decode)]
struct Bar;
// #[derive(codec::Encode, codec::Decode)]
// struct Bar;
#[pallet::storage]
type Foo<T> = StorageNMap<_, NMapKey<Twox64Concat, Bar>, u32>;
}
// #[pallet::storage]
// type Foo<T> = StorageNMap<_, NMapKey<Twox64Concat, Bar>, u32>;
// }
fn main() {
compile_error!("Temporarily disabled due to test flakiness");
}
@@ -1,9 +1,5 @@
error[E0277]: the trait bound `Bar: MaxEncodedLen` is not satisfied
--> $DIR/storage_info_unsatisfied_nmap.rs:10:12
error: Temporarily disabled due to test flakiness
--> $DIR/storage_info_unsatisfied_nmap.rs:27:2
|
10 | #[pallet::generate_storage_info]
| ^^^^^^^^^^^^^^^^^^^^^ the trait `MaxEncodedLen` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `KeyGeneratorMaxEncodedLen` for `NMapKey<frame_support::Twox64Concat, Bar>`
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageNMap<_GeneratedPrefixForStorageFoo<T>, NMapKey<frame_support::Twox64Concat, Bar>, u32>`
= note: required by `storage_info`
27 | compile_error!("Temporarily disabled due to test flakiness");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^