difftreelog
fix cargo fmt
in: master
4 files changed
pallets/scheduler-v2/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/lib.rs
+++ b/pallets/scheduler-v2/src/lib.rs
@@ -77,13 +77,16 @@
use codec::{Codec, Decode, Encode, MaxEncodedLen};
use frame_support::{
- dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, PostDispatchInfo},
+ dispatch::{
+ DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, PostDispatchInfo,
+ },
traits::{
schedule::{self, DispatchTime, LOWEST_PRIORITY},
EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,
ConstU32, UnfilteredDispatchable,
},
- weights::Weight, unsigned::TransactionValidityError,
+ weights::Weight,
+ unsigned::TransactionValidityError,
};
use frame_system::{self as system};
@@ -318,8 +321,10 @@
/// The aggregated call type.
type RuntimeCall: Parameter
- + Dispatchable<RuntimeOrigin = <Self as Config>::RuntimeOrigin, PostInfo = PostDispatchInfo>
- + UnfilteredDispatchable<RuntimeOrigin = <Self as system::Config>::RuntimeOrigin>
+ + Dispatchable<
+ RuntimeOrigin = <Self as Config>::RuntimeOrigin,
+ PostInfo = PostDispatchInfo,
+ > + UnfilteredDispatchable<RuntimeOrigin = <Self as system::Config>::RuntimeOrigin>
+ GetDispatchInfo
+ From<system::Call<Self>>;
@@ -940,7 +945,7 @@
}
return Err((Unavailable, Some(task)));
- },
+ }
};
weight.check_accrue(T::WeightInfo::service_task(
@@ -979,7 +984,7 @@
Err(Overweight) => {
// Preserve Lookup -- the task will be postponed.
Err((Overweight, Some(task)))
- },
+ }
Ok(result) => {
Self::deposit_event(Event::Dispatched {
task: (when, agenda_index),
@@ -987,7 +992,9 @@
result,
});
- let is_canceled = task.maybe_id.as_ref()
+ let is_canceled = task
+ .maybe_id
+ .as_ref()
.map(|id| !Lookup::<T>::contains_key(id))
.unwrap_or(false);
@@ -1011,14 +1018,14 @@
});
}
}
- },
+ }
_ => {
if let Some(ref id) = task.maybe_id {
Lookup::<T>::remove(id);
}
T::Preimages::drop(&task.call)
- },
+ }
}
Ok(())
}
@@ -1056,12 +1063,12 @@
let r = match ensured_origin {
Ok(ScheduledEnsureOriginSuccess::Root) => {
Ok(call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()))
- },
+ }
Ok(ScheduledEnsureOriginSuccess::Signed(sender)) => {
// Execute transaction via chain default pipeline
// That means dispatch will be processed like any user's extrinsic e.g. transaction fees will be taken
T::CallExecutor::dispatch_call(Some(sender), call.clone())
- },
+ }
Ok(ScheduledEnsureOriginSuccess::Unsigned) => {
// Unsigned version of the above
T::CallExecutor::dispatch_call(None, call.clone())
pallets/scheduler-v2/src/mock.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435//! # Scheduler test environment.3637use super::*;3839use crate as scheduler;40use frame_support::{41 ord_parameter_types, parameter_types,42 traits::{43 ConstU32, ConstU64, Contains, EqualPrivilegeOnly, OnFinalize, OnInitialize,44 },45 weights::constants::RocksDbWeight,46};47use frame_system::{EnsureRoot, RawOrigin};48use sp_core::H256;49use sp_runtime::{50 testing::Header,51 traits::{BlakeTwo256, IdentityLookup},52 Perbill,53};5455// Logger module to track execution.56#[frame_support::pallet]57pub mod logger {58 use super::{OriginCaller, OriginTrait};59 use frame_support::{pallet_prelude::*, parameter_types};60 use frame_system::pallet_prelude::*;6162 parameter_types! {63 static Log: Vec<(OriginCaller, u32)> = Vec::new();64 }65 pub fn log() -> Vec<(OriginCaller, u32)> {66 Log::get().clone()67 }6869 #[pallet::pallet]70 #[pallet::generate_store(pub(super) trait Store)]71 pub struct Pallet<T>(PhantomData<T>);7273 #[pallet::hooks]74 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}7576 #[pallet::config]77 pub trait Config: frame_system::Config {78 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;79 }8081 #[pallet::event]82 #[pallet::generate_deposit(pub(super) fn deposit_event)]83 pub enum Event<T: Config> {84 Logged(u32, Weight),85 }8687 #[pallet::call]88 impl<T: Config> Pallet<T>89 where90 <T as frame_system::Config>::RuntimeOrigin: OriginTrait<PalletsOrigin = OriginCaller>,91 {92 #[pallet::weight(*weight)]93 pub fn log(origin: OriginFor<T>, i: u32, weight: Weight) -> DispatchResult {94 Self::deposit_event(Event::Logged(i, weight));95 Log::mutate(|log| {96 log.push((origin.caller().clone(), i));97 });98 Ok(())99 }100101 #[pallet::weight(*weight)]102 pub fn log_without_filter(origin: OriginFor<T>, i: u32, weight: Weight) -> DispatchResult {103 Self::deposit_event(Event::Logged(i, weight));104 Log::mutate(|log| {105 log.push((origin.caller().clone(), i));106 });107 Ok(())108 }109 }110}111112type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;113type Block = frame_system::mocking::MockBlock<Test>;114115frame_support::construct_runtime!(116 pub enum Test where117 Block = Block,118 NodeBlock = Block,119 UncheckedExtrinsic = UncheckedExtrinsic,120 {121 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},122 Logger: logger::{Pallet, Call, Event<T>},123 Scheduler: scheduler::{Pallet, Call, Storage, Event<T>},124 }125);126127// Scheduler must dispatch with root and no filter, this tests base filter is indeed not used.128pub struct BaseFilter;129impl Contains<RuntimeCall> for BaseFilter {130 fn contains(call: &RuntimeCall) -> bool {131 !matches!(call, RuntimeCall::Logger(LoggerCall::log { .. }))132 }133}134135parameter_types! {136 pub BlockWeights: frame_system::limits::BlockWeights =137 frame_system::limits::BlockWeights::simple_max(138 Weight::from_ref_time(2_000_000_000_000)139 // .set_proof_size(u64::MAX),140 );141}142impl system::Config for Test {143 type BaseCallFilter = BaseFilter;144 type BlockWeights = BlockWeights;145 type BlockLength = ();146 type DbWeight = RocksDbWeight;147 type RuntimeOrigin = RuntimeOrigin;148 type RuntimeCall = RuntimeCall;149 type Index = u64;150 type BlockNumber = u64;151 type Hash = H256;152 type Hashing = BlakeTwo256;153 type AccountId = u64;154 type Lookup = IdentityLookup<Self::AccountId>;155 type Header = Header;156 type RuntimeEvent = RuntimeEvent;157 type BlockHashCount = ConstU64<250>;158 type Version = ();159 type PalletInfo = PalletInfo;160 type AccountData = ();161 type OnNewAccount = ();162 type OnKilledAccount = ();163 type SystemWeightInfo = ();164 type SS58Prefix = ();165 type OnSetCode = ();166 type MaxConsumers = ConstU32<16>;167}168impl logger::Config for Test {169 type RuntimeEvent = RuntimeEvent;170}171ord_parameter_types! {172 pub const One: u64 = 1;173}174175pub struct TestWeightInfo;176impl WeightInfo for TestWeightInfo {177 fn service_agendas_base() -> Weight {178 Weight::from_ref_time(0b0000_0001)179 }180 fn service_agenda_base(i: u32) -> Weight {181 Weight::from_ref_time((i << 8) as u64 + 0b0000_0010)182 }183 fn service_task_base() -> Weight {184 Weight::from_ref_time(0b0000_0100)185 }186 fn service_task_periodic() -> Weight {187 Weight::from_ref_time(0b0000_1100)188 }189 fn service_task_named() -> Weight {190 Weight::from_ref_time(0b0001_0100)191 }192 fn service_task_fetched(s: u32) -> Weight {193 Weight::from_ref_time((s << 8) as u64 + 0b0010_0100)194 }195 fn execute_dispatch_signed() -> Weight {196 Weight::from_ref_time(0b0100_0000)197 }198 fn execute_dispatch_unsigned() -> Weight {199 Weight::from_ref_time(0b1000_0000)200 }201 fn schedule(_s: u32) -> Weight {202 Weight::from_ref_time(50)203 }204 fn cancel(_s: u32) -> Weight {205 Weight::from_ref_time(50)206 }207 fn schedule_named(_s: u32) -> Weight {208 Weight::from_ref_time(50)209 }210 fn cancel_named(_s: u32) -> Weight {211 Weight::from_ref_time(50)212 }213 fn change_named_priority(_s: u32, ) -> Weight {214 Weight::from_ref_time(50)215 }216}217parameter_types! {218 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *219 BlockWeights::get().max_block;220}221222pub struct EnsureSignedOneOrRoot;223impl<O: Into<Result<RawOrigin<u64>, O>> + From<RawOrigin<u64>>>224 EnsureOrigin<O> for EnsureSignedOneOrRoot225{226 type Success = ScheduledEnsureOriginSuccess<u64>;227 fn try_origin(o: O) -> Result<Self::Success, O> {228 o.into().and_then(|o| match o {229 RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),230 RawOrigin::Signed(1) => Ok(ScheduledEnsureOriginSuccess::Signed(1)),231 r => Err(O::from(r)),232 })233 }234}235236pub struct Executor;237impl DispatchCall<Test, sp_core::H160> for Executor {238 fn dispatch_call(239 signer: Option<u64>,240 function: RuntimeCall,241 ) -> Result<242 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,243 TransactionValidityError,244 > {245 let origin = match signer {246 Some(who) => RuntimeOrigin::signed(who),247 None => RuntimeOrigin::none(),248 };249 Ok(function.dispatch(origin))250 }251}252253impl Config for Test {254 type RuntimeEvent = RuntimeEvent;255 type RuntimeOrigin = RuntimeOrigin;256 type PalletsOrigin = OriginCaller;257 type RuntimeCall = RuntimeCall;258 type MaximumWeight = MaximumSchedulerWeight;259 type ScheduleOrigin = EnsureSignedOneOrRoot;260 type MaxScheduledPerBlock = ConstU32<10>;261 type WeightInfo = TestWeightInfo;262 type OriginPrivilegeCmp = EqualPrivilegeOnly;263 type Preimages = ();264 type PrioritySetOrigin = EnsureRoot<u64>;265 type CallExecutor = Executor;266}267268pub type LoggerCall = logger::Call<Test>;269270pub fn new_test_ext() -> sp_io::TestExternalities {271 let t = system::GenesisConfig::default().build_storage::<Test>().unwrap();272 t.into()273}274275pub fn run_to_block(n: u64) {276 while System::block_number() < n {277 Scheduler::on_finalize(System::block_number());278 System::set_block_number(System::block_number() + 1);279 Scheduler::on_initialize(System::block_number());280 }281}282283pub fn root() -> OriginCaller {284 system::RawOrigin::Root.into()285}pallets/scheduler-v2/src/tests.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/tests.rs
+++ b/pallets/scheduler-v2/src/tests.rs
@@ -46,15 +46,19 @@
#[test]
fn basic_scheduling_works() {
new_test_ext().execute_with(|| {
- let call =
- RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
- assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: Weight::from_ref_time(10),
+ });
+ assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(
+ &call
+ ));
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
127,
root(),
- <ScheduledCall<Test>>::new(call).unwrap(),
+ <ScheduledCall<Test>>::new(call).unwrap(),
));
run_to_block(3);
assert!(logger::log().is_empty());
@@ -69,9 +73,13 @@
fn schedule_after_works() {
new_test_ext().execute_with(|| {
run_to_block(2);
- let call =
- RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
- assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: Weight::from_ref_time(10),
+ });
+ assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(
+ &call
+ ));
// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
assert_ok!(Scheduler::do_schedule(
DispatchTime::After(3),
@@ -93,9 +101,13 @@
fn schedule_after_zero_works() {
new_test_ext().execute_with(|| {
run_to_block(2);
- let call =
- RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
- assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: Weight::from_ref_time(10),
+ });
+ assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(
+ &call
+ ));
assert_ok!(Scheduler::do_schedule(
DispatchTime::After(0),
None,
@@ -120,7 +132,7 @@
Some((3, 3)),
127,
root(),
- <ScheduledCall<Test>>::new(RuntimeCall::Logger(logger::Call::log {
+ <ScheduledCall<Test>>::new(RuntimeCall::Logger(logger::Call::log {
i: 42,
weight: Weight::from_ref_time(10)
}))
@@ -137,9 +149,15 @@
run_to_block(9);
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
run_to_block(10);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
+ assert_eq!(
+ logger::log(),
+ vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
+ );
run_to_block(100);
- assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
+ assert_eq!(
+ logger::log(),
+ vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]
+ );
});
}
@@ -241,7 +259,10 @@
fn scheduler_respects_weight_limits() {
let max_weight: Weight = <Test as Config>::MaximumWeight::get();
new_test_ext().execute_with(|| {
- let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 3 * 2 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: max_weight / 3 * 2,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -249,7 +270,10 @@
root(),
<ScheduledCall<Test>>::new(call).unwrap(),
));
- let call = RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 3 * 2 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 69,
+ weight: max_weight / 3 * 2,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -270,7 +294,10 @@
fn scheduler_does_not_delete_permanently_overweight_call() {
let max_weight: Weight = <Test as Config>::MaximumWeight::get();
new_test_ext().execute_with(|| {
- let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: max_weight,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -285,7 +312,11 @@
// Assert the `PermanentlyOverweight` event.
assert_eq!(
System::events().last().unwrap().event,
- crate::Event::PermanentlyOverweight { task: (4, 0), id: None }.into(),
+ crate::Event::PermanentlyOverweight {
+ task: (4, 0),
+ id: None
+ }
+ .into(),
);
// The call is still in the agenda.
assert!(Agenda::<Test>::get(4)[0].is_some());
@@ -298,7 +329,10 @@
let max_per_block = <Test as Config>::MaxScheduledPerBlock::get();
new_test_ext().execute_with(|| {
- let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: (max_weight / 3) * 2 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: (max_weight / 3) * 2,
+ });
let call = <ScheduledCall<Test>>::new(call).unwrap();
assert_ok!(Scheduler::do_schedule(
@@ -329,7 +363,11 @@
assert_eq!(
System::events().last().unwrap().event,
- crate::Event::PeriodicFailed { task: (24, 0), id: None }.into(),
+ crate::Event::PeriodicFailed {
+ task: (24, 0),
+ id: None
+ }
+ .into(),
);
});
}
@@ -338,7 +376,10 @@
fn scheduler_respects_priority_ordering() {
let max_weight: Weight = <Test as Config>::MaximumWeight::get();
new_test_ext().execute_with(|| {
- let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 3 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: max_weight / 3,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -346,7 +387,10 @@
root(),
<ScheduledCall<Test>>::new(call).unwrap(),
));
- let call = RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 3 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 69,
+ weight: max_weight / 3,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -363,7 +407,10 @@
fn scheduler_respects_priority_ordering_with_soft_deadlines() {
new_test_ext().execute_with(|| {
let max_weight: Weight = <Test as Config>::MaximumWeight::get();
- let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: max_weight / 5 * 2 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: max_weight / 5 * 2,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -371,7 +418,10 @@
root(),
<ScheduledCall<Test>>::new(call).unwrap(),
));
- let call = RuntimeCall::Logger(LoggerCall::log { i: 69, weight: max_weight / 5 * 2 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 69,
+ weight: max_weight / 5 * 2,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -379,7 +429,10 @@
root(),
<ScheduledCall<Test>>::new(call).unwrap(),
));
- let call = RuntimeCall::Logger(LoggerCall::log { i: 2600, weight: max_weight / 5 * 4 });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 2600,
+ weight: max_weight / 5 * 4,
+ });
assert_ok!(Scheduler::do_schedule(
DispatchTime::At(4),
None,
@@ -393,7 +446,10 @@
assert_eq!(logger::log(), vec![(root(), 2600u32)]);
// 69 and 42 fit together
run_to_block(5);
- assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
+ assert_eq!(
+ logger::log(),
+ vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]
+ );
});
}
@@ -456,11 +512,11 @@
// Will include the named periodic only
assert_eq!(
Scheduler::on_initialize(1),
- TestWeightInfo::service_agendas_base() +
- TestWeightInfo::service_agenda_base(1) +
- <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, true) +
- TestWeightInfo::execute_dispatch_unsigned() +
- call_weight + Weight::from_ref_time(4)
+ TestWeightInfo::service_agendas_base()
+ + TestWeightInfo::service_agenda_base(1)
+ + <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, true)
+ + TestWeightInfo::execute_dispatch_unsigned()
+ + call_weight + Weight::from_ref_time(4)
);
assert_eq!(IncompleteSince::<Test>::get(), None);
assert_eq!(logger::log(), vec![(root(), 2600u32)]);
@@ -468,31 +524,39 @@
// Will include anon and anon periodic
assert_eq!(
Scheduler::on_initialize(2),
- TestWeightInfo::service_agendas_base() +
- TestWeightInfo::service_agenda_base(2) +
- <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, true) +
- TestWeightInfo::execute_dispatch_unsigned() +
- call_weight + Weight::from_ref_time(3) +
- <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, false) +
- TestWeightInfo::execute_dispatch_unsigned() +
- call_weight + Weight::from_ref_time(2)
+ TestWeightInfo::service_agendas_base()
+ + TestWeightInfo::service_agenda_base(2)
+ + <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, true)
+ + TestWeightInfo::execute_dispatch_unsigned()
+ + call_weight + Weight::from_ref_time(3)
+ + <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, false)
+ + TestWeightInfo::execute_dispatch_unsigned()
+ + call_weight + Weight::from_ref_time(2)
);
assert_eq!(IncompleteSince::<Test>::get(), None);
- assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
+ assert_eq!(
+ logger::log(),
+ vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]
+ );
// Will include named only
assert_eq!(
Scheduler::on_initialize(3),
- TestWeightInfo::service_agendas_base() +
- TestWeightInfo::service_agenda_base(1) +
- <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, false) +
- TestWeightInfo::execute_dispatch_unsigned() +
- call_weight + Weight::from_ref_time(1)
+ TestWeightInfo::service_agendas_base()
+ + TestWeightInfo::service_agenda_base(1)
+ + <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, false)
+ + TestWeightInfo::execute_dispatch_unsigned()
+ + call_weight + Weight::from_ref_time(1)
);
assert_eq!(IncompleteSince::<Test>::get(), None);
assert_eq!(
logger::log(),
- vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32), (root(), 3u32)]
+ vec![
+ (root(), 2600u32),
+ (root(), 69u32),
+ (root(), 42u32),
+ (root(), 3u32)
+ ]
);
// Will contain none
@@ -515,10 +579,21 @@
i: 42,
weight: Weight::from_ref_time(10),
}));
- assert_ok!(
- Scheduler::schedule_named(RuntimeOrigin::root(), [1u8; 32], 4, None, Some(127), call,)
- );
- assert_ok!(Scheduler::schedule(RuntimeOrigin::root(), 4, None, Some(127), call2));
+ assert_ok!(Scheduler::schedule_named(
+ RuntimeOrigin::root(),
+ [1u8; 32],
+ 4,
+ None,
+ Some(127),
+ call,
+ ));
+ assert_ok!(Scheduler::schedule(
+ RuntimeOrigin::root(),
+ 4,
+ None,
+ Some(127),
+ call2
+ ));
run_to_block(3);
// Scheduled calls are in the agenda.
assert_eq!(Agenda::<Test>::get(4).len(), 2);
@@ -585,12 +660,21 @@
None,
call,
));
- assert_ok!(Scheduler::schedule(system::RawOrigin::Signed(1).into(), 4, None, None, call2,));
+ assert_ok!(Scheduler::schedule(
+ system::RawOrigin::Signed(1).into(),
+ 4,
+ None,
+ None,
+ call2,
+ ));
run_to_block(3);
// Scheduled calls are in the agenda.
assert_eq!(Agenda::<Test>::get(4).len(), 2);
assert!(logger::log().is_empty());
- assert_ok!(Scheduler::cancel_named(system::RawOrigin::Signed(1).into(), [1u8; 32]));
+ assert_ok!(Scheduler::cancel_named(
+ system::RawOrigin::Signed(1).into(),
+ [1u8; 32]
+ ));
assert_ok!(Scheduler::cancel(system::RawOrigin::Signed(1).into(), 4, 1));
// Scheduled calls are made NONE, so should not effect state
run_to_block(100);
@@ -646,7 +730,13 @@
None,
call,
));
- assert_ok!(Scheduler::schedule(system::RawOrigin::Signed(1).into(), 4, None, None, call2,));
+ assert_ok!(Scheduler::schedule(
+ system::RawOrigin::Signed(1).into(),
+ 4,
+ None,
+ None,
+ call2,
+ ));
run_to_block(3);
// Scheduled calls are in the agenda.
assert_eq!(Agenda::<Test>::get(4).len(), 2);
@@ -655,9 +745,18 @@
Scheduler::cancel_named(system::RawOrigin::Signed(2).into(), [1u8; 32]),
BadOrigin
);
- assert_noop!(Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1), BadOrigin);
- assert_noop!(Scheduler::cancel_named(system::RawOrigin::Root.into(), [1u8; 32]), BadOrigin);
- assert_noop!(Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1), BadOrigin);
+ assert_noop!(
+ Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1),
+ BadOrigin
+ );
+ assert_noop!(
+ Scheduler::cancel_named(system::RawOrigin::Root.into(), [1u8; 32]),
+ BadOrigin
+ );
+ assert_noop!(
+ Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1),
+ BadOrigin
+ );
run_to_block(5);
assert_eq!(
logger::log(),
@@ -674,8 +773,10 @@
#[test]
fn schedule_does_not_resuse_addr() {
new_test_ext().execute_with(|| {
- let call =
- RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: Weight::from_ref_time(10),
+ });
// Schedule both calls.
let addr_1 = Scheduler::do_schedule(
@@ -707,20 +808,15 @@
let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();
new_test_ext().execute_with(|| {
- let call =
- RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: Weight::from_ref_time(10),
+ });
let call = <ScheduledCall<Test>>::new(call).unwrap();
// Schedule the maximal number allowed per block.
for _ in 0..max {
- Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- call.clone(),
- )
- .unwrap();
+ Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone()).unwrap();
}
// One more time and it errors.
@@ -739,25 +835,24 @@
#[test]
fn cancel_and_schedule_fills_holes() {
let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();
- assert!(max > 3, "This test only makes sense for MaxScheduledPerBlock > 3");
+ assert!(
+ max > 3,
+ "This test only makes sense for MaxScheduledPerBlock > 3"
+ );
new_test_ext().execute_with(|| {
- let call =
- RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) });
+ let call = RuntimeCall::Logger(LoggerCall::log {
+ i: 42,
+ weight: Weight::from_ref_time(10),
+ });
let call = <ScheduledCall<Test>>::new(call).unwrap();
let mut addrs = Vec::<_>::default();
// Schedule the maximal number allowed per block.
for _ in 0..max {
addrs.push(
- Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- call.clone(),
- )
- .unwrap(),
+ Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())
+ .unwrap(),
);
}
// Cancel three of them.
@@ -766,14 +861,9 @@
}
// Schedule three new ones.
for i in 0..3 {
- let (_block, index) = Scheduler::do_schedule(
- DispatchTime::At(4),
- None,
- 127,
- root(),
- call.clone(),
- )
- .unwrap();
+ let (_block, index) =
+ Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())
+ .unwrap();
assert_eq!(i, index);
}
runtime/common/scheduler.rsdiffbeforeafterboth--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -105,7 +105,6 @@
}
}
-
// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>
// DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor
// where