git.delta.rocks / unique-network / refs/commits / 829f2bcebad6

difftreelog

fix scheduler warnings

Daniel Shiposha2022-10-25parent: #53db16c.patch.diff
in: master

3 files changed

modifiedpallets/scheduler-v2/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/lib.rs
+++ b/pallets/scheduler-v2/src/lib.rs
@@ -77,13 +77,13 @@
 
 use codec::{Codec, Decode, Encode, MaxEncodedLen};
 use frame_support::{
-	dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter},
+	dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, PostDispatchInfo},
 	traits::{
 		schedule::{self, DispatchTime, LOWEST_PRIORITY},
 		EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,
 		ConstU32, UnfilteredDispatchable,
 	},
-	weights::{Weight, PostDispatchInfo}, unsigned::TransactionValidityError,
+	weights::Weight, unsigned::TransactionValidityError,
 };
 
 use frame_system::{self as system};
modifiedpallets/scheduler-v2/src/mock.rsdiffbeforeafterboth
before · pallets/scheduler-v2/src/mock.rs
1// 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, EitherOfDiverse, EqualPrivilegeOnly, OnFinalize, OnInitialize,44	},45	weights::constants::RocksDbWeight,46};47use frame_system::{EnsureRoot, EnsureSignedBy, 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}
after · pallets/scheduler-v2/src/mock.rs
1// 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}
modifiedpallets/scheduler-v2/src/tests.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/tests.rs
+++ b/pallets/scheduler-v2/src/tests.rs
@@ -40,8 +40,7 @@
 };
 use frame_support::{
 	assert_noop, assert_ok,
-	traits::{Contains, GetStorageVersion, OnInitialize},
-	Hashable,
+	traits::{Contains, OnInitialize},
 };
 
 #[test]