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

Commit

Permalink
pallet-utility: Disallow none origin (#12321)
Browse files Browse the repository at this point in the history
Co-authored-by: André Silva <andrerfosilva@gmail.com>
  • Loading branch information
bkchr and andresilva authored Sep 22, 2022
1 parent 493b58b commit 1253de6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions frame/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub mod pallet {
origin: OriginFor<T>,
calls: Vec<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let is_root = ensure_signed_or_root(origin.clone())?.is_none();
let calls_len = calls.len();
ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::<T>::TooManyCalls);

Expand Down Expand Up @@ -319,7 +319,7 @@ pub mod pallet {
origin: OriginFor<T>,
calls: Vec<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let is_root = ensure_signed_or_root(origin.clone())?.is_none();
let calls_len = calls.len();
ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::<T>::TooManyCalls);

Expand Down Expand Up @@ -426,7 +426,7 @@ pub mod pallet {
origin: OriginFor<T>,
calls: Vec<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let is_root = ensure_root(origin.clone()).is_ok();
let is_root = ensure_signed_or_root(origin.clone())?.is_none();
let calls_len = calls.len();
ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::<T>::TooManyCalls);

Expand Down
14 changes: 12 additions & 2 deletions frame/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate as utility;
use frame_support::{
assert_err_ignore_postinfo, assert_noop, assert_ok,
dispatch::{DispatchError, DispatchErrorWithPostInfo, Dispatchable, Pays},
error::BadOrigin,
parameter_types, storage,
traits::{ConstU32, ConstU64, Contains},
weights::Weight,
Expand Down Expand Up @@ -651,7 +652,7 @@ fn force_batch_works() {
call_transfer(2, 10),
call_transfer(2, 5),
]
),);
));
System::assert_last_event(utility::Event::BatchCompletedWithErrors.into());
System::assert_has_event(
utility::Event::ItemFailed { error: DispatchError::Other("") }.into(),
Expand All @@ -662,10 +663,19 @@ fn force_batch_works() {
assert_ok!(Utility::force_batch(
RuntimeOrigin::signed(2),
vec![call_transfer(1, 5), call_transfer(1, 5),]
),);
));
System::assert_last_event(utility::Event::BatchCompleted.into());

assert_ok!(Utility::force_batch(RuntimeOrigin::signed(1), vec![call_transfer(2, 50),]),);
System::assert_last_event(utility::Event::BatchCompletedWithErrors.into());
});
}

#[test]
fn none_origin_does_not_work() {
new_test_ext().execute_with(|| {
assert_noop!(Utility::force_batch(RuntimeOrigin::none(), vec![]), BadOrigin);
assert_noop!(Utility::batch(RuntimeOrigin::none(), vec![]), BadOrigin);
assert_noop!(Utility::batch_all(RuntimeOrigin::none(), vec![]), BadOrigin);
})
}

0 comments on commit 1253de6

Please sign in to comment.