difftreelog
feat add testUtils batchAll
in: master
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6729,6 +6729,7 @@
"pallet-unique-scheduler-v2",
"parity-scale-codec 3.2.1",
"scale-info",
+ "sp-std",
]
[[package]]
runtime/common/config/test_pallets.rsdiffbeforeafterboth--- a/runtime/common/config/test_pallets.rs
+++ b/runtime/common/config/test_pallets.rs
@@ -14,8 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use crate::{Runtime, RuntimeEvent};
+use crate::{Runtime, RuntimeEvent, RuntimeCall};
impl pallet_test_utils::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
+ type RuntimeCall = RuntimeCall;
}
test-pallets/utils/Cargo.tomldiffbeforeafterboth--- a/test-pallets/utils/Cargo.toml
+++ b/test-pallets/utils/Cargo.toml
@@ -12,6 +12,7 @@
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
# pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false }
pallet-unique-scheduler-v2 = { path = '../../pallets/scheduler-v2', default-features = false }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
[features]
default = ["std"]
@@ -21,5 +22,6 @@
"frame-support/std",
"frame-system/std",
"pallet-unique-scheduler-v2/std",
+ "sp-std/std",
]
try-runtime = ["frame-support/try-runtime", "pallet-unique-scheduler/try-runtime"]
test-pallets/utils/src/lib.rsdiffbeforeafterboth222223#[frame_support::pallet]23#[frame_support::pallet]24pub mod pallet {24pub mod pallet {25 use frame_support::pallet_prelude::*;25 use frame_support::{pallet_prelude::*, dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo}, traits::{UnfilteredDispatchable, IsSubType, OriginTrait}};26 use frame_system::pallet_prelude::*;26 use frame_system::pallet_prelude::*;27 use sp_std::vec::Vec;27 use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};28 use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};282929 #[pallet::config]30 #[pallet::config]30 pub trait Config: frame_system::Config + pallet_unique_scheduler_v2::Config {31 pub trait Config: frame_system::Config + pallet_unique_scheduler_v2::Config {31 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;32 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;3334 /// The overarching call type.35 type RuntimeCall: Parameter36 + Dispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin, PostInfo = PostDispatchInfo>37 + GetDispatchInfo38 + From<frame_system::Call<Self>>39 + UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>40 + IsSubType<Call<Self>>41 + IsType<<Self as frame_system::Config>::RuntimeCall>;32 }42 }334334 #[pallet::event]44 #[pallet::event]35 #[pallet::generate_deposit(pub(super) fn deposit_event)]45 #[pallet::generate_deposit(pub(super) fn deposit_event)]36 pub enum Event<T: Config> {46 pub enum Event<T: Config> {37 ValueIsSet,47 ValueIsSet,38 ShouldRollback,48 ShouldRollback,49 BatchCompleted,39 }50 }405141 #[pallet::pallet]52 #[pallet::pallet]113 Ok(())124 Ok(())114 }125 }126127 #[pallet::weight(10_000)]128 pub fn batch_all(129 origin: OriginFor<T>,130 calls: Vec<<T as Config>::RuntimeCall>,131 ) -> DispatchResultWithPostInfo {132 Self::ensure_origin_and_enabled(origin.clone())?;133134 let is_root = ensure_root(origin.clone()).is_ok();135136 for call in calls {137 if is_root {138 call.dispatch_bypass_filter(origin.clone())?;139 } else {140 let mut filtered_origin = origin.clone();141 // Don't allow users to nest `batch_all` calls.142 filtered_origin.add_filter(143 move |c: &<T as frame_system::Config>::RuntimeCall| {144 let c = <T as Config>::RuntimeCall::from_ref(c);145 !matches!(c.is_sub_type(), Some(Call::batch_all { .. }))146 },147 );148 call.dispatch(filtered_origin)?;149 }150 }151152 Self::deposit_event(Event::BatchCompleted);153 Ok(None::<Weight>.into())154 }115 }155 }116}156}117157