difftreelog
ffeat: add new fns to test-utils pallet
in: master
3 files changed
Cargo.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",
]
test-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",
]
test-pallets/utils/src/lib.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#![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}