From d31e607bda2157f445f3e5a07d21afbf90b81e01 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere Date: Sat, 12 Jun 2021 18:15:21 +0200 Subject: [PATCH] Enforce pub calls in pallets (#9085) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * make all extrinsics public so they are available from outside * Impl * fix * more fix * more pub * few more * merge fix * fix ui test * fix ui test Co-authored-by: Alexander Popiak Co-authored-by: Shawn Tabrizi Co-authored-by: Bastian Köcher --- substrate/frame/authorship/src/lib.rs | 2 +- .../election-provider-multi-phase/src/lib.rs | 2 +- substrate/frame/grandpa/src/lib.rs | 4 +-- substrate/frame/scheduler/src/lib.rs | 4 +-- substrate/frame/staking/src/lib.rs | 2 +- substrate/frame/sudo/src/mock.rs | 4 +-- .../procedural/src/pallet/parse/call.rs | 12 ++++++++ substrate/frame/support/src/lib.rs | 4 +-- substrate/frame/support/test/tests/pallet.rs | 8 ++--- .../test/tests/pallet_compatibility.rs | 2 +- .../tests/pallet_compatibility_instance.rs | 2 +- .../support/test/tests/pallet_instance.rs | 4 +-- .../pallet_ui/call_argument_invalid_bound.rs | 2 +- .../call_argument_invalid_bound.stderr | 18 +++++------ .../call_argument_invalid_bound_2.rs | 2 +- .../call_argument_invalid_bound_2.stderr | 30 +++++++++---------- .../call_argument_invalid_bound_3.rs | 2 +- .../call_argument_invalid_bound_3.stderr | 18 +++++------ .../pallet_ui/call_invalid_origin_type.rs | 2 +- .../pallet_ui/call_invalid_origin_type.stderr | 12 ++++---- .../tests/pallet_ui/call_invalid_return.rs | 2 +- .../pallet_ui/call_invalid_return.stderr | 6 ++-- .../test/tests/pallet_ui/call_invalid_vis.rs | 27 +++++++++++++++++ .../tests/pallet_ui/call_invalid_vis.stderr | 5 ++++ .../tests/pallet_ui/call_invalid_vis_2.rs | 27 +++++++++++++++++ .../tests/pallet_ui/call_invalid_vis_2.stderr | 5 ++++ .../tests/pallet_ui/call_missing_weight.rs | 2 +- .../pallet_ui/call_missing_weight.stderr | 6 ++-- .../test/tests/pallet_ui/call_no_origin.rs | 2 +- .../tests/pallet_ui/call_no_origin.stderr | 6 ++-- .../test/tests/pallet_ui/call_no_return.rs | 2 +- .../tests/pallet_ui/call_no_return.stderr | 6 ++-- 32 files changed, 154 insertions(+), 78 deletions(-) create mode 100644 substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.stderr diff --git a/substrate/frame/authorship/src/lib.rs b/substrate/frame/authorship/src/lib.rs index b00f412808..9b46a3fe11 100644 --- a/substrate/frame/authorship/src/lib.rs +++ b/substrate/frame/authorship/src/lib.rs @@ -226,7 +226,7 @@ pub mod pallet { impl Pallet { /// Provide a set of uncles. #[pallet::weight((0, DispatchClass::Mandatory))] - fn set_uncles(origin: OriginFor, new_uncles: Vec) -> DispatchResult { + pub fn set_uncles(origin: OriginFor, new_uncles: Vec) -> DispatchResult { ensure_none(origin)?; ensure!(new_uncles.len() <= MAX_UNCLES, Error::::TooManyUncles); diff --git a/substrate/frame/election-provider-multi-phase/src/lib.rs b/substrate/frame/election-provider-multi-phase/src/lib.rs index a4ca89a417..0254525ce8 100644 --- a/substrate/frame/election-provider-multi-phase/src/lib.rs +++ b/substrate/frame/election-provider-multi-phase/src/lib.rs @@ -786,7 +786,7 @@ pub mod pallet { /// /// This check can be turned off by setting the value to `None`. #[pallet::weight(T::DbWeight::get().writes(1))] - fn set_minimum_untrusted_score( + pub fn set_minimum_untrusted_score( origin: OriginFor, maybe_next_score: Option, ) -> DispatchResult { diff --git a/substrate/frame/grandpa/src/lib.rs b/substrate/frame/grandpa/src/lib.rs index 28546018a9..2d10e3c96b 100644 --- a/substrate/frame/grandpa/src/lib.rs +++ b/substrate/frame/grandpa/src/lib.rs @@ -190,7 +190,7 @@ pub mod pallet { /// against the extracted offender. If both are valid, the offence /// will be reported. #[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))] - fn report_equivocation( + pub fn report_equivocation( origin: OriginFor, equivocation_proof: EquivocationProof, key_owner_proof: T::KeyOwnerProof, @@ -236,7 +236,7 @@ pub mod pallet { /// will start the new authority set using the given finalized block as base. /// Only callable by root. #[pallet::weight(T::WeightInfo::note_stalled())] - fn note_stalled( + pub fn note_stalled( origin: OriginFor, delay: T::BlockNumber, best_finalized_block_number: T::BlockNumber, diff --git a/substrate/frame/scheduler/src/lib.rs b/substrate/frame/scheduler/src/lib.rs index 950bbde8bc..a3520f3b21 100644 --- a/substrate/frame/scheduler/src/lib.rs +++ b/substrate/frame/scheduler/src/lib.rs @@ -867,7 +867,7 @@ mod tests { #[pallet::call] impl Pallet where ::Origin: OriginTrait { #[pallet::weight(*weight)] - fn log(origin: OriginFor, i: u32, weight: Weight) -> DispatchResult { + pub fn log(origin: OriginFor, i: u32, weight: Weight) -> DispatchResult { Self::deposit_event(Event::Logged(i, weight)); LOG.with(|log| { log.borrow_mut().push((origin.caller().clone(), i)); @@ -876,7 +876,7 @@ mod tests { } #[pallet::weight(*weight)] - fn log_without_filter(origin: OriginFor, i: u32, weight: Weight) -> DispatchResult { + pub fn log_without_filter(origin: OriginFor, i: u32, weight: Weight) -> DispatchResult { Self::deposit_event(Event::Logged(i, weight)); LOG.with(|log| { log.borrow_mut().push((origin.caller().clone(), i)); diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index 49660350ba..0a22f31e6c 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -1959,7 +1959,7 @@ pub mod pallet { /// Paying even a dead controller is cheaper weight-wise. We don't do any refunds here. /// # #[pallet::weight(T::WeightInfo::payout_stakers_alive_staked(T::MaxNominatorRewardedPerValidator::get()))] - pub(super) fn payout_stakers( + pub fn payout_stakers( origin: OriginFor, validator_stash: T::AccountId, era: EraIndex, diff --git a/substrate/frame/sudo/src/mock.rs b/substrate/frame/sudo/src/mock.rs index 6b296c62fe..92683f98fb 100644 --- a/substrate/frame/sudo/src/mock.rs +++ b/substrate/frame/sudo/src/mock.rs @@ -45,7 +45,7 @@ pub mod logger { #[pallet::call] impl Pallet { #[pallet::weight(*weight)] - pub(crate) fn privileged_i32_log( + pub fn privileged_i32_log( origin: OriginFor, i: i32, weight: Weight @@ -58,7 +58,7 @@ pub mod logger { } #[pallet::weight(*weight)] - pub(crate) fn non_privileged_log( + pub fn non_privileged_log( origin: OriginFor, i: i32, weight: Weight diff --git a/substrate/frame/support/procedural/src/pallet/parse/call.rs b/substrate/frame/support/procedural/src/pallet/parse/call.rs index c2e6dce225..299b86cf6f 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/call.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/call.rs @@ -149,6 +149,18 @@ impl CallDef { let mut methods = vec![]; for impl_item in &mut item.items { if let syn::ImplItem::Method(method) = impl_item { + if !matches!(method.vis, syn::Visibility::Public(_)) { + let msg = "Invalid pallet::call, dispatchable function must be public: \ + `pub fn`"; + + let span = match method.vis { + syn::Visibility::Inherited => method.sig.span(), + _ => method.vis.span(), + }; + + return Err(syn::Error::new(span, msg)); + } + match method.sig.inputs.first() { None => { let msg = "Invalid pallet::call, must have at least origin arg"; diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 1d4d7e4618..43891c1582 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -1438,7 +1438,7 @@ pub mod pallet_prelude { /// impl Pallet { /// /// $some_doc /// #[pallet::weight($ExpressionResultingInWeight)] -/// $vis fn $fn_name( +/// pub fn $fn_name( /// origin: OriginFor, /// $some_arg: $some_type, /// // or with compact attribute: #[pallet::compact] $some_arg: $some_type, @@ -1897,7 +1897,7 @@ pub mod pallet_prelude { /// impl Pallet { /// /// Doc comment put in metadata /// #[pallet::weight(0)] // Defines weight for call (function parameters are in scope) -/// fn toto( +/// pub fn toto( /// origin: OriginFor, /// #[pallet::compact] _foo: u32, /// ) -> DispatchResultWithPostInfo { diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index f7e04e9226..a79c25ae8f 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -133,11 +133,11 @@ pub mod pallet { #[pallet::call] impl Pallet - where T::AccountId: From + From + SomeAssociation1 + where T::AccountId: From + From + SomeAssociation1 { /// Doc comment put in metadata #[pallet::weight(Weight::from(*_foo))] - fn foo( + pub fn foo( origin: OriginFor, #[pallet::compact] _foo: u32, _bar: u32, @@ -152,7 +152,7 @@ pub mod pallet { /// Doc comment put in metadata #[pallet::weight(1)] #[frame_support::transactional] - fn foo_transactional( + pub fn foo_transactional( _origin: OriginFor, #[pallet::compact] foo: u32, ) -> DispatchResultWithPostInfo { @@ -166,7 +166,7 @@ pub mod pallet { // Test for DispatchResult return type #[pallet::weight(1)] - fn foo_no_post_info( + pub fn foo_no_post_info( _origin: OriginFor, ) -> DispatchResult { Ok(()) diff --git a/substrate/frame/support/test/tests/pallet_compatibility.rs b/substrate/frame/support/test/tests/pallet_compatibility.rs index 130014f1e9..db01d15e5d 100644 --- a/substrate/frame/support/test/tests/pallet_compatibility.rs +++ b/substrate/frame/support/test/tests/pallet_compatibility.rs @@ -123,7 +123,7 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::weight(>::into(new_value.clone()))] - fn set_dummy( + pub fn set_dummy( origin: OriginFor, #[pallet::compact] new_value: T::Balance ) -> DispatchResultWithPostInfo { diff --git a/substrate/frame/support/test/tests/pallet_compatibility_instance.rs b/substrate/frame/support/test/tests/pallet_compatibility_instance.rs index d80d9ba3df..63e71c8bf2 100644 --- a/substrate/frame/support/test/tests/pallet_compatibility_instance.rs +++ b/substrate/frame/support/test/tests/pallet_compatibility_instance.rs @@ -113,7 +113,7 @@ pub mod pallet { #[pallet::call] impl, I: 'static> Pallet { #[pallet::weight(>::into(new_value.clone()))] - fn set_dummy( + pub fn set_dummy( origin: OriginFor, #[pallet::compact] new_value: T::Balance ) -> DispatchResultWithPostInfo { diff --git a/substrate/frame/support/test/tests/pallet_instance.rs b/substrate/frame/support/test/tests/pallet_instance.rs index 48ff166c5b..f0b72da2c7 100644 --- a/substrate/frame/support/test/tests/pallet_instance.rs +++ b/substrate/frame/support/test/tests/pallet_instance.rs @@ -81,7 +81,7 @@ pub mod pallet { impl, I: 'static> Pallet { /// Doc comment put in metadata #[pallet::weight(Weight::from(*_foo))] - fn foo(origin: OriginFor, #[pallet::compact] _foo: u32) -> DispatchResultWithPostInfo { + pub fn foo(origin: OriginFor, #[pallet::compact] _foo: u32) -> DispatchResultWithPostInfo { let _ = origin; Self::deposit_event(Event::Something(3)); Ok(().into()) @@ -90,7 +90,7 @@ pub mod pallet { /// Doc comment put in metadata #[pallet::weight(1)] #[frame_support::transactional] - fn foo_transactional( + pub fn foo_transactional( origin: OriginFor, #[pallet::compact] _foo: u32 ) -> DispatchResultWithPostInfo { diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.rs b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.rs index 69d35344d5..0f58187f73 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.rs @@ -17,7 +17,7 @@ mod pallet { #[pallet::call] impl Pallet { #[pallet::weight(0)] - fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { Ok(().into()) } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr index 1eaf71be17..ead05261b1 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound.stderr @@ -1,8 +1,8 @@ error[E0369]: binary operation `==` cannot be applied to type `&::Bar` - --> $DIR/call_argument_invalid_bound.rs:20:37 + --> $DIR/call_argument_invalid_bound.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ | help: consider further restricting this bound | @@ -10,18 +10,18 @@ help: consider further restricting this bound | ^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `::Bar: Clone` is not satisfied - --> $DIR/call_argument_invalid_bound.rs:20:37 + --> $DIR/call_argument_invalid_bound.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ the trait `Clone` is not implemented for `::Bar` +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ the trait `Clone` is not implemented for `::Bar` | = note: required by `clone` error[E0277]: `::Bar` doesn't implement `std::fmt::Debug` - --> $DIR/call_argument_invalid_bound.rs:20:37 + --> $DIR/call_argument_invalid_bound.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ `::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ `::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | = help: the trait `std::fmt::Debug` is not implemented for `::Bar` = note: required because of the requirements on the impl of `std::fmt::Debug` for `&::Bar` diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.rs b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.rs index 581c72a424..da87046822 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.rs @@ -17,7 +17,7 @@ mod pallet { #[pallet::call] impl Pallet { #[pallet::weight(0)] - fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { Ok(().into()) } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr index 1d0e96be9e..2a3bbe1abf 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `::Bar: WrapperTypeDecode` is not satisfied - --> $DIR/call_argument_invalid_bound_2.rs:20:37 + --> $DIR/call_argument_invalid_bound_2.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ the trait `WrapperTypeDecode` is not implemented for `::Bar` +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ the trait `WrapperTypeDecode` is not implemented for `::Bar` | ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.1/src/codec.rs:277:18 | @@ -12,10 +12,10 @@ error[E0277]: the trait bound `::Bar: WrapperTypeDecode` is = note: required because of the requirements on the impl of `Decode` for `::Bar` error[E0277]: the trait bound `::Bar: WrapperTypeEncode` is not satisfied - --> $DIR/call_argument_invalid_bound_2.rs:20:37 + --> $DIR/call_argument_invalid_bound_2.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ the trait `WrapperTypeEncode` is not implemented for `::Bar` +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ the trait `WrapperTypeEncode` is not implemented for `::Bar` | ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.1/src/codec.rs:216:21 | @@ -25,10 +25,10 @@ error[E0277]: the trait bound `::Bar: WrapperTypeEncode` is = note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `::Bar` error[E0369]: binary operation `==` cannot be applied to type `&::Bar` - --> $DIR/call_argument_invalid_bound_2.rs:20:37 + --> $DIR/call_argument_invalid_bound_2.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ | help: consider further restricting this bound | @@ -36,18 +36,18 @@ help: consider further restricting this bound | ^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `::Bar: Clone` is not satisfied - --> $DIR/call_argument_invalid_bound_2.rs:20:37 + --> $DIR/call_argument_invalid_bound_2.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ the trait `Clone` is not implemented for `::Bar` +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ the trait `Clone` is not implemented for `::Bar` | = note: required by `clone` error[E0277]: `::Bar` doesn't implement `std::fmt::Debug` - --> $DIR/call_argument_invalid_bound_2.rs:20:37 + --> $DIR/call_argument_invalid_bound_2.rs:20:41 | -20 | fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { - | ^ `::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` +20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { + | ^ `::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | = help: the trait `std::fmt::Debug` is not implemented for `::Bar` = note: required because of the requirements on the impl of `std::fmt::Debug` for `&::Bar` diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs index 97f3625510..4a6a781ff4 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs @@ -19,7 +19,7 @@ mod pallet { #[pallet::call] impl Pallet { #[pallet::weight(0)] - fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { + pub fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { Ok(().into()) } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr index 89cee573a2..73c3069719 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.stderr @@ -1,24 +1,24 @@ error[E0369]: binary operation `==` cannot be applied to type `&Bar` - --> $DIR/call_argument_invalid_bound_3.rs:22:37 + --> $DIR/call_argument_invalid_bound_3.rs:22:41 | -22 | fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { - | ^^^ +22 | pub fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { + | ^^^ | = note: an implementation of `std::cmp::PartialEq` might be missing for `&Bar` error[E0277]: the trait bound `Bar: Clone` is not satisfied - --> $DIR/call_argument_invalid_bound_3.rs:22:37 + --> $DIR/call_argument_invalid_bound_3.rs:22:41 | -22 | fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { - | ^^^ the trait `Clone` is not implemented for `Bar` +22 | pub fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { + | ^^^ the trait `Clone` is not implemented for `Bar` | = note: required by `clone` error[E0277]: `Bar` doesn't implement `std::fmt::Debug` - --> $DIR/call_argument_invalid_bound_3.rs:22:37 + --> $DIR/call_argument_invalid_bound_3.rs:22:41 | -22 | fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { - | ^^^ `Bar` cannot be formatted using `{:?}` +22 | pub fn foo(origin: OriginFor, bar: Bar) -> DispatchResultWithPostInfo { + | ^^^ `Bar` cannot be formatted using `{:?}` | = help: the trait `std::fmt::Debug` is not implemented for `Bar` = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug` diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.rs b/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.rs index edf953b597..2502506fa6 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.rs @@ -14,7 +14,7 @@ mod pallet { #[pallet::call] impl Pallet { - fn foo(origin: u8) {} + pub fn foo(origin: u8) {} } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.stderr b/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.stderr index 855c59fd8d..f17cd9016a 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_origin_type.stderr @@ -1,11 +1,11 @@ error: Invalid type: expected `OriginFor` - --> $DIR/call_invalid_origin_type.rs:17:18 + --> $DIR/call_invalid_origin_type.rs:17:22 | -17 | fn foo(origin: u8) {} - | ^^ +17 | pub fn foo(origin: u8) {} + | ^^ error: expected `OriginFor` - --> $DIR/call_invalid_origin_type.rs:17:18 + --> $DIR/call_invalid_origin_type.rs:17:22 | -17 | fn foo(origin: u8) {} - | ^^ +17 | pub fn foo(origin: u8) {} + | ^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.rs b/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.rs index 477e7f3219..1ccdff5d07 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.rs @@ -14,7 +14,7 @@ mod pallet { #[pallet::call] impl Pallet { - fn foo(origin: OriginFor) -> ::DispatchResult { todo!() } + pub fn foo(origin: OriginFor) -> ::DispatchResult { todo!() } } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.stderr b/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.stderr index c79da3bbf7..6a851ed3fc 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_return.stderr @@ -1,5 +1,5 @@ error: expected `DispatchResultWithPostInfo` or `DispatchResult` - --> $DIR/call_invalid_return.rs:17:35 + --> $DIR/call_invalid_return.rs:17:39 | -17 | fn foo(origin: OriginFor) -> ::DispatchResult { todo!() } - | ^^ +17 | pub fn foo(origin: OriginFor) -> ::DispatchResult { todo!() } + | ^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.rs b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.rs new file mode 100644 index 0000000000..fe1c5aee45 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.rs @@ -0,0 +1,27 @@ +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo}; + use frame_system::pallet_prelude::{BlockNumberFor, OriginFor}; + + #[pallet::config] + pub trait Config: frame_system::Config { + type Bar: codec::Codec; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::hooks] + impl Hooks> for Pallet {} + + #[pallet::call] + impl Pallet { + #[pallet::weight(0)] + fn foo(origin: OriginFor) -> DispatchResultWithPostInfo { + Ok(().into()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.stderr b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.stderr new file mode 100644 index 0000000000..321828a1ae --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis.stderr @@ -0,0 +1,5 @@ +error: Invalid pallet::call, dispatchable function must be public: `pub fn` + --> $DIR/call_invalid_vis.rs:20:3 + | +20 | fn foo(origin: OriginFor) -> DispatchResultWithPostInfo { + | ^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.rs b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.rs new file mode 100644 index 0000000000..fb25e9876d --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.rs @@ -0,0 +1,27 @@ +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo}; + use frame_system::pallet_prelude::{BlockNumberFor, OriginFor}; + + #[pallet::config] + pub trait Config: frame_system::Config { + type Bar: codec::Codec; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::hooks] + impl Hooks> for Pallet {} + + #[pallet::call] + impl Pallet { + #[pallet::weight(0)] + pub(crate) fn foo(origin: OriginFor) -> DispatchResultWithPostInfo { + Ok(().into()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.stderr b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.stderr new file mode 100644 index 0000000000..7d3113474a --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/call_invalid_vis_2.stderr @@ -0,0 +1,5 @@ +error: Invalid pallet::call, dispatchable function must be public: `pub fn` + --> $DIR/call_invalid_vis_2.rs:20:3 + | +20 | pub(crate) fn foo(origin: OriginFor) -> DispatchResultWithPostInfo { + | ^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.rs b/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.rs index 2ce607c53a..4cdb85502b 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.rs @@ -14,7 +14,7 @@ mod pallet { #[pallet::call] impl Pallet { - fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} + pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.stderr b/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.stderr index 37386d7771..ec45d47887 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_missing_weight.stderr @@ -1,5 +1,5 @@ error: Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]` - --> $DIR/call_missing_weight.rs:17:3 + --> $DIR/call_missing_weight.rs:17:7 | -17 | fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} - | ^^ +17 | pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} + | ^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/call_no_origin.rs b/substrate/frame/support/test/tests/pallet_ui/call_no_origin.rs index 83d10b6b08..231c75f43f 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_no_origin.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_no_origin.rs @@ -14,7 +14,7 @@ mod pallet { #[pallet::call] impl Pallet { - fn foo() {} + pub fn foo() {} } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_no_origin.stderr b/substrate/frame/support/test/tests/pallet_ui/call_no_origin.stderr index 42afd02c42..97574ea1b6 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_no_origin.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_no_origin.stderr @@ -1,5 +1,5 @@ error: Invalid pallet::call, must have at least origin arg - --> $DIR/call_no_origin.rs:17:3 + --> $DIR/call_no_origin.rs:17:7 | -17 | fn foo() {} - | ^^ +17 | pub fn foo() {} + | ^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/call_no_return.rs b/substrate/frame/support/test/tests/pallet_ui/call_no_return.rs index a18c30f6d6..68a883c52c 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_no_return.rs +++ b/substrate/frame/support/test/tests/pallet_ui/call_no_return.rs @@ -14,7 +14,7 @@ mod pallet { #[pallet::call] impl Pallet { - fn foo(origin: OriginFor) {} + pub fn foo(origin: OriginFor) {} } } diff --git a/substrate/frame/support/test/tests/pallet_ui/call_no_return.stderr b/substrate/frame/support/test/tests/pallet_ui/call_no_return.stderr index b16d401355..18ebbaff76 100644 --- a/substrate/frame/support/test/tests/pallet_ui/call_no_return.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/call_no_return.stderr @@ -1,5 +1,5 @@ error: Invalid pallet::call, require return type DispatchResultWithPostInfo - --> $DIR/call_no_return.rs:17:3 + --> $DIR/call_no_return.rs:17:7 | -17 | fn foo(origin: OriginFor) {} - | ^^ +17 | pub fn foo(origin: OriginFor) {} + | ^^