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
6675dependencies = [6675dependencies = [
6676 "frame-support",6676 "frame-support",
6677 "frame-system",6677 "frame-system",
6678 "pallet-unique-scheduler",
6678 "parity-scale-codec 3.1.5",6679 "parity-scale-codec 3.1.5",
6679 "scale-info",6680 "scale-info",
6680]6681]
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
--- a/test-pallets/utils/src/lib.rs
+++ b/test-pallets/utils/src/lib.rs
@@ -16,15 +16,17 @@
 
 #![cfg_attr(not(feature = "std"), no_std)]
 
+
 pub use pallet::*;
 
 #[frame_support::pallet]
 pub mod pallet {
 	use frame_support::pallet_prelude::*;
 	use frame_system::pallet_prelude::*;
+	use pallet_unique_scheduler::{ScheduledId, Pallet as SchedulerPallet};
 
 	#[pallet::config]
-	pub trait Config: frame_system::Config {
+	pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {
 		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
 	}
 
@@ -40,7 +42,7 @@
 	pub struct Pallet<T>(_);
 
 	#[pallet::storage]
-	#[pallet::getter(fn something)]
+	#[pallet::getter(fn test_value)]
 	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;
 
 	#[pallet::error]
@@ -70,6 +72,26 @@
 			Err(<Error<T>>::TriggerRollback.into())
 		}
 
+		#[pallet::weight(10_000)]
+		pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {
+			Self::set_test_value(origin, <TestValue<T>>::get() + 1)
+		}
+
+		#[pallet::weight(10_000)]
+		pub fn self_canceling_inc(
+			origin: OriginFor<T>,
+			id: ScheduledId,
+			max_test_value: u32,
+		) -> DispatchResult {
+			if <TestValue<T>>::get() < max_test_value {
+				Self::inc_test_value(origin)?;
+			} else {
+				SchedulerPallet::<T>::cancel_named(origin, id)?;
+			}
+
+			Ok(())
+		}
+
 		#[pallet::weight(100_000_000)]
 		pub fn just_take_fee(_origin: OriginFor<T>) -> DispatchResult {
 			Ok(())