12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#![cfg_attr(not(feature = "std"), no_std)]53#![allow(clippy::type_complexity, clippy::boxed_local, clippy::unused_unit)]5455mod benchmarking;56pub mod weights;5758use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow, cmp};59use codec::{Encode, Decode, Codec};60use sp_runtime::{61 RuntimeDebug,62 traits::{Zero, One, BadOrigin, Saturating},63 transaction_validity::TransactionValidityError,64 DispatchErrorWithPostInfo,65};66use frame_support::{67 decl_module, decl_storage, decl_event, decl_error,68 dispatch::{Dispatchable, DispatchError, DispatchResult, Parameter},69 traits::{70 Get,71 schedule::{self, DispatchTime},72 OriginTrait, EnsureOrigin, IsType,73 },74 weights::{GetDispatchInfo, Weight, PostDispatchInfo},75};76use frame_system::{self as system, ensure_signed};77pub use weights::WeightInfo;78use up_sponsorship::SponsorshipHandler;79use scale_info::TypeInfo;80use sp_core::H160;8182838485868788pub trait Config: system::Config {89 90 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;9192 93 type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>94 + From<Self::PalletsOrigin>95 + IsType<<Self as system::Config>::Origin>;9697 98 type PalletsOrigin: From<system::RawOrigin<Self::AccountId>> + Codec + TypeInfo + Clone + Eq;99100 101 type Call: Parameter102 + Dispatchable<Origin = <Self as Config>::Origin>103 + GetDispatchInfo104 + From<system::Call<Self>>;105106 107 108 type MaximumWeight: Get<Weight>;109110 111 type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;112113 114 115 type MaxScheduledPerBlock: Get<u32>;116117 118 type SponsorshipHandler: SponsorshipHandler<Self::AccountId, <Self as Config>::Call>;119120 121 type WeightInfo: WeightInfo;122123 124 type CallExecutor: DispatchCall<Self, H160>;125}126127128pub trait DispatchCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {129 130 type Pre: Default + Codec + Clone + TypeInfo;131132 133 fn dispatch_call(134 pre_dispatch: Self::Pre,135 function: <T as Config>::Call,136 ) -> Result<137 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,138 TransactionValidityError,139 >;140141 142 fn pre_dispatch(143 signer: T::AccountId,144 function: <T as Config>::Call,145 ) -> Result<Self::Pre, TransactionValidityError>;146147 148 fn cancel_dispatch(pre_dispatch: Self::Pre) -> Result<(), TransactionValidityError>;149}150151pub const MAX_TASK_ID_LENGTH_IN_BYTES: u8 = 16;152153pub const PERIODIC_CALLS_LIMIT: u32 = 100;154155156157158pub type PeriodicIndex = u32;159160pub type TaskAddress<BlockNumber> = (BlockNumber, u32);161162163164165166167168169170171172#[cfg_attr(any(feature = "std", test), derive(PartialEq, Eq))]173#[derive(Clone, RuntimeDebug, Encode, Decode, TypeInfo)]174pub struct Scheduled<Call, BlockNumber, PalletsOrigin, AccountId, PreDispatch> {175 176 maybe_id: Option<Vec<u8>>,177 178 priority: schedule::Priority,179 180 call: Call,181 182 maybe_periodic: Option<schedule::Period<BlockNumber>>,183 184 origin: PalletsOrigin,185 186 pre_dispatch: PreDispatch,187 _phantom: PhantomData<AccountId>,188}189190191192193194195196197198199200201202203204205206207208209#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]210pub struct CallSpec {211 module: u32,212 method: u32,213}214215decl_storage! {216 trait Store for Module<T: Config> as Scheduler {217 218 pub Agenda: map hasher(twox_64_concat) T::BlockNumber219 => Vec<Option<Scheduled<220 <T as Config>::Call,221 T::BlockNumber,222 T::PalletsOrigin,223 T::AccountId,224 <<T as Config>::CallExecutor as DispatchCall<T, H160>>::Pre225 >>>;226227 228229230 231 Lookup: map hasher(twox_64_concat) Vec<u8> => Option<TaskAddress<T::BlockNumber>>;232233 234 235 236 237 }238}239240decl_event!(241 pub enum Event<T> where <T as system::Config>::BlockNumber {242 243 Scheduled(BlockNumber, u32),244 245 Canceled(BlockNumber, u32),246 247 Dispatched(TaskAddress<BlockNumber>, Option<Vec<u8>>, DispatchResult),248 }249);250251decl_error! {252 pub enum Error for Module<T: Config> {253 254 FailedToSchedule,255 256 NotFound,257 258 TargetBlockNumberInPast,259 260 RescheduleNoChange,261 }262}263264decl_module! {265 266 pub struct Module<T: Config> for enum Call267 where268 origin: <T as system::Config>::Origin269 {270 type Error = Error<T>;271 fn deposit_event() = default;272273 274 275 276 277 278 279 280 281 282 283 #[weight = <T as Config>::WeightInfo::schedule(T::MaxScheduledPerBlock::get())]284 fn schedule(origin,285 when: T::BlockNumber,286 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,287 priority: schedule::Priority,288 call: Box<<T as Config>::Call>,289 )290 {291 let origin = <T as Config>::Origin::from(origin);292 Self::do_schedule_nameless(DispatchTime::At(when), maybe_periodic, priority, origin.caller().clone(), *call)?;293 }294295 296 297 298 299 300 301 302 303 304 305 #[weight = <T as Config>::WeightInfo::cancel(T::MaxScheduledPerBlock::get())]306 fn cancel(origin, when: T::BlockNumber, index: u32) {307 T::ScheduleOrigin::ensure_origin(origin.clone())?;308 let origin = <T as Config>::Origin::from(origin);309 Self::do_cancel(Some(origin.caller().clone()), (when, index))?;310 }311312 313 314 315 316 317 318 319 320 321 322 #[weight = <T as Config>::WeightInfo::schedule_named(T::MaxScheduledPerBlock::get())]323 fn schedule_named(origin,324 id: Vec<u8>,325 when: T::BlockNumber,326 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,327 priority: schedule::Priority,328 call: Box<<T as Config>::Call>,329 ) {330 T::ScheduleOrigin::ensure_origin(origin.clone())?;331 let origin = <T as Config>::Origin::from(origin);332 Self::do_schedule_named(333 id, DispatchTime::At(when), maybe_periodic, priority, origin.caller().clone(), *call334 )?;335 }336337 338 339 340 341 342 343 344 345 346 347 #[weight = <T as Config>::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get())]348 fn cancel_named(origin, id: Vec<u8>) {349 T::ScheduleOrigin::ensure_origin(origin.clone())?;350 let origin = <T as Config>::Origin::from(origin);351 Self::do_cancel_named(Some(origin.caller().clone()), id)?;352 }353354 355 356 357 358 359 #[weight = <T as Config>::WeightInfo::schedule(T::MaxScheduledPerBlock::get())]360 fn schedule_after(origin,361 after: T::BlockNumber,362 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,363 priority: schedule::Priority,364 call: Box<<T as Config>::Call>,365 ) {366 T::ScheduleOrigin::ensure_origin(origin.clone())?;367 let origin = <T as Config>::Origin::from(origin);368 Self::do_schedule_nameless(369 DispatchTime::After(after), maybe_periodic, priority, origin.caller().clone(), *call370 )?;371 }372373 374 375 376 377 378 #[weight = <T as Config>::WeightInfo::schedule_named(T::MaxScheduledPerBlock::get())]379 fn schedule_named_after(origin,380 id: Vec<u8>,381 after: T::BlockNumber,382 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,383 priority: schedule::Priority,384 call: Box<<T as Config>::Call>,385 ) {386 T::ScheduleOrigin::ensure_origin(origin.clone())?;387 let origin = <T as Config>::Origin::from(origin);388 Self::do_schedule_named(389 id, DispatchTime::After(after), maybe_periodic, priority, origin.caller().clone(), *call390 )?;391 }392393 394 395 396 397 398 399 400 401 402 403 404 fn on_initialize(now: T::BlockNumber) -> Weight {405 let limit = T::MaximumWeight::get();406 let mut queued = Agenda::<T>::take(now)407 .into_iter()408 .enumerate()409 .filter_map(|(index, s)| s.map(|inner| (index as u32, inner)))410 .collect::<Vec<_>>();411 if queued.len() as u32 > T::MaxScheduledPerBlock::get() {412 log::warn!(413 target: "runtime::scheduler",414 "Warning: This block has more items queued in Scheduler than \415 expected from the runtime configuration. An update might be needed."416 );417 }418 queued.sort_by_key(|(_, s)| s.priority);419 let base_weight: Weight = T::DbWeight::get().reads_writes(1, 2); 420 let mut total_weight: Weight = 0; 421 queued.into_iter()422 .enumerate()423 .scan(base_weight, |cumulative_weight, (order, (index, s))| {424 *cumulative_weight = cumulative_weight425 .saturating_add(s.call.get_dispatch_info().weight);426427 let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(428 s.origin.clone()429 ).into();430431 if ensure_signed(origin).is_ok() {432 433 *cumulative_weight = cumulative_weight434 .saturating_add(T::DbWeight::get().reads_writes(1, 1));435 }436437 if s.maybe_id.is_some() {438 439 *cumulative_weight = cumulative_weight.saturating_add(T::DbWeight::get().writes(1));440 }441 if s.maybe_periodic.is_some() {442 443 *cumulative_weight = cumulative_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));444 }445446 Some((order, index, *cumulative_weight, s))447 })448 .filter_map(|(order, index, cumulative_weight, mut s)| {449 450 451 452 453 454 if s.priority <= schedule::HARD_DEADLINE && cumulative_weight <= limit || order == 0 {455 let r = T::CallExecutor::dispatch_call(s.pre_dispatch.clone(), s.call.clone());456457 if let Err(_) = r {458 log::warn!(459 target: "runtime::scheduler",460 "Warning: Scheduler has failed to execute a post-dispatch transaction. \461 This block might have become invalid.",462 );463 464 }465466 let r = r.unwrap(); 467468 let maybe_id = s.maybe_id.clone();469 if let Some((period, count)) = s.maybe_periodic {470 if count > 1 {471 s.maybe_periodic = Some((period, count - 1));472 } else {473 s.maybe_periodic = None;474 }475 let next = now + period;476 477 if let Some(ref id) = s.maybe_id {478 let next_index = Agenda::<T>::decode_len(now + period).unwrap_or(0);479 Lookup::<T>::insert(id, (next, next_index as u32));480 }481 Agenda::<T>::append(next, Some(s));482 } else if let Some(ref id) = s.maybe_id {483 Lookup::<T>::remove(id);484 }485 Self::deposit_event(RawEvent::Dispatched(486 (now, index),487 maybe_id,488 r.map(|_| ()).map_err(|e| e.error)489 ));490 total_weight = cumulative_weight;491 None492 } else {493 Some(Some(s))494 }495 })496 .for_each(|unused| {497 let next = now + One::one();498 Agenda::<T>::append(next, unused);499 });500501 total_weight502 }503 }504}505506impl<T: Config> Module<T> {507 fn resolve_time(when: DispatchTime<T::BlockNumber>) -> Result<T::BlockNumber, DispatchError> {508 let now = frame_system::Pallet::<T>::block_number();509510 let when = match when {511 DispatchTime::At(x) => x,512 513 514 DispatchTime::After(x) => now.saturating_add(x).saturating_add(One::one()),515 };516517 if when <= now {518 return Err(Error::<T>::TargetBlockNumberInPast.into());519 }520521 Ok(when)522 }523524 fn do_schedule(525 maybe_id: Option<Vec<u8>>,526 when: DispatchTime<T::BlockNumber>,527 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,528 priority: schedule::Priority,529 origin: T::PalletsOrigin,530 call: <T as Config>::Call,531 ) -> Result<(T::BlockNumber, u32), DispatchError> {532 let when = Self::resolve_time(when)?;533534 let sender = ensure_signed(535 <<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone()).into(),536 )537 .unwrap_or_default(); 538 539 540 541542 let pre_dispatch = match T::CallExecutor::pre_dispatch(sender.clone(), call.clone()) {543 Ok(pre_dispatch) => pre_dispatch,544 Err(_) => return Err(Error::<T>::FailedToSchedule.into()),545 };546547 548 549 550551 552 let maybe_periodic = maybe_periodic553 .filter(|p| p.1 > 1 && !p.0.is_zero())554 555 .map(|(p, c)| (p, cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));556557 if let Some(periodic) = maybe_periodic {558 for _i in 0..=periodic.1 {559 560 561 562 }563 }564565 let s = Some(Scheduled {566 maybe_id,567 priority,568 call,569 maybe_periodic,570 origin,571 pre_dispatch,572 _phantom: PhantomData::<T::AccountId>::default(),573 });574 Agenda::<T>::append(when, s);575 let index = Agenda::<T>::decode_len(when).unwrap_or(1) as u32 - 1;576 if index > T::MaxScheduledPerBlock::get() {577 log::warn!(578 target: "runtime::scheduler",579 "Warning: There are more items queued in the Scheduler than \580 expected from the runtime configuration. An update might be needed.",581 );582 }583584 Ok((when, index))585 }586587 fn do_schedule_nameless(588 when: DispatchTime<T::BlockNumber>,589 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,590 priority: schedule::Priority,591 origin: T::PalletsOrigin,592 call: <T as Config>::Call,593 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {594 let address = Self::do_schedule(None, when, maybe_periodic, priority, origin, call)?;595 let (when, index) = address;596597 Self::deposit_event(RawEvent::Scheduled(when, index));598599 Ok(address)600 }601602 fn do_cancel(603 origin: Option<T::PalletsOrigin>,604 (when, index): TaskAddress<T::BlockNumber>,605 ) -> Result<(), DispatchError> {606 let scheduled = Agenda::<T>::try_mutate(when, |agenda| {607 agenda.get_mut(index as usize).map_or(608 Ok(None),609 |s| -> Result<Option<Scheduled<_, _, _, _, _>>, DispatchError> {610 if let (Some(ref o), Some(ref s)) = (origin, s.borrow()) {611 if *o != s.origin {612 return Err(BadOrigin.into());613 }614 };615 Ok(s.take())616 },617 )618 })?;619 if let Some(s) = scheduled {620 if let Some(id) = s.maybe_id {621 Lookup::<T>::remove(id);622 }623 if let Err(_) = T::CallExecutor::cancel_dispatch(s.pre_dispatch.clone()) {624 log::warn!(625 target: "runtime::scheduler",626 "Warning: Scheduler has failed to execute a post-dispatch transaction. \627 This block might have become invalid.",628 );629 } 630 Self::deposit_event(RawEvent::Canceled(when, index));631 Ok(())632 } else {633 Err(Error::<T>::NotFound.into())634 }635 }636637 fn do_reschedule(638 (when, index): TaskAddress<T::BlockNumber>,639 new_time: DispatchTime<T::BlockNumber>,640 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {641 let new_time = Self::resolve_time(new_time)?;642643 if new_time == when {644 return Err(Error::<T>::RescheduleNoChange.into());645 }646647 Agenda::<T>::try_mutate(when, |agenda| -> DispatchResult {648 let task = agenda.get_mut(index as usize).ok_or(Error::<T>::NotFound)?;649 let task = task.take().ok_or(Error::<T>::NotFound)?;650 Agenda::<T>::append(new_time, Some(task));651 Ok(())652 })?;653654 let new_index = Agenda::<T>::decode_len(new_time).unwrap_or(1) as u32 - 1;655 Self::deposit_event(RawEvent::Canceled(when, index));656 Self::deposit_event(RawEvent::Scheduled(new_time, new_index));657658 Ok((new_time, new_index))659 }660661 fn do_schedule_named(662 id: Vec<u8>,663 when: DispatchTime<T::BlockNumber>,664 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,665 priority: schedule::Priority,666 origin: T::PalletsOrigin,667 call: <T as Config>::Call,668 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {669 670 if id.len() > MAX_TASK_ID_LENGTH_IN_BYTES.try_into().unwrap()671 || Lookup::<T>::contains_key(&id)672 {673 return Err(Error::<T>::FailedToSchedule.into());674 }675676 let address = Self::do_schedule(677 Some(id.clone()),678 when,679 maybe_periodic,680 priority,681 origin,682 call,683 )?;684 let (when, index) = address;685686 Lookup::<T>::insert(&id, &address);687 Self::deposit_event(RawEvent::Scheduled(when, index));688 Ok(address)689 }690691 fn do_cancel_named(origin: Option<T::PalletsOrigin>, id: Vec<u8>) -> DispatchResult {692 Lookup::<T>::try_mutate_exists(id, |lookup| -> DispatchResult {693 if let Some((when, index)) = lookup.take() {694 let i = index as usize;695 Agenda::<T>::try_mutate(when, |agenda| -> DispatchResult {696 if let Some(s) = agenda.get_mut(i) {697 if let (Some(ref o), Some(ref s)) = (origin, s.borrow()) {698 if *o != s.origin {699 return Err(BadOrigin.into());700 }701 if let Err(_) = T::CallExecutor::cancel_dispatch(s.pre_dispatch.clone())702 {703 log::warn!(704 target: "runtime::scheduler",705 "Warning: Scheduler has failed to execute a post-dispatch transaction. \706 This block might have become invalid.",707 );708 } 709 }710 *s = None;711 }712 Ok(())713 })?;714 Self::deposit_event(RawEvent::Canceled(when, index));715 Ok(())716 } else {717 Err(Error::<T>::NotFound.into())718 }719 })720 }721722 fn do_reschedule_named(723 id: Vec<u8>,724 new_time: DispatchTime<T::BlockNumber>,725 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {726 let new_time = Self::resolve_time(new_time)?;727728 Lookup::<T>::try_mutate_exists(729 id,730 |lookup| -> Result<TaskAddress<T::BlockNumber>, DispatchError> {731 let (when, index) = lookup.ok_or(Error::<T>::NotFound)?;732733 if new_time == when {734 return Err(Error::<T>::RescheduleNoChange.into());735 }736737 Agenda::<T>::try_mutate(when, |agenda| -> DispatchResult {738 let task = agenda.get_mut(index as usize).ok_or(Error::<T>::NotFound)?;739 let task = task.take().ok_or(Error::<T>::NotFound)?;740 Agenda::<T>::append(new_time, Some(task));741742 Ok(())743 })?;744745 let new_index = Agenda::<T>::decode_len(new_time).unwrap_or(1) as u32 - 1;746 Self::deposit_event(RawEvent::Canceled(when, index));747 Self::deposit_event(RawEvent::Scheduled(new_time, new_index));748749 *lookup = Some((new_time, new_index));750751 Ok((new_time, new_index))752 },753 )754 }755}756757impl<T: Config> schedule::Anon<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin>758 for Module<T>759{760 type Address = TaskAddress<T::BlockNumber>;761762 fn schedule(763 when: DispatchTime<T::BlockNumber>,764 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,765 priority: schedule::Priority,766 origin: T::PalletsOrigin,767 call: <T as Config>::Call,768 ) -> Result<Self::Address, DispatchError> {769 Self::do_schedule_nameless(when, maybe_periodic, priority, origin, call)770 }771772 fn cancel((when, index): Self::Address) -> Result<(), ()> {773 Self::do_cancel(None, (when, index)).map_err(|_| ())774 }775776 fn reschedule(777 address: Self::Address,778 when: DispatchTime<T::BlockNumber>,779 ) -> Result<Self::Address, DispatchError> {780 Self::do_reschedule(address, when)781 }782783 fn next_dispatch_time((when, index): Self::Address) -> Result<T::BlockNumber, ()> {784 Agenda::<T>::get(when)785 .get(index as usize)786 .ok_or(())787 .map(|_| when)788 }789}790791impl<T: Config> schedule::Named<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin>792 for Module<T>793{794 type Address = TaskAddress<T::BlockNumber>;795796 fn schedule_named(797 id: Vec<u8>,798 when: DispatchTime<T::BlockNumber>,799 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,800 priority: schedule::Priority,801 origin: T::PalletsOrigin,802 call: <T as Config>::Call,803 ) -> Result<Self::Address, ()> {804 Self::do_schedule_named(id, when, maybe_periodic, priority, origin, call).map_err(|_| ())805 }806807 fn cancel_named(id: Vec<u8>) -> Result<(), ()> {808 Self::do_cancel_named(None, id).map_err(|_| ())809 }810811 fn reschedule_named(812 id: Vec<u8>,813 when: DispatchTime<T::BlockNumber>,814 ) -> Result<Self::Address, DispatchError> {815 Self::do_reschedule_named(id, when)816 }817818 fn next_dispatch_time(id: Vec<u8>) -> Result<T::BlockNumber, ()> {819 Lookup::<T>::get(id)820 .and_then(|(when, index)| Agenda::<T>::get(when).get(index as usize).map(|_| when))821 .ok_or(())822 }823}824825#[cfg(test)]826#[allow(clippy::from_over_into)]827mod tests {828 use super::*;829830 use frame_support::{831 ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,832 };833 use sp_core::H256;834 use sp_runtime::{835 Perbill,836 testing::Header,837 traits::{BlakeTwo256, IdentityLookup},838 };839 use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};840 use crate as scheduler;841842 mod logger {843 use super::*;844 use std::cell::RefCell;845846 thread_local! {847 static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());848 }849 pub trait Config: system::Config {850 type Event: From<Event> + Into<<Self as system::Config>::Event>;851 }852 decl_event! {853 pub enum Event {854 Logged(u32, Weight),855 }856 }857 decl_module! {858 pub struct Module<T: Config> for enum Call859 where860 origin: <T as system::Config>::Origin,861 <T as system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>862 {863 fn deposit_event() = default;864865 #[weight = *weight]866 fn log(origin, i: u32, weight: Weight) {867 Self::deposit_event(Event::Logged(i, weight));868 LOG.with(|log| {869 log.borrow_mut().push((origin.caller().clone(), i));870 })871 }872873 #[weight = *weight]874 fn log_without_filter(origin, i: u32, weight: Weight) {875 Self::deposit_event(Event::Logged(i, weight));876 LOG.with(|log| {877 log.borrow_mut().push((origin.caller().clone(), i));878 })879 }880 }881 }882 }883884 type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;885 type Block = frame_system::mocking::MockBlock<Test>;886887 frame_support::construct_runtime!(888 pub enum Test where889 Block = Block,890 NodeBlock = Block,891 UncheckedExtrinsic = UncheckedExtrinsic,892 {893 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},894 Logger: logger::{Pallet, Call, Event},895 Scheduler: scheduler::{Pallet, Call, Storage, Event<T>},896 }897 );898899 900 pub struct BaseFilter;901 impl Contains<Call> for BaseFilter {902 fn contains(call: &Call) -> bool {903 !matches!(call, Call::Logger(logger::Call::log { .. }))904 }905 }906907 pub struct DummyExecutor;908 impl<T: frame_system::Config + Config, SelfContainedSignedInfo>909 DispatchCall<T, SelfContainedSignedInfo> for DummyExecutor910 {911 type Pre = ();912913 fn dispatch_call(914 _pre: Self::Pre,915 _call: <T as Config>::Call,916 ) -> Result<917 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,918 TransactionValidityError,919 > {920 todo!()921 }922923 fn pre_dispatch(924 _signer: <T as frame_system::Config>::AccountId,925 _call: <T as Config>::Call,926 ) -> Result<Self::Pre, TransactionValidityError> {927 todo!()928 }929930 fn cancel_dispatch(_pre: Self::Pre) -> Result<(), TransactionValidityError> {931 todo!()932 }933 }934935 parameter_types! {936 pub const BlockHashCount: u64 = 250;937 pub BlockWeights: frame_system::limits::BlockWeights =938 frame_system::limits::BlockWeights::simple_max(2_000_000_000_000);939 }940 impl system::Config for Test {941 type BaseCallFilter = BaseFilter;942 type BlockWeights = ();943 type BlockLength = ();944 type DbWeight = RocksDbWeight;945 type Origin = Origin;946 type Call = Call;947 type Index = u64;948 type BlockNumber = u64;949 type Hash = H256;950 type Hashing = BlakeTwo256;951 type AccountId = u64;952 type Lookup = IdentityLookup<Self::AccountId>;953 type Header = Header;954 type Event = Event;955 type BlockHashCount = BlockHashCount;956 type Version = ();957 type PalletInfo = PalletInfo;958 type AccountData = ();959 type OnNewAccount = ();960 type OnKilledAccount = ();961 type SystemWeightInfo = ();962 type SS58Prefix = ();963 type OnSetCode = ();964 }965 impl logger::Config for Test {966 type Event = Event;967 }968 parameter_types! {969 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;970 pub const MaxScheduledPerBlock: u32 = 10;971 }972 ord_parameter_types! {973 pub const One: u64 = 1;974 }975976 impl Config for Test {977 type Event = Event;978 type Origin = Origin;979 type PalletsOrigin = OriginCaller;980 type Call = Call;981 type MaximumWeight = MaximumSchedulerWeight;982 type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;983 type MaxScheduledPerBlock = MaxScheduledPerBlock;984 type SponsorshipHandler = ();985 type WeightInfo = ();986 type CallExecutor = DummyExecutor;987 }988}