mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
pallet-utility: Disallow none origin (#12321)
Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -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(),
|
||||
@@ -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);
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user