Browse Source

runtime: Upgrade the ‘hiring’ pallet.

Shamil Gadelshin 4 years ago
parent
commit
654fa04ab5

+ 113 - 0
Cargo.lock

@@ -282,6 +282,12 @@ dependencies = [
  "syn",
 ]
 
+[[package]]
+name = "difference"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
+
 [[package]]
 name = "digest"
 version = "0.8.1"
@@ -291,6 +297,12 @@ dependencies = [
  "generic-array",
 ]
 
+[[package]]
+name = "downcast"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d"
+
 [[package]]
 name = "ed25519-dalek"
 version = "1.0.0-pre.3"
@@ -355,6 +367,21 @@ dependencies = [
  "static_assertions",
 ]
 
+[[package]]
+name = "float-cmp"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da62c4f1b81918835a8c6a484a397775fff5953fe83529afd51b05f5c6a6617d"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "fragile"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9"
+
 [[package]]
 name = "frame-benchmarking"
 version = "2.0.0-rc4"
@@ -818,6 +845,33 @@ dependencies = [
  "zeroize",
 ]
 
+[[package]]
+name = "mockall"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b95a7e7cfbce0e99ebbf5356a085d3b5e320a7ef300f77cd50a7148aa362e7c2"
+dependencies = [
+ "cfg-if",
+ "downcast",
+ "fragile",
+ "lazy_static",
+ "mockall_derive",
+ "predicates",
+ "predicates-tree",
+]
+
+[[package]]
+name = "mockall_derive"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d5a615a1ad92048ad5d9633251edb7492b8abc057d7a679a9898476aef173935"
+dependencies = [
+ "cfg-if",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "nalgebra"
 version = "0.18.1"
@@ -841,6 +895,12 @@ version = "0.1.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
 
+[[package]]
+name = "normalize-line-endings"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
+
 [[package]]
 name = "num-bigint"
 version = "0.2.6"
@@ -943,6 +1003,24 @@ dependencies = [
  "sp-runtime",
 ]
 
+[[package]]
+name = "pallet-hiring"
+version = "3.0.0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "mockall",
+ "pallet-balances",
+ "pallet-stake",
+ "parity-scale-codec",
+ "serde",
+ "sp-arithmetic",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
 [[package]]
 name = "pallet-memo"
 version = "3.0.0"
@@ -1197,6 +1275,35 @@ version = "0.2.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
 
+[[package]]
+name = "predicates"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "347a1b6f0b21e636bc9872fb60b83b8e185f6f5516298b8238699f7f9a531030"
+dependencies = [
+ "difference",
+ "float-cmp",
+ "normalize-line-endings",
+ "predicates-core",
+ "regex",
+]
+
+[[package]]
+name = "predicates-core"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178"
+
+[[package]]
+name = "predicates-tree"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124"
+dependencies = [
+ "predicates-core",
+ "treeline",
+]
+
 [[package]]
 name = "primitive-types"
 version = "0.7.1"
@@ -2076,6 +2183,12 @@ dependencies = [
  "lazy_static",
 ]
 
+[[package]]
+name = "treeline"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
+
 [[package]]
 name = "trie-db"
 version = "0.21.0"

+ 1 - 1
Cargo.toml

@@ -8,7 +8,7 @@ members = [
 #	"runtime-modules/content-working-group",
 #	"runtime-modules/forum",
 #	"runtime-modules/governance",
-#	"runtime-modules/hiring",
+	"runtime-modules/hiring",
 #	"runtime-modules/membership",
 	"runtime-modules/memo",
 	"runtime-modules/recurring-reward",

+ 17 - 43
runtime-modules/hiring/Cargo.toml

@@ -1,60 +1,34 @@
 [package]
-name = 'substrate-hiring-module'
-version = '1.0.2'
+name = 'pallet-hiring'
+version = '3.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
 
 [dependencies]
-hex-literal = '0.1.0'
-serde = { version = '1.0', optional = true }
-serde_derive = { version = '1.0', optional = true }
-rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-balances = { package = 'srml-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] }
-mockall = {version = "0.6.0", optional = true}
-# https://users.rust-lang.org/t/failure-derive-compilation-error/39062
-quote = '<=1.0.2'
-
-[dependencies.stake]
-default_features = false
-package = 'substrate-stake-module'
-path = '../stake'
-
-[dependencies.timestamp]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'srml-timestamp'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dependencies.runtime-io]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'sr-io'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
+serde = { version = "1.0.101", optional = true, features = ["derive"] }
+codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+rstd = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+stake = { package = 'pallet-stake', default-features = false, path = '../stake'}
 
 [dev-dependencies]
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
 mockall = "0.6.0"
-
+sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 
 [features]
 default = ['std']
-test = ['mockall']
 std = [
 	'serde',
-	'serde_derive',
 	'codec/std',
 	'rstd/std',
-	'runtime-io/std',
-	'runtime-primitives/std',
-	'srml-support/std',
+	'frame-support/std',
 	'system/std',
-  	'balances/std',
-	'timestamp/std',
+	'sp-arithmetic/std',
+	'sp-runtime/std',
 	'stake/std',
-]
+]

+ 0 - 4
runtime-modules/hiring/src/hiring/opening.rs

@@ -191,8 +191,6 @@ pub enum OpeningStage<BlockNumber, ApplicationId> {
 
         /// Deactivated at any time for any cause.
         deactivated_application_count: u32,
-        // Removed at any time.
-        //removed_application_count: u32
     },
 }
 
