Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 12 additions & 3 deletions frame/support/procedural/src/construct_runtime/expand/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ pub fn expand_outer_dispatch(
let path = &pallet_declaration.path;
let index = pallet_declaration.index;

variant_defs.extend(quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),));
variant_defs.extend(quote!(
#[codec(index = #index)]
#name(#scrate::sp_std::boxed::Box<
#scrate::dispatch::CallableCallFor<#name, #runtime>
>),
));
variant_patterns.push(quote!(Call::#name(call)));
pallet_names.push(name);
query_call_part_macros.push(quote! {
Expand Down Expand Up @@ -117,7 +122,10 @@ pub fn expand_outer_dispatch(
match self {
#(
#variant_patterns =>
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(call, origin),
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(
*call,
origin,
),
)*
}
}
Expand All @@ -128,7 +136,7 @@ pub fn expand_outer_dispatch(
#[allow(unreachable_patterns)]
fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> {
match self {
#variant_patterns => Some(call),
#variant_patterns => Some(&*call),
// May be unreachable
_ => None,
}
Expand All @@ -137,6 +145,7 @@ pub fn expand_outer_dispatch(

impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self {
let call = #scrate::sp_std::boxed::Box::new(call);
#variant_patterns
}
}
Expand Down
26 changes: 13 additions & 13 deletions frame/support/test/tests/construct_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,17 @@ fn event_codec() {
#[test]
fn call_codec() {
use codec::Encode;
assert_eq!(Call::System(system::Call::noop()).encode()[0], 30);
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::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);
assert_eq!(Call::Module1_8(module1::Call::fail()).encode()[0], 12);
assert_eq!(Call::Module1_9(module1::Call::fail()).encode()[0], 13);
assert_eq!(Call::System(Box::new(system::Call::noop())).encode()[0], 30);
assert_eq!(Call::Module1_1(Box::new(module1::Call::fail())).encode()[0], 31);
assert_eq!(Call::Module2(Box::new(module2::Call::fail())).encode()[0], 32);
assert_eq!(Call::Module1_2(Box::new(module1::Call::fail())).encode()[0], 33);
assert_eq!(Call::NestedModule3(Box::new(nested::module3::Call::fail())).encode()[0], 34);
assert_eq!(Call::Module3(Box::new(module3::Call::fail())).encode()[0], 35);
assert_eq!(Call::Module1_4(Box::new(module1::Call::fail())).encode()[0], 3);
assert_eq!(Call::Module1_6(Box::new(module1::Call::fail())).encode()[0], 1);
assert_eq!(Call::Module1_7(Box::new(module1::Call::fail())).encode()[0], 2);
assert_eq!(Call::Module1_8(Box::new(module1::Call::fail())).encode()[0], 12);
assert_eq!(Call::Module1_9(Box::new(module1::Call::fail())).encode()[0], 13);
}

#[test]
Expand Down Expand Up @@ -539,7 +539,7 @@ fn call_name() {
#[test]
fn call_metadata() {
use frame_support::dispatch::{CallMetadata, GetCallMetadata};
let call = Call::Module3(module3::Call::<Runtime>::aux_4());
let call = Call::Module3(Box::new(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);
Expand All @@ -565,7 +565,7 @@ fn get_module_names() {
#[test]
fn call_subtype_conversion() {
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
let call = Call::Module3(module3::Call::<Runtime>::fail());
let call = Call::Module3(Box::new(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);
Expand Down
75 changes: 60 additions & 15 deletions frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ fn inherent_expand() {
let inherents = InherentData::new().create_extrinsics();

let expected = vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_no_post_info())),
signature: None,
},
];
assert_eq!(expected, inherents);

Expand All @@ -586,8 +589,14 @@ fn inherent_expand() {
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 },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_no_post_info())),
signature: None,
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo(1, 0))),
signature: None,
},
],
);

Expand All @@ -602,8 +611,14 @@ fn inherent_expand() {
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 },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_no_post_info())),
signature: None,
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo(0, 0))),
signature: None,
},
],
);

Expand All @@ -618,7 +633,10 @@ fn inherent_expand() {
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_transactional(0))),
signature: None,
},
],
);

Expand All @@ -635,7 +653,10 @@ fn inherent_expand() {
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: Some((1, (), ())) },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_no_post_info())),
signature: Some((1, (), ())),
},
],
);

Expand All @@ -652,8 +673,14 @@ fn inherent_expand() {
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(Box::new(pallet::Call::foo(1, 1))),
signature: None,
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_transactional(0))),
signature: None,
},
],
);

Expand All @@ -668,9 +695,18 @@ fn inherent_expand() {
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 },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo(1, 1))),
signature: None,
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_transactional(0))),
signature: None,
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_no_post_info())),
signature: None,
},
],
);

Expand All @@ -685,9 +721,18 @@ fn inherent_expand() {
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 },
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo(1, 1))),
signature: None,
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo(1, 0))),
signature: Some((1, (), ())),
},
UncheckedExtrinsic {
function: Call::Example(Box::new(pallet::Call::foo_no_post_info())),
signature: None,
},
],
);

Expand Down