Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Allow usage of path in construct_runtime! #8801

Merged
18 commits merged into from
Jun 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ensure pallets with different paths but same last path segment can co…
…exist
  • Loading branch information
KiChjang committed May 20, 2021
commit b9724e84baf06b2e43bbe11259ac5ce675de6fe8
82 changes: 77 additions & 5 deletions frame/support/test/tests/construct_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,46 @@ mod nested {
}
}

pub mod module3 {
use super::*;

pub trait Config: system::Config {}

frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Err(Error::<T>::Something.into())
}
}
}

#[derive(Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode)]
pub struct Origin;

frame_support::decl_event! {
pub enum Event {
A,
}
}

frame_support::decl_error! {
pub enum Error for Module<T: Config> {
Something
}
}

frame_support::decl_storage! {
trait Store for Module<T: Config> as Module {}
}
}

impl<I> module1::Config<I> for Runtime {}
impl module2::Config for Runtime {}
impl nested::module3::Config for Runtime {}
impl module3::Config for Runtime {}

pub type Signature = sr25519::Signature;
pub type AccountId = <Signature as Verify>::Signer;
Expand Down Expand Up @@ -187,7 +224,8 @@ frame_support::construct_runtime!(
Module1_1: module1::<Instance1>::{Pallet, Call, Storage, Event<T>, Origin<T>},
Module2: module2::{Pallet, Call, Storage, Event, Origin},
Module1_2: module1::<Instance2>::{Pallet, Call, Storage, Event<T>, Origin<T>},
Module3: nested::module3::{Pallet, Call, Storage, Event, Origin},
NestedModule3: nested::module3::{Pallet, Call, Storage, Event, Origin},
Module3: module3::{Pallet, Call, Storage, Event, Origin},
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
Module1_3: module1::<Instance3>::{Pallet, Storage} = 6,
Module1_4: module1::<Instance4>::{Pallet, Call} = 3,
Module1_5: module1::<Instance5>::{Pallet, Event<T>},
Expand Down Expand Up @@ -217,7 +255,7 @@ fn check_modules_error_type() {
Err(DispatchError::Module { index: 33, error: 0, message: Some("Something") }),
);
assert_eq!(
Module3::fail(system::Origin::<Runtime>::Root.into()),
NestedModule3::fail(system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module { index: 34, error: 0, message: Some("Something") }),
);
assert_eq!(
Expand Down Expand Up @@ -275,6 +313,9 @@ fn origin_codec() {
let origin = OriginCaller::nested_module3(nested::module3::Origin);
assert_eq!(origin.encode()[0], 34);

let origin = OriginCaller::module3(module3::Origin);
assert_eq!(origin.encode()[0], 35);

let origin = OriginCaller::module1_Instance6(module1::Origin(Default::default()));
assert_eq!(origin.encode()[0], 1);

Expand Down Expand Up @@ -307,6 +348,9 @@ fn event_codec() {
let event = nested::module3::Event::A;
assert_eq!(Event::from(event).encode()[0], 34);

let event = module3::Event::A;
assert_eq!(Event::from(event).encode()[0], 35);

let event = module1::Event::<Runtime, module1::Instance5>::A(Default::default());
assert_eq!(Event::from(event).encode()[0], 4);

Expand All @@ -330,7 +374,8 @@ fn call_codec() {
assert_eq!(Call::Module1_1(module1::Call::fail()).encode()[0], 31);
assert_eq!(Call::Module2(module2::Call::fail()).encode()[0], 32);
assert_eq!(Call::Module1_2(module1::Call::fail()).encode()[0], 33);
assert_eq!(Call::Module3(nested::module3::Call::fail()).encode()[0], 34);
assert_eq!(Call::NestedModule3(nested::module3::Call::fail()).encode()[0], 34);
assert_eq!(Call::Module3(module3::Call::fail()).encode()[0], 35);
assert_eq!(Call::Module1_4(module1::Call::fail()).encode()[0], 3);
assert_eq!(Call::Module1_6(module1::Call::fail()).encode()[0], 1);
assert_eq!(Call::Module1_7(module1::Call::fail()).encode()[0], 2);
Expand Down Expand Up @@ -439,7 +484,7 @@ fn test_metadata() {
index: 33,
},
ModuleMetadata {
name: DecodeDifferent::Encode("Module3"),
name: DecodeDifferent::Encode("NestedModule3"),
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
prefix: DecodeDifferent::Encode("Module"),
entries: DecodeDifferent::Encode(&[]),
Expand All @@ -462,6 +507,30 @@ fn test_metadata() {
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
index: 34,
},
ModuleMetadata {
name: DecodeDifferent::Encode("Module3"),
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
prefix: DecodeDifferent::Encode("Module"),
entries: DecodeDifferent::Encode(&[]),
}))),
calls: Some(DecodeDifferent::Encode(FnEncode(|| &[
FunctionMetadata {
name: DecodeDifferent::Encode("fail"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
]))),
event: Some(DecodeDifferent::Encode(FnEncode(|| &[
EventMetadata {
name: DecodeDifferent::Encode("A"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
]))),
constants: DecodeDifferent::Encode(FnEncode(|| &[])),
errors: DecodeDifferent::Encode(FnEncode(|| &[])),
index: 35,
},
ModuleMetadata {
name: DecodeDifferent::Encode("Module1_3"),
storage: Some(DecodeDifferent::Encode(FnEncode(|| StorageMetadata {
Expand Down Expand Up @@ -603,7 +672,10 @@ fn pallet_in_runtime_is_correct() {
assert_eq!(PalletInfo::index::<Module1_2>().unwrap(), 33);
assert_eq!(PalletInfo::name::<Module1_2>().unwrap(), "Module1_2");

assert_eq!(PalletInfo::index::<Module3>().unwrap(), 34);
assert_eq!(PalletInfo::index::<NestedModule3>().unwrap(), 34);
assert_eq!(PalletInfo::name::<NestedModule3>().unwrap(), "NestedModule3");

assert_eq!(PalletInfo::index::<Module3>().unwrap(), 35);
assert_eq!(PalletInfo::name::<Module3>().unwrap(), "Module3");

assert_eq!(PalletInfo::index::<Module1_3>().unwrap(), 6);
Expand Down