git.delta.rocks / unique-network / refs/commits / fd7a252de8c6

difftreelog

ffeat: add new fns to test-utils pallet

Daniel Shiposha2022-09-12parent: #6f1c728.patch.diff
in: master

3 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6675,6 +6675,7 @@
 dependencies = [
  "frame-support",
  "frame-system",
+ "pallet-unique-scheduler",
  "parity-scale-codec 3.1.5",
  "scale-info",
 ]
modifiedtest-pallets/utils/Cargo.tomldiffbeforeafterboth
--- a/test-pallets/utils/Cargo.toml
+++ b/test-pallets/utils/Cargo.toml
@@ -10,6 +10,7 @@
 scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
 frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
 frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false }
 
 [features]
 default = ["std"]
@@ -18,4 +19,5 @@
 	"scale-info/std",
 	"frame-support/std",
 	"frame-system/std",
+	"pallet-unique-scheduler/std",
 ]
modifiedtest-pallets/utils/src/lib.rsdiffbeforeafterboth
before · test-pallets/utils/src/lib.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#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;2021#[frame_support::pallet]22pub mod pallet {23	use frame_support::pallet_prelude::*;24	use frame_system::pallet_prelude::*;2526	#[pallet::config]27	pub trait Config: frame_system::Config {28		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;29	}3031	#[pallet::event]32	#[pallet::generate_deposit(pub(super) fn deposit_event)]33	pub enum Event<T: Config> {34		ValueIsSet,35		ShouldRollback,36	}3738	#[pallet::pallet]39	#[pallet::generate_store(pub(super) trait Store)]40	pub struct Pallet<T>(_);4142	#[pallet::storage]43	#[pallet::getter(fn something)]44	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;4546	#[pallet::error]47	pub enum Error<T> {48		TriggerRollback,49	}5051	#[pallet::call]52	impl<T: Config> Pallet<T> {53		#[pallet::weight(10_000)]54		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {55			ensure_signed(origin)?;5657			<TestValue<T>>::put(value);5859			Self::deposit_event(Event::ValueIsSet);6061			Ok(())62		}6364		#[pallet::weight(10_000)]65		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {66			Self::set_test_value(origin, value)?;6768			Self::deposit_event(Event::ShouldRollback);6970			Err(<Error<T>>::TriggerRollback.into())71		}7273		#[pallet::weight(100_000_000)]74		pub fn just_take_fee(_origin: OriginFor<T>) -> DispatchResult {75			Ok(())76		}77	}78}
after · test-pallets/utils/src/lib.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#![cfg_attr(not(feature = "std"), no_std)]181920pub use pallet::*;2122#[frame_support::pallet]23pub mod pallet {24	use frame_support::pallet_prelude::*;25	use frame_system::pallet_prelude::*;26	use pallet_unique_scheduler::{ScheduledId, Pallet as SchedulerPallet};2728	#[pallet::config]29	pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {30		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;31	}3233	#[pallet::event]34	#[pallet::generate_deposit(pub(super) fn deposit_event)]35	pub enum Event<T: Config> {36		ValueIsSet,37		ShouldRollback,38	}3940	#[pallet::pallet]41	#[pallet::generate_store(pub(super) trait Store)]42	pub struct Pallet<T>(_);4344	#[pallet::storage]45	#[pallet::getter(fn test_value)]46	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;4748	#[pallet::error]49	pub enum Error<T> {50		TriggerRollback,51	}5253	#[pallet::call]54	impl<T: Config> Pallet<T> {55		#[pallet::weight(10_000)]56		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {57			ensure_signed(origin)?;5859			<TestValue<T>>::put(value);6061			Self::deposit_event(Event::ValueIsSet);6263			Ok(())64		}6566		#[pallet::weight(10_000)]67		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {68			Self::set_test_value(origin, value)?;6970			Self::deposit_event(Event::ShouldRollback);7172			Err(<Error<T>>::TriggerRollback.into())73		}7475		#[pallet::weight(10_000)]76		pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {77			Self::set_test_value(origin, <TestValue<T>>::get() + 1)78		}7980		#[pallet::weight(10_000)]81		pub fn self_canceling_inc(82			origin: OriginFor<T>,83			id: ScheduledId,84			max_test_value: u32,85		) -> DispatchResult {86			if <TestValue<T>>::get() < max_test_value {87				Self::inc_test_value(origin)?;88			} else {89				SchedulerPallet::<T>::cancel_named(origin, id)?;90			}9192			Ok(())93		}9495		#[pallet::weight(100_000_000)]96		pub fn just_take_fee(_origin: OriginFor<T>) -> DispatchResult {97			Ok(())98		}99	}100}