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 {