@@ -401,6 +399,4 @@ pub enum ActivateOpeningAt<BlockNumber> {
 pub struct ApplicationRationingPolicy {
     /// The maximum number of applications that can be on the list at any time.
     pub max_active_applicants: u32,
-    // How applicants will be ranked, in order to respect the maximum simultaneous application limit
-    //pub applicant_ranking: ApplicationRankingPolicy
 }

+ 27 - 34
runtime-modules/hiring/src/lib.rs

@@ -18,31 +18,25 @@
 // Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
 //#![warn(missing_docs)]
 
-// Test feature dependencies
-#[cfg(all(any(test, feature = "test"), not(target_arch = "wasm32")))]
+// Test dependencies
+#[cfg(all(test, not(target_arch = "wasm32")))]
 use mockall::predicate::*;
-#[cfg(all(any(test, feature = "test"), not(target_arch = "wasm32")))]
+#[cfg(all(test, not(target_arch = "wasm32")))]
 use mockall::*;
 
-use stake::{InitiateUnstakingError, Stake, StakeActionError, StakingError, Trait as StakeTrait};
-
 use codec::Codec;
-
-use runtime_primitives::traits::Zero;
-use runtime_primitives::traits::{MaybeSerialize, Member, One, SimpleArithmetic};
-
-use srml_support::traits::Currency;
-use srml_support::{decl_module, decl_storage, ensure, Parameter};
-
+use frame_support::storage::IterableStorageMap;
+use frame_support::traits::{Currency, Imbalance};
+use frame_support::{decl_module, decl_storage, ensure, Parameter};
+use rstd::cell::RefCell;
 use rstd::collections::btree_map::BTreeMap;
 use rstd::collections::btree_set::BTreeSet;
 use rstd::iter::Iterator;
-use rstd::prelude::*;
-
-use rstd::cell::RefCell;
 use rstd::rc::Rc;
+use sp_arithmetic::traits::{BaseArithmetic, One, Zero};
+use sp_runtime::traits::{MaybeSerialize, Member};
 
-use crate::sr_api_hidden_includes_decl_storage::hidden_include::traits::Imbalance;
+use stake::{InitiateUnstakingError, Stake, StakeActionError, StakingError, Trait as StakeTrait};
 
 mod hiring;
 #[macro_use]
@@ -57,7 +51,7 @@ pub trait Trait: system::Trait + stake::Trait + Sized {
     /// OpeningId type
     type OpeningId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -67,7 +61,7 @@ pub trait Trait: system::Trait + stake::Trait + Sized {
     /// ApplicationId type
     type ApplicationId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -83,21 +77,23 @@ pub trait Trait: system::Trait + stake::Trait + Sized {
 
 decl_storage! {
     trait Store for Module<T: Trait> as Hiring {
-
         /// Openings.
-        pub OpeningById get(opening_by_id): linked_map T::OpeningId => Opening<BalanceOf<T>, T::BlockNumber, T::ApplicationId>;
+        pub OpeningById get(fn opening_by_id): map hasher(blake2_128_concat)
+            T::OpeningId => Opening<BalanceOf<T>, T::BlockNumber, T::ApplicationId>;
 
         /// Identifier for next opening to be added.
-        pub NextOpeningId get(next_opening_id): T::OpeningId;
+        pub NextOpeningId get(fn next_opening_id): T::OpeningId;
 
         /// Applications
-        pub ApplicationById get(application_by_id): linked_map T::ApplicationId => Application<T::OpeningId, T::BlockNumber, T::StakeId>;
+        pub ApplicationById get(fn application_by_id): map hasher(blake2_128_concat)
+            T::ApplicationId => Application<T::OpeningId, T::BlockNumber, T::StakeId>;
 
         /// Identifier for next application to be added.
-        pub NextApplicationId get(next_application_id): T::ApplicationId;
+        pub NextApplicationId get(fn next_application_id): T::ApplicationId;
 
         /// Internal purpose of given stake, i.e. fro what application, and whether for the role or for the application.
-        pub ApplicationIdByStakingId get(stake_purpose_by_staking_id): linked_map T::StakeId => T::ApplicationId;
+        pub ApplicationIdByStakingId get(fn stake_purpose_by_staking_id): map hasher(blake2_128_concat)
+            T::StakeId => T::ApplicationId;
     }
 }
 
@@ -769,14 +765,14 @@ impl<T: Trait> Module<T> {
     /// The stake, with the given id, was unstaked.
     pub fn unstaked(stake_id: T::StakeId) -> UnstakedResult {
         // Ignore unstaked
-        if !<ApplicationIdByStakingId<T>>::exists(stake_id) {
+        if !<ApplicationIdByStakingId<T>>::contains_key(stake_id) {
             return UnstakedResult::StakeIdNonExistent;
         }
 
         // Get application
         let application_id = <ApplicationIdByStakingId<T>>::get(stake_id);
 
-        assert!(<ApplicationById<T>>::exists(application_id));
+        assert!(<ApplicationById<T>>::contains_key(application_id));
 
         let application = <ApplicationById<T>>::get(application_id);
 
@@ -1005,7 +1001,7 @@ impl<T: Trait> Module<T> {
             Opening<BalanceOf<T>, T::BlockNumber, T::ApplicationId>,
         ),
     > {
-        <OpeningById<T>>::enumerate().filter_map(move |(opening_id, opening)| {
+        <OpeningById<T>>::iter().filter_map(move |(opening_id, opening)| {
             if let hiring::OpeningStage::WaitingToBegin { begins_at_block } = opening.stage {
                 if begins_at_block == now {
                     Some((opening_id, opening))
@@ -1028,7 +1024,7 @@ impl<T: Trait> Module<T> {
             (BTreeSet<T::ApplicationId>, T::BlockNumber, T::BlockNumber),
         ),
     > {
-        <OpeningById<T>>::enumerate().filter_map(move |(opening_id, opening)| {
+        <OpeningById<T>>::iter().filter_map(move |(opening_id, opening)| {
             if let hiring::OpeningStage::Active {
                 ref stage,
                 ref applications_added,
@@ -1282,7 +1278,7 @@ impl<T: Trait> Module<T> {
 
         // MUST never already be a key for new stake, false means code is broken.
         // But should we do panic in runtime? Is there safer way?
-        assert!(!<ApplicationIdByStakingId<T>>::exists(new_stake_id));
+        assert!(!<ApplicationIdByStakingId<T>>::contains_key(new_stake_id));
 
         <ApplicationIdByStakingId<T>>::insert(new_stake_id, application_id);
 
@@ -1476,10 +1472,7 @@ impl<T: Trait> Module<T> {
  */
 
 /// Defines stake module interface
-#[cfg_attr(
-    all(any(test, feature = "test"), not(target_arch = "wasm32")),
-    automock
-)]
+#[cfg_attr(all(test, not(target_arch = "wasm32")), automock)]
 pub trait StakeHandler<T: StakeTrait> {
     /// Adds a new Stake which is NotStaked, created at given block, into stakes map.
     fn create_stake(&self) -> T::StakeId;
@@ -1536,7 +1529,7 @@ impl<T: Trait> StakeHandler<T> for HiringStakeHandler {
     }
 
     fn stake_exists(&self, stake_id: T::StakeId) -> bool {
-        <stake::Stakes<T>>::exists(stake_id)
+        <stake::Stakes<T>>::contains_key(stake_id)
     }
 
     fn get_stake(&self, stake_id: T::StakeId) -> Stake<T::BlockNumber, BalanceOf<T>, T::SlashId> {

+ 1 - 1
runtime-modules/hiring/src/macroes.rs

@@ -10,7 +10,7 @@ macro_rules! ensure_eq {
 /// Ensure that a storage map, with a given name, has mapping for the given key value.
 macro_rules! ensure_map_key {
     ($map_variable_name:ident , $runtime_trait:tt, $key:expr, $error:expr) => {{
-        if <$map_variable_name<$runtime_trait>>::exists($key) {
+        if <$map_variable_name<$runtime_trait>>::contains_key($key) {
             let value = <$map_variable_name<$runtime_trait>>::get($key);
 
             Ok(value)

+ 22 - 30
runtime-modules/hiring/src/mock.rs

@@ -1,23 +1,21 @@
 #![cfg(test)]
 
-use primitives::H256;
-use runtime_primitives::{
+use frame_support::{impl_outer_origin, parameter_types};
+use rstd::cell::{Cell, RefCell};
+use rstd::rc::Rc;
+use sp_core::H256;
+use sp_runtime::{
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
-use srml_support::{impl_outer_origin, parameter_types};
+use std::panic;
 
 use crate::hiring::ApplicationDeactivationCause;
 use crate::{Module, Trait};
 use balances;
 use stake;
 
-use std::cell::Cell;
-use std::cell::RefCell;
-use std::panic;
-use std::rc::Rc;
-
 impl_outer_origin! {
     pub enum Origin for Test {}
 }
@@ -27,7 +25,6 @@ parameter_types! {
     pub const MaximumBlockWeight: u32 = 1024;
     pub const MaximumBlockLength: u32 = 2 * 1024;
     pub const AvailableBlockRatio: Perbill = Perbill::one();
-    pub const MinimumPeriod: u64 = 5;
 }
 
 // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
@@ -35,10 +32,11 @@ parameter_types! {
 pub struct Test;
 
 impl system::Trait for Test {
+    type BaseCallFilter = ();
     type Origin = Origin;
+    type Call = ();
     type Index = u64;
     type BlockNumber = u64;
-    type Call = ();
     type Hash = H256;
     type Hashing = BlakeTwo256;
     type AccountId = u64;
@@ -47,45 +45,36 @@ impl system::Trait for Test {
     type Event = ();
     type BlockHashCount = BlockHashCount;
     type MaximumBlockWeight = MaximumBlockWeight;
+    type DbWeight = ();
+    type BlockExecutionWeight = ();
+    type ExtrinsicBaseWeight = ();
+    type MaximumExtrinsicWeight = ();
     type MaximumBlockLength = MaximumBlockLength;
     type AvailableBlockRatio = AvailableBlockRatio;
     type Version = ();
+    type ModuleToIndex = ();
+    type AccountData = balances::AccountData<u64>;
+    type OnNewAccount = ();
+    type OnKilledAccount = ();
 }
 
 parameter_types! {
     pub const ExistentialDeposit: u32 = 100;
-    pub const TransferFee: u32 = 0;
-    pub const CreationFee: u32 = 0;
-    pub const TransactionBaseFee: u32 = 1;
-    pub const TransactionByteFee: u32 = 0;
-    pub const InitialMembersBalance: u64 = 2000;
     pub const StakePoolId: [u8; 8] = *b"joystake";
 }
 
 impl balances::Trait for Test {
-    /// The type for recording an account's balance.
     type Balance = u64;
-    /// What to do if an account's free balance gets zeroed.
-    type OnFreeBalanceZero = ();
-    /// What to do if a new account is created.
-    type OnNewAccount = ();
-    /// The ubiquitous event type.
-    type Event = ();
-
     type DustRemoval = ();
-    type TransferPayment = ();
+    type Event = ();
     type ExistentialDeposit = ExistentialDeposit;
-    type TransferFee = TransferFee;
-    type CreationFee = CreationFee;
+    type AccountStore = System;
 }
 
 impl Trait for Test {
     type OpeningId = u64;
-
     type ApplicationId = u64;
-
     type ApplicationDeactivatedHandler = TestApplicationDeactivatedHandler;
-
     type StakeHandlerProvider = TestStakeHandlerProvider;
 }
 
@@ -149,7 +138,7 @@ pub(crate) fn test_expectation_and_clear_mock() {
     set_stake_handler_impl(Rc::new(RefCell::new(crate::HiringStakeHandler {})));
 }
 
-pub fn build_test_externalities() -> runtime_io::TestExternalities {
+pub fn build_test_externalities() -> sp_io::TestExternalities {
     let t = system::GenesisConfig::default()
         .build_storage::<Test>()
         .unwrap();
@@ -202,3 +191,6 @@ impl TestApplicationDeactivatedHandler {
         );
     }
 }
+
+// Test fixtures starting block.
+pub(crate) static FIRST_BLOCK_HEIGHT: <Test as system::Trait>::BlockNumber = 0;

+ 9 - 5
runtime-modules/hiring/src/test/public_api/add_application.rs

@@ -66,12 +66,16 @@ impl AddApplicationFixture {
             // Check next application id has been updated
             assert_eq!(Hiring::next_application_id(), expected_application_id + 1);
             // Check application exists
-            assert!(<ApplicationById<Test>>::exists(expected_application_id));
+            assert!(<ApplicationById<Test>>::contains_key(
+                expected_application_id
+            ));
         } else {
             // Check next application id has not been updated
             assert_eq!(Hiring::next_application_id(), expected_application_id);
             // Check application does not exist
-            assert!(!<ApplicationById<Test>>::exists(expected_application_id));
+            assert!(!<ApplicationById<Test>>::contains_key(
+                expected_application_id
+            ));
         };
 
         //Check application content
@@ -115,7 +119,7 @@ impl AddApplicationFixture {
             let expected_application = Application {
                 opening_id: self.opening_id,
                 application_index_in_opening: expected_application_index_in_opening,
-                add_to_opening_in_block: 1,
+                add_to_opening_in_block: 0,
                 active_role_staking_id: expected_active_role_staking_id,
                 active_application_staking_id: expected_active_application_staking_id,
                 stage: ApplicationStage::Active,
@@ -166,7 +170,7 @@ impl AddApplicationFixture {
         let expected_opening = Opening {
             stage: OpeningStage::Active {
                 stage: ActiveOpeningStage::AcceptingApplications {
-                    started_accepting_applicants_at_block: 1,
+                    started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
                 },
                 applications_added: expected_added_apps_in_opening,
                 active_application_count: expected_active_application_count,
@@ -289,7 +293,7 @@ fn add_application_succeeds_with_created_application_stake() {
 
         let stake = Hiring::staking().get_stake(application_stake_id);
         let expected_stake = stake::Stake {
-            created: 1,
+            created: FIRST_BLOCK_HEIGHT,
             staking_status: stake::StakingStatus::Staked(stake::StakedState {
                 staked_amount: 100,
                 staked_status: stake::StakedStatus::Normal,

+ 4 - 5
runtime-modules/hiring/src/test/public_api/add_opening.rs

@@ -1,4 +1,4 @@
-use crate::mock::{build_test_externalities, Hiring, Test};
+use crate::mock::{build_test_externalities, Hiring, Test, FIRST_BLOCK_HEIGHT};
 use crate::test::{BlockNumber, OpeningId};
 use crate::StakingAmountLimitMode::Exact;
 use crate::*;
@@ -8,7 +8,6 @@ use crate::{
 };
 use rstd::collections::btree_set::BTreeSet;
 
-static FIRST_BLOCK_HEIGHT: <Test as system::Trait>::BlockNumber = 1;
 pub static HUMAN_READABLE_TEXT: &[u8] = b"HUMAN_READABLE_TEXT!!!!";
 
 pub struct AddOpeningFixture<Balance> {
@@ -44,12 +43,12 @@ impl AddOpeningFixture<OpeningId> {
             // Check next opening id has been updated
             assert_eq!(Hiring::next_opening_id(), expected_opening_id + 1);
             // Check opening exists
-            assert!(<OpeningById<Test>>::exists(expected_opening_id));
+            assert!(<OpeningById<Test>>::contains_key(expected_opening_id));
         } else {
             // Check next opening id has not been updated
             assert_eq!(Hiring::next_opening_id(), expected_opening_id);
             // Check opening does not exist
-            assert!(!<OpeningById<Test>>::exists(expected_opening_id));
+            assert!(!<OpeningById<Test>>::contains_key(expected_opening_id));
         };
 
         //Check opening content
@@ -75,7 +74,7 @@ impl AddOpeningFixture<OpeningId> {
         };
 
         let expected_opening = Opening {
-            created: FIRST_BLOCK_HEIGHT,
+            created: mock::FIRST_BLOCK_HEIGHT,
             stage: expected_opening_stage,
             max_review_period_length: self.max_review_period_length,
             application_rationing_policy: self.application_rationing_policy.clone(),

+ 2 - 2
runtime-modules/hiring/src/test/public_api/begin_accepting_applications.rs

@@ -42,10 +42,10 @@ fn begin_accepting_applications_succeeds() {
         let updated_opening = <OpeningById<Test>>::get(opening_id);
 
         let expected_opening_state = Opening {
-            created: 1,
+            created: FIRST_BLOCK_HEIGHT,
             stage: OpeningStage::Active {
                 stage: ActiveOpeningStage::AcceptingApplications {
-                    started_accepting_applicants_at_block: 1,
+                    started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
                 },
                 applications_added: BTreeSet::new(),
                 active_application_count: 0,

+ 2 - 2
runtime-modules/hiring/src/test/public_api/begin_review.rs

@@ -46,8 +46,8 @@ fn begin_review_succeeds() {
 
         let expected_opening_state =
             old_opening.clone_with_new_active_opening_stage(ActiveOpeningStage::ReviewPeriod {
-                started_accepting_applicants_at_block: 1,
-                started_review_period_at_block: 1,
+                started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
+                started_review_period_at_block: FIRST_BLOCK_HEIGHT,
             });
 
         assert_eq!(updated_opening, expected_opening_state);

+ 2 - 2
runtime-modules/hiring/src/test/public_api/cancel_opening.rs

@@ -96,7 +96,7 @@ impl CancelOpeningFixture {
                         started_accepting_applicants_at_block,
                     } => ActiveOpeningStage::Deactivated {
                         cause: OpeningDeactivationCause::CancelledAcceptingApplications,
-                        deactivated_at_block: 1,
+                        deactivated_at_block: FIRST_BLOCK_HEIGHT,
                         started_accepting_applicants_at_block,
                         started_review_period_at_block: None,
                     },
@@ -105,7 +105,7 @@ impl CancelOpeningFixture {
                         started_review_period_at_block,
                     } => ActiveOpeningStage::Deactivated {
                         cause: OpeningDeactivationCause::CancelledInReviewPeriod,
-                        deactivated_at_block: 1,
+                        deactivated_at_block: FIRST_BLOCK_HEIGHT,
                         started_accepting_applicants_at_block,
                         started_review_period_at_block: Some(started_review_period_at_block),
                     },

+ 5 - 5
runtime-modules/hiring/src/test/public_api/deactivate_application.rs

@@ -67,7 +67,7 @@ impl DeactivateApplicationFixture {
             {
                 Application {
                     stage: ApplicationStage::Unstaking {
-                        deactivation_initiated: 1,
+                        deactivation_initiated: FIRST_BLOCK_HEIGHT,
                         cause: ApplicationDeactivationCause::External,
                     },
                     ..old_application_state
@@ -75,8 +75,8 @@ impl DeactivateApplicationFixture {
             } else {
                 Application {
                     stage: ApplicationStage::Inactive {
-                        deactivation_initiated: 1,
-                        deactivated: 1,
+                        deactivation_initiated: FIRST_BLOCK_HEIGHT,
+                        deactivated: FIRST_BLOCK_HEIGHT,
                         cause: ApplicationDeactivationCause::External,
                     },
                     ..old_application_state
@@ -98,7 +98,7 @@ impl DeactivateApplicationFixture {
         // invalid opening stages are not supported
 
         // check for opening existence
-        if !<OpeningById<Test>>::exists(opening_id) {
+        if !<OpeningById<Test>>::contains_key(opening_id) {
             return;
         }
 
@@ -131,7 +131,7 @@ impl DeactivateApplicationFixture {
                 let expected_opening = Opening {
                     stage: OpeningStage::Active {
                         stage: ActiveOpeningStage::AcceptingApplications {
-                            started_accepting_applicants_at_block: 1,
+                            started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
                         },
                         applications_added,
                         active_application_count: expected_active_application_count,

+ 3 - 3
runtime-modules/hiring/src/test/public_api/ensure_can_add_application.rs

@@ -239,10 +239,10 @@ fn ensure_can_add_application_succeeds() {
             ensure_can_add_application_result,
             Ok(DestructuredApplicationCanBeAddedEvaluation {
                 opening: Opening {
-                    created: 1,
+                    created: FIRST_BLOCK_HEIGHT,
                     stage: hiring::OpeningStage::Active {
                         stage: hiring::ActiveOpeningStage::AcceptingApplications {
-                            started_accepting_applicants_at_block: 1
+                            started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT
                         },
                         applications_added: BTreeSet::new(),
                         active_application_count: 0,
@@ -266,7 +266,7 @@ fn ensure_can_add_application_succeeds() {
                     human_readable_text: HUMAN_READABLE_TEXT.to_vec()
                 },
                 active_stage: hiring::ActiveOpeningStage::AcceptingApplications {
-                    started_accepting_applicants_at_block: 1
+                    started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT
                 },
                 applications_added: BTreeSet::new(),
                 active_application_count: 0,

+ 3 - 3
runtime-modules/hiring/src/test/public_api/fill_opening.rs

@@ -89,9 +89,9 @@ impl FillOpeningFixture {
                 // compose expected stage
                 let expected_active_stage = ActiveOpeningStage::Deactivated {
                     cause: OpeningDeactivationCause::Filled,
-                    deactivated_at_block: 1,
-                    started_accepting_applicants_at_block: 1,
-                    started_review_period_at_block: Some(1),
+                    deactivated_at_block: FIRST_BLOCK_HEIGHT,
+                    started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
+                    started_review_period_at_block: Some(FIRST_BLOCK_HEIGHT),
                 };
 
                 // calculate application counters

+ 1 - 1
runtime-modules/hiring/src/test/public_api/on_finalize.rs

@@ -1,7 +1,7 @@
 use crate::mock::*;
 use crate::test::*;
 
-use runtime_primitives::traits::{OnFinalize, OnInitialize};
+use frame_support::traits::{OnFinalize, OnInitialize};
 
 // Recommendation from Parity on testing on_finalize
 // https://substrate.dev/docs/en/next/development/module/tests

+ 1 - 1
runtime-modules/hiring/src/test/public_api/unstaked.rs

@@ -62,7 +62,7 @@ impl UnstakedFixture {
                 {
                     let expected_application_stage = ApplicationStage::Inactive {
                         deactivation_initiated,
-                        deactivated: 1,
+                        deactivated: FIRST_BLOCK_HEIGHT,
                         cause,
                     };
 

+ 16 - 18
runtime-modules/hiring/src/test/smoke.rs

@@ -1,8 +1,6 @@
 use super::*;
 use crate::mock::*;
 
-static FIRST_BLOCK_HEIGHT: <Test as system::Trait>::BlockNumber = 1;
-
 use rstd::collections::btree_set::BTreeSet;
 
 /**
@@ -52,7 +50,7 @@ fn full_hiring_workflow_successful_path() {
         assert_eq!(Hiring::next_opening_id(), expected_opening_id + 1);
 
         // Check that our opening actually was added
-        assert!(<OpeningById<Test>>::exists(expected_opening_id));
+        assert!(<OpeningById<Test>>::contains_key(expected_opening_id));
 
         let found_opening = Hiring::opening_by_id(expected_opening_id);
 
@@ -90,10 +88,10 @@ fn full_hiring_workflow_successful_path() {
         let destructured_app_data = ensure_can_add_application_result.unwrap();
         let expected = DestructuredApplicationCanBeAddedEvaluation {
             opening: Opening {
-                created: 1,
+                created: FIRST_BLOCK_HEIGHT,
                 stage: OpeningStage::Active {
                     stage: ActiveOpeningStage::AcceptingApplications {
-                        started_accepting_applicants_at_block: 1,
+                        started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
                     },
                     applications_added: BTreeSet::new(),
                     active_application_count: 0,
@@ -107,7 +105,7 @@ fn full_hiring_workflow_successful_path() {
                 human_readable_text: human_readable_text.clone(),
             },
             active_stage: ActiveOpeningStage::AcceptingApplications {
-                started_accepting_applicants_at_block: 1,
+                started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
             },
             applications_added: BTreeSet::new(),
             active_application_count: 0,
@@ -136,7 +134,7 @@ fn full_hiring_workflow_successful_path() {
         let new_application_id = app_added.application_id_added;
 
         // Check that our application actually was added
-        assert!(<ApplicationById<Test>>::exists(new_application_id));
+        assert!(<ApplicationById<Test>>::contains_key(new_application_id));
 
         let new_application = Hiring::application_by_id(new_application_id);
 
@@ -146,7 +144,7 @@ fn full_hiring_workflow_successful_path() {
             Application {
                 opening_id: 0,
                 application_index_in_opening: 0,
-                add_to_opening_in_block: 1,
+                add_to_opening_in_block: FIRST_BLOCK_HEIGHT,
                 active_role_staking_id: None,
                 active_application_staking_id: None,
                 stage: ApplicationStage::Active,
@@ -169,11 +167,11 @@ fn full_hiring_workflow_successful_path() {
         assert_eq!(
             updated_opening_after_begin_review,
             Opening {
-                created: 1,
+                created: FIRST_BLOCK_HEIGHT,
                 stage: OpeningStage::Active {
                     stage: ActiveOpeningStage::ReviewPeriod {
-                        started_accepting_applicants_at_block: 1,
-                        started_review_period_at_block: 1
+                        started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
+                        started_review_period_at_block: FIRST_BLOCK_HEIGHT
                     },
                     applications_added: expected_added_apps_in_opening.clone(),
                     active_application_count: 1,
@@ -204,13 +202,13 @@ fn full_hiring_workflow_successful_path() {
         assert_eq!(
             updated_opening_fill_opening,
             Opening {
-                created: 1,
+                created: FIRST_BLOCK_HEIGHT,
                 stage: OpeningStage::Active {
                     stage: ActiveOpeningStage::Deactivated {
                         cause: OpeningDeactivationCause::Filled,
-                        deactivated_at_block: 1,
-                        started_accepting_applicants_at_block: 1,
-                        started_review_period_at_block: Some(1)
+                        deactivated_at_block: FIRST_BLOCK_HEIGHT,
+                        started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
+                        started_review_period_at_block: Some(FIRST_BLOCK_HEIGHT)
                     },
                     applications_added: expected_added_apps_in_opening,
                     active_application_count: 0,
@@ -234,12 +232,12 @@ fn full_hiring_workflow_successful_path() {
             Application {
                 opening_id: 0,
                 application_index_in_opening: 0,
-                add_to_opening_in_block: 1,
+                add_to_opening_in_block: FIRST_BLOCK_HEIGHT,
                 active_role_staking_id: None,
                 active_application_staking_id: None,
                 stage: ApplicationStage::Inactive {
-                    deactivation_initiated: 1,
-                    deactivated: 1,
+                    deactivation_initiated: FIRST_BLOCK_HEIGHT,
+                    deactivated: FIRST_BLOCK_HEIGHT,
                     cause: ApplicationDeactivationCause::Hired
                 },
                 human_readable_text: application_readable_text.clone()

+ 5 - 5
runtime-modules/hiring/src/test/staking_module/try_to_initiate_application_deactivation.rs

@@ -56,15 +56,15 @@ impl<'a> TryToInitiateApplicationDeactivationFixture<'a> {
         let expected_application_state = match result {
             ApplicationDeactivationInitiationResult::Deactivated => Application {
                 stage: ApplicationStage::Inactive {
-                    deactivation_initiated: 1,
-                    deactivated: 1,
+                    deactivation_initiated: FIRST_BLOCK_HEIGHT,
+                    deactivated: FIRST_BLOCK_HEIGHT,
                     cause: self.cause,
                 },
                 ..old_application_state
             },
             ApplicationDeactivationInitiationResult::Unstaking => Application {
                 stage: ApplicationStage::Unstaking {
-                    deactivation_initiated: 1,
+                    deactivation_initiated: FIRST_BLOCK_HEIGHT,
                     cause: self.cause,
                 },
                 ..old_application_state
@@ -84,7 +84,7 @@ impl<'a> TryToInitiateApplicationDeactivationFixture<'a> {
         // invalid opening stages are not supported
 
         // check for opening existence
-        if !<OpeningById<Test>>::exists(opening_id) {
+        if !<OpeningById<Test>>::contains_key(opening_id) {
             return;
         }
 
@@ -118,7 +118,7 @@ impl<'a> TryToInitiateApplicationDeactivationFixture<'a> {
                 let expected_opening = Opening {
                     stage: OpeningStage::Active {
                         stage: ActiveOpeningStage::AcceptingApplications {
-                            started_accepting_applicants_at_block: 1,
+                            started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
                         },
                         applications_added,
                         active_application_count: expected_active_application_count,

+ 0 - 1
runtime-modules/stake/src/mock.rs

@@ -23,7 +23,6 @@ parameter_types! {
     pub const MaximumBlockWeight: u32 = 1024;
     pub const MaximumBlockLength: u32 = 2 * 1024;
     pub const AvailableBlockRatio: Perbill = Perbill::one();
-    pub const MinimumPeriod: u64 = 5;
 }
 
 impl system::Trait for Test {