Parcourir la source

Merge pull request #1587 from conectado/working_team_pallet

Benchmarking working_team
shamil-gadelshin il y a 4 ans
Parent
commit
c1b1c2b532

+ 5 - 4
.travis.yml

@@ -24,20 +24,21 @@ before_install:
     fi
 
 install:
+  - rustup install nightly-2020-07-12 --force
   - rustup install nightly-2020-05-23 --force
   - rustup target add wasm32-unknown-unknown --toolchain nightly-2020-05-23
   # travis installs rust using rustup with the "minimal" profile so these tools are not installed by default
   - rustup component add rustfmt
-  - rustup component add clippy
+  - rustup component add clippy --toolchain nightly-2020-07-12
 
 before_script:
   - cargo fmt --all -- --check
 
 script:
   - export WASM_BUILD_TOOLCHAIN=nightly-2020-05-23
-  - BUILD_DUMMY_WASM_BINARY=1 cargo clippy --release --all -- -D warnings
-  - travis_wait 75 cargo test --release --verbose --all -- --ignored
-  - cargo build --release
+  - BUILD_DUMMY_WASM_BINARY=1 cargo +nightly-2020-07-12 clippy --release --all -- -D warnings
+  - travis_wait 75 cargo +nightly-2020-07-12 test --release --verbose --all -- --ignored
+  - cargo +nightly-2020-07-12 build --release
   - ls -l ./target/release/wbuild/joystream-node-runtime/
   - ./target/release/joystream-node --version
   - ./target/release/chain-spec-builder --version

+ 11 - 3
Cargo.lock

@@ -1690,6 +1690,12 @@ dependencies = [
  "proc-macro-hack",
 ]
 
+[[package]]
+name = "hex-literal"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5af1f635ef1bc545d78392b136bfe1c9809e029023c84a3638a864a10b8819c8"
+
 [[package]]
 name = "hex-literal-impl"
 version = "0.2.2"
@@ -2061,6 +2067,7 @@ dependencies = [
  "frame-system",
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
+ "hex-literal 0.3.1",
  "pallet-authority-discovery",
  "pallet-authorship",
  "pallet-babe",
@@ -3885,8 +3892,9 @@ dependencies = [
 
 [[package]]
 name = "pallet-working-team"
-version = "1.0.0"
+version = "1.0.1"
 dependencies = [
+ "frame-benchmarking",
  "frame-support",
  "frame-system",
  "pallet-balances",
@@ -5048,7 +5056,7 @@ dependencies = [
  "fnv",
  "futures 0.3.4",
  "hash-db",
- "hex-literal",
+ "hex-literal 0.2.1",
  "kvdb",
  "lazy_static",
  "log",
@@ -5658,7 +5666,7 @@ dependencies = [
  "fdlimit",
  "futures 0.1.29",
  "futures 0.3.4",
- "hex-literal",
+ "hex-literal 0.2.1",
  "log",
  "parity-scale-codec",
  "parking_lot 0.10.2",

+ 3 - 2
runtime-modules/working-team/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pallet-working-team"
-version = "1.0.0"
+version = "1.0.1"
 authors = ['Joystream contributors']
 edition = '2018'
 
@@ -15,7 +15,7 @@ sp-std = { package = 'sp-std', default-features = false, git = 'https://github.c
 common = { package = 'pallet-common', default-features = false, path = '../common'}
 membership = { package = 'pallet-membership', default-features = false, path = '../membership'}
 balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
-
+frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4', optional = true}
 
 [dev-dependencies]
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
@@ -24,6 +24,7 @@ pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git
 
 [features]
 default = ['std']
+runtime-benchmarks = ["frame-benchmarking"]
 std = [
 	'serde',
 	'codec/std',

+ 1126 - 0
runtime-modules/working-team/src/benchmarking.rs

@@ -0,0 +1,1126 @@
+#![cfg(feature = "runtime-benchmarks")]
+use super::*;
+use core::convert::TryInto;
+use frame_benchmarking::{account, benchmarks_instance, Zero};
+use frame_support::traits::OnInitialize;
+use sp_runtime::traits::Bounded;
+use sp_std::cmp::min;
+use sp_std::prelude::*;
+use system as frame_system;
+use system::EventRecord;
+use system::Module as System;
+use system::RawOrigin;
+
+use crate::types::StakeParameters;
+use crate::Module as WorkingTeam;
+use membership::Module as Membership;
+
+const SEED: u32 = 0;
+const MAX_BYTES: u32 = 16384;
+
+enum StakingRole {
+    WithStakes,
+    WithoutStakes,
+}
+
+fn assert_last_event<T: Trait<I>, I: Instance>(generic_event: <T as Trait<I>>::Event) {
+    let events = System::<T>::events();
+    let system_event: <T as frame_system::Trait>::Event = generic_event.into();
+    // compare to the last event record
+    let EventRecord { event, .. } = &events[events.len() - 1];
+    assert_eq!(event, &system_event);
+}
+
+fn get_byte(num: u32, byte_number: u8) -> u8 {
+    ((num & (0xff << (8 * byte_number))) >> 8 * byte_number) as u8
+}
+
+fn add_opening_helper<T: Trait<I>, I: Instance>(
+    id: u32,
+    add_opening_origin: &T::Origin,
+    staking_role: &StakingRole,
+    job_opening_type: &JobOpeningType,
+) -> T::OpeningId {
+    let staking_policy = match staking_role {
+        StakingRole::WithStakes => Some(StakePolicy {
+            stake_amount: One::one(),
+            leaving_unstaking_period: T::MinUnstakingPeriodLimit::get() + One::one(),
+        }),
+        StakingRole::WithoutStakes => None,
+    };
+
+    WorkingTeam::<T, _>::add_opening(
+        add_opening_origin.clone(),
+        vec![],
+        *job_opening_type,
+        staking_policy,
+        Some(RewardPolicy {
+            reward_per_block: One::one(),
+        }),
+    )
+    .unwrap();
+
+    let opening_id = T::OpeningId::from(id.try_into().unwrap());
+
+    assert!(
+        OpeningById::<T, I>::contains_key(opening_id),
+        "Opening not added"
+    );
+
+    opening_id
+}
+
+fn apply_on_opening_helper<T: Trait<I>, I: Instance>(
+    id: u32,
+    staking_role: &StakingRole,
+    applicant_id: &T::AccountId,
+    member_id: &T::MemberId,
+    opening_id: &T::OpeningId,
+) -> T::ApplicationId {
+    let stake_parameters = match staking_role {
+        StakingRole::WithStakes => Some(StakeParameters {
+            // Due to mock implementation of StakingHandler we can't go over 1000
+            stake: min(
+                BalanceOfCurrency::<T>::max_value(),
+                BalanceOfCurrency::<T>::from(1000),
+            ),
+            staking_account_id: applicant_id.clone(),
+        }),
+        StakingRole::WithoutStakes => None,
+    };
+
+    WorkingTeam::<T, _>::apply_on_opening(
+        RawOrigin::Signed(applicant_id.clone()).into(),
+        ApplyOnOpeningParameters::<T, I> {
+            member_id: *member_id,
+            opening_id: *opening_id,
+            role_account_id: applicant_id.clone(),
+            reward_account_id: applicant_id.clone(),
+            description: vec![],
+            stake_parameters,
+        },
+    )
+    .unwrap();
+
+    let application_id = T::ApplicationId::from(id.try_into().unwrap());
+
+    assert!(
+        ApplicationById::<T, I>::contains_key(application_id),
+        "Application not added"
+    );
+
+    application_id
+}
+
+fn add_opening_and_apply_with_multiple_ids<T: Trait<I>, I: Instance>(
+    ids: &Vec<u32>,
+    add_opening_origin: &T::Origin,
+    staking_role: &StakingRole,
+    job_opening_type: &JobOpeningType,
+) -> (T::OpeningId, BTreeSet<T::ApplicationId>, Vec<T::AccountId>) {
+    let opening_id =
+        add_opening_helper::<T, I>(1, add_opening_origin, &staking_role, job_opening_type);
+
+    let mut successful_application_ids = BTreeSet::new();
+
+    let mut account_ids = Vec::new();
+    for id in ids.iter() {
+        let (applicant_account_id, applicant_member_id) = member_funded_account::<T>("member", *id);
+        let application_id = apply_on_opening_helper::<T, I>(
+            *id,
+            &staking_role,
+            &applicant_account_id,
+            &applicant_member_id,
+            &opening_id,
+        );
+
+        successful_application_ids.insert(application_id);
+        account_ids.push(applicant_account_id);
+    }
+
+    (opening_id, successful_application_ids, account_ids)
+}
+
+fn add_and_apply_opening<T: Trait<I>, I: Instance>(
+    id: u32,
+    add_opening_origin: &T::Origin,
+    staking_role: &StakingRole,
+    applicant_id: &T::AccountId,
+    member_id: &T::MemberId,
+    job_opening_type: &JobOpeningType,
+) -> (T::OpeningId, T::ApplicationId) {
+    let opening_id =
+        add_opening_helper::<T, I>(id, add_opening_origin, staking_role, job_opening_type);
+
+    let application_id =
+        apply_on_opening_helper::<T, I>(id, staking_role, applicant_id, member_id, &opening_id);
+
+    (opening_id, application_id)
+}
+
+// Method to generate a distintic valid handle
+// for a membership. For each index.
+fn handle_from_id<T: membership::Trait>(id: u32) -> Vec<u8> {
+    let min_handle_length = Membership::<T>::min_handle_length();
+
+    let mut handle = vec![];
+
+    for i in 0..min(Membership::<T>::max_handle_length().try_into().unwrap(), 4) {
+        handle.push(get_byte(id, i));
+    }
+
+    while handle.len() < (min_handle_length as usize) {
+        handle.push(0u8);
+    }
+
+    handle
+}
+
+fn member_funded_account<T: membership::Trait>(
+    name: &'static str,
+    id: u32,
+) -> (T::AccountId, T::MemberId) {
+    let account_id = account::<T::AccountId>(name, id, SEED);
+    let handle = handle_from_id::<T>(id);
+
+    let _ = <T as common::currency::GovernanceCurrency>::Currency::make_free_balance_be(
+        &account_id,
+        BalanceOfCurrency::<T>::max_value(),
+    );
+
+    let authority_account = account::<T::AccountId>(name, 0, SEED);
+
+    Membership::<T>::set_screening_authority(RawOrigin::Root.into(), authority_account.clone())
+        .unwrap();
+
+    Membership::<T>::add_screened_member(
+        RawOrigin::Signed(authority_account.clone()).into(),
+        account_id.clone(),
+        Some(handle),
+        None,
+        None,
+    )
+    .unwrap();
+
+    (account_id, T::MemberId::from(id.try_into().unwrap()))
+}
+
+fn force_missed_reward<T: Trait<I>, I: Instance>() {
+    let curr_block_number =
+        System::<T>::block_number().saturating_add(T::RewardPeriod::get().into());
+    System::<T>::set_block_number(curr_block_number);
+    WorkingTeam::<T, _>::set_budget(RawOrigin::Root.into(), Zero::zero()).unwrap();
+    WorkingTeam::<T, _>::on_initialize(curr_block_number);
+}
+
+fn insert_a_worker<T: Trait<I>, I: Instance>(
+    staking_role: StakingRole,
+    job_opening_type: JobOpeningType,
+    id: u32,
+    lead_id: Option<T::AccountId>,
+) -> (T::AccountId, TeamWorkerId<T>)
+where
+    WorkingTeam<T, I>: OnInitialize<T::BlockNumber>,
+{
+    let add_worker_origin = match job_opening_type {
+        JobOpeningType::Leader => RawOrigin::Root,
+        JobOpeningType::Regular => RawOrigin::Signed(lead_id.clone().unwrap()),
+    };
+
+    let (caller_id, member_id) = member_funded_account::<T>("member", id);
+
+    let (opening_id, application_id) = add_and_apply_opening::<T, I>(
+        id,
+        &T::Origin::from(add_worker_origin.clone()),
+        &staking_role,
+        &caller_id,
+        &member_id,
+        &job_opening_type,
+    );
+
+    let mut successful_application_ids = BTreeSet::<T::ApplicationId>::new();
+    successful_application_ids.insert(application_id);
+    WorkingTeam::<T, _>::fill_opening(
+        add_worker_origin.clone().into(),
+        opening_id,
+        successful_application_ids,
+    )
+    .unwrap();
+
+    // Every worst case either include or doesn't mind having a non-zero
+    // remaining reward
+    force_missed_reward::<T, I>();
+
+    let worker_id = TeamWorkerId::<T>::from(id.try_into().unwrap());
+
+    assert!(WorkerById::<T, I>::contains_key(worker_id));
+
+    (caller_id, worker_id)
+}
+
+benchmarks_instance! {
+    _ { }
+
+    on_initialize_leaving {
+        let i in 1 .. T::MaxWorkerNumberLimit::get();
+
+        let (lead_id, lead_worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+
+        let (opening_id, successful_application_ids, application_account_id) =
+            add_opening_and_apply_with_multiple_ids::<T, I>(
+                &(1..i).collect(),
+                &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
+                &StakingRole::WithStakes,
+                &JobOpeningType::Regular
+            );
+
+        WorkingTeam::<T, _>::fill_opening(
+            RawOrigin::Signed(lead_id.clone()).into(),
+            opening_id,
+            successful_application_ids.clone()
+        ).unwrap();
+
+        force_missed_reward::<T,I>();
+
+        // Force all workers to leave (Including the lead)
+        // We should have every TeamWorkerId from 0 to i-1
+        // Corresponding to each account id
+        let mut worker_id = Zero::zero();
+        for id in application_account_id {
+            worker_id += One::one();
+            WorkingTeam::<T, _>::leave_role(RawOrigin::Signed(id).into(), worker_id).unwrap();
+        }
+
+        // Worst case scenario one of the leaving workers is the lead
+        WorkingTeam::<T, _>::leave_role(
+            RawOrigin::Signed(lead_id).into(),
+            lead_worker_id
+        ).unwrap();
+
+        for i in 1..successful_application_ids.len() {
+            let worker = TeamWorkerId::<T>::from(i.try_into().unwrap());
+            assert!(WorkerById::<T, I>::contains_key(worker), "Not all workers added");
+            assert_eq!(
+                WorkingTeam::<T, _>::worker_by_id(worker).started_leaving_at,
+                Some(System::<T>::block_number()),
+                "Worker hasn't started leaving"
+            );
+        }
+
+        // Maintain consistency with add_opening_helper
+        let leaving_unstaking_period = T::MinUnstakingPeriodLimit::get() + One::one();
+
+        // Force unstaking period to have passed
+        let curr_block_number =
+            System::<T>::block_number().saturating_add(leaving_unstaking_period.into());
+        System::<T>::set_block_number(curr_block_number);
+        WorkingTeam::<T, _>::set_budget(
+            RawOrigin::Root.into(),
+            BalanceOfCurrency::<T>::max_value()
+        ).unwrap();
+
+        assert_eq!(WorkingTeam::<T, _>::budget(), BalanceOfCurrency::<T>::max_value());
+    }: { WorkingTeam::<T, _>::on_initialize(curr_block_number) }
+    verify {
+        WorkerById::<T, I>::iter().for_each(|(worker_id, _)| {
+            assert!(!WorkerById::<T, I>::contains_key(worker_id), "Worker hasn't left");
+        });
+
+        let reward_per_worker = BalanceOfCurrency::<T>::from(T::RewardPeriod::get());
+
+        assert_eq!(
+            WorkingTeam::<T, I>::budget(),
+            BalanceOfCurrency::<T>::max_value()
+                .saturating_sub(BalanceOfCurrency::<T>::from(i) * reward_per_worker)
+                .saturating_sub(reward_per_worker),
+            "Budget wasn't correctly updated, probably not all workers rewarded"
+        );
+    }
+
+
+    on_initialize_rewarding_with_missing_reward {
+        let i in 1 .. T::MaxWorkerNumberLimit::get();
+
+        let (lead_id, _) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+
+        let (opening_id, successful_application_ids, _) =
+            add_opening_and_apply_with_multiple_ids::<T, I>(
+                &(1..i).collect(),
+                &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
+                &StakingRole::WithStakes,
+                &JobOpeningType::Regular
+            );
+
+        WorkingTeam::<T, _>::fill_opening(RawOrigin::Signed(lead_id.clone()).into(), opening_id,
+        successful_application_ids.clone()).unwrap();
+
+        for i in 1..successful_application_ids.len() {
+            assert!(
+                WorkerById::<T, I>::contains_key(TeamWorkerId::<T>::from(i.try_into().unwrap())),
+                "Not all workers added"
+            );
+        }
+
+        // Worst case scenario there is a missing reward
+        force_missed_reward::<T, I>();
+
+        // Sets periods so that we can reward
+        let curr_block_number =
+            System::<T>::block_number().saturating_add(T::RewardPeriod::get().into());
+        System::<T>::set_block_number(curr_block_number);
+
+        // Sets budget so that we can pay it
+        WorkingTeam::<T, _>::set_budget(
+            RawOrigin::Root.into(),
+            BalanceOfCurrency::<T>::max_value()
+        ).unwrap();
+
+        assert_eq!(WorkingTeam::<T, _>::budget(), BalanceOfCurrency::<T>::max_value());
+    }: { WorkingTeam::<T, _>::on_initialize(curr_block_number) }
+    verify {
+        let reward_per_worker = BalanceOfCurrency::<T>::from(T::RewardPeriod::get());
+
+        let reward_for_workers =
+            BalanceOfCurrency::<T>::from(i) * reward_per_worker * BalanceOfCurrency::<T>::from(2);
+
+        assert_eq!(
+            WorkingTeam::<T, _>::budget(),
+            // When creating a worker using `insert_a_worker` it gives the lead a number of block
+            // equating to reward period as missed reward(and the reward value is 1) therefore the
+            // additional discount of balance
+            BalanceOfCurrency::<T>::max_value()
+                .saturating_sub(reward_for_workers)
+                .saturating_sub(reward_per_worker),
+            "Budget wasn't correctly updated, probably not all workers rewarded"
+        );
+    }
+
+    on_initialize_rewarding_with_missing_reward_cant_pay {
+        let i in 1 .. T::MaxWorkerNumberLimit::get();
+
+        let (lead_id, _) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+
+        let (opening_id, successful_application_ids, _) =
+            add_opening_and_apply_with_multiple_ids::<T, I>(
+                &(1..i).collect(),
+                &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
+                &StakingRole::WithStakes,
+                &JobOpeningType::Regular
+            );
+
+        WorkingTeam::<T, _>::fill_opening(RawOrigin::Signed(lead_id.clone()).into(), opening_id,
+        successful_application_ids.clone()).unwrap();
+
+        for i in 1..successful_application_ids.len() {
+            assert!(
+                WorkerById::<T, I>::contains_key(TeamWorkerId::<T>::from(i.try_into().unwrap())),
+                "Not all workers added"
+            );
+        }
+
+        // Sets periods so that we can reward
+        let curr_block_number =
+            System::<T>::block_number().saturating_add(T::RewardPeriod::get().into());
+
+        System::<T>::set_block_number(curr_block_number);
+
+        // Sets budget so that we can't pay it
+        WorkingTeam::<T, _>::set_budget(RawOrigin::Root.into(), Zero::zero()).unwrap();
+
+        assert_eq!(WorkingTeam::<T, _>::budget(), Zero::zero());
+
+    }: { WorkingTeam::<T, _>::on_initialize(curr_block_number) }
+    verify {
+        WorkerById::<T, I>::iter().for_each(|(_, worker)| {
+            let missed_reward = worker.missed_reward.expect("There should be some missed reward");
+
+            assert!(
+                missed_reward >= BalanceOfCurrency::<T>::from(T::RewardPeriod::get()),
+                "At least one worker wasn't rewarded"
+            );
+        });
+    }
+
+    on_initialize_rewarding_without_missing_reward {
+        let i in 1 .. T::MaxWorkerNumberLimit::get();
+
+        let (lead_id, _) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+
+        let (opening_id, successful_application_ids, _) =
+            add_opening_and_apply_with_multiple_ids::<T, I>(
+                &(1..i).collect(),
+                &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
+                &StakingRole::WithStakes,
+                &JobOpeningType::Regular
+            );
+
+        WorkingTeam::<T, _>::fill_opening(RawOrigin::Signed(lead_id.clone()).into(), opening_id,
+        successful_application_ids.clone()).unwrap();
+
+        for i in 1..successful_application_ids.len() {
+            assert!(
+                WorkerById::<T, I>::contains_key(TeamWorkerId::<T>::from(i.try_into().unwrap())),
+                "Not all workers added"
+            );
+        }
+
+        // Sets periods so that we can reward
+        let curr_block_number =
+            System::<T>::block_number().saturating_add(T::RewardPeriod::get().into());
+        System::<T>::set_block_number(curr_block_number);
+
+        // Sets budget so that we can pay it
+        WorkingTeam::<T, _>::set_budget(
+            RawOrigin::Root.into(), BalanceOfCurrency::<T>::max_value()
+        ).unwrap();
+        assert_eq!(WorkingTeam::<T, _>::budget(), BalanceOfCurrency::<T>::max_value());
+
+    }: { WorkingTeam::<T, _>::on_initialize(curr_block_number) }
+    verify {
+        let reward_per_worker = BalanceOfCurrency::<T>::from(T::RewardPeriod::get());
+        let workers_total_reward = BalanceOfCurrency::<T>::from(i) * reward_per_worker;
+        assert_eq!(
+            WorkingTeam::<T, _>::budget(),
+            // When creating a worker using `insert_a_worker` it gives the lead a number of block
+            // equating to reward period as missed reward(and the reward value is 1) therefore the
+            // additional discount of balance
+            BalanceOfCurrency::<T>::max_value()
+                .saturating_sub(workers_total_reward)
+                .saturating_sub(reward_per_worker),
+            "Budget wasn't correctly updated, probably not all workers rewarded"
+        );
+    }
+
+    apply_on_opening {
+        let i in 1 .. MAX_BYTES;
+
+        let (lead_account_id, lead_member_id) = member_funded_account::<T>("lead", 0);
+        let opening_id = add_opening_helper::<T, I>(
+            0,
+            &T::Origin::from(RawOrigin::Root),
+            &StakingRole::WithStakes,
+            &JobOpeningType::Leader
+        );
+
+        let apply_on_opening_params = ApplyOnOpeningParameters::<T, I> {
+            member_id: lead_member_id,
+            opening_id: opening_id.clone(),
+            role_account_id: lead_account_id.clone(),
+            reward_account_id: lead_account_id.clone(),
+            description: vec![0u8; i.try_into().unwrap()],
+            stake_parameters: Some(
+                // Make sure to keep consistency with the StakePolicy in add_opening_helper
+                // (we are safe as long as we are using max_value for stake)
+                StakeParameters {
+                    stake: One::one(),
+                    staking_account_id: lead_account_id.clone(),
+                }
+            ),
+        };
+
+    }: _ (RawOrigin::Signed(lead_account_id.clone()), apply_on_opening_params)
+    verify {
+        assert!(
+            ApplicationById::<T, I>::contains_key(T::ApplicationId::from(0)),
+            "Application not found"
+        );
+
+        assert_last_event::<T, I>(RawEvent::AppliedOnOpening(opening_id, Zero::zero()).into());
+    }
+
+    fill_opening_lead {
+        let i in 0 .. 1;
+
+        let (lead_account_id, lead_member_id) = member_funded_account::<T>("lead", 0);
+        let (opening_id, application_id) = add_and_apply_opening::<T, I>(
+            0,
+            &RawOrigin::Root.into(),
+            &StakingRole::WithoutStakes,
+            &lead_account_id,
+            &lead_member_id,
+            &JobOpeningType::Leader
+        );
+
+        let mut successful_application_ids: BTreeSet<T::ApplicationId> = BTreeSet::new();
+        successful_application_ids.insert(application_id);
+    }: fill_opening(RawOrigin::Root, opening_id, successful_application_ids)
+    verify {
+        assert!(!OpeningById::<T, I>::contains_key(opening_id), "Opening still not filled");
+
+        let worker_id = Zero::zero();
+
+        assert_eq!(
+            WorkingTeam::<T, I>::current_lead(),
+            Some(worker_id),
+            "Opening for lead not filled"
+        );
+
+        let mut application_id_to_worker_id = BTreeMap::new();
+        application_id_to_worker_id.insert(application_id, worker_id);
+
+        assert_last_event::<T, I>(
+            RawEvent::OpeningFilled(opening_id, application_id_to_worker_id).into()
+        );
+    }
+
+    fill_opening_worker {
+        let i in 1 .. T::MaxWorkerNumberLimit::get();
+        let (lead_id, lead_worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithoutStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+
+        let (opening_id, successful_application_ids, _) =
+            add_opening_and_apply_with_multiple_ids::<T, I>(
+                &(1..i).collect(),
+                &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
+                &StakingRole::WithoutStakes,
+                &JobOpeningType::Regular
+            );
+    }: fill_opening(
+            RawOrigin::Signed(lead_id.clone()),
+            opening_id,
+            successful_application_ids.clone()
+        )
+    verify {
+        assert!(!OpeningById::<T, I>::contains_key(opening_id), "Opening still not filled");
+
+        let mut application_id_to_worker_id = BTreeMap::new();
+        for (i, application_id) in successful_application_ids.iter().enumerate() {
+            let worker_id = TeamWorkerId::<T>::from((i + 1).try_into().unwrap());
+            application_id_to_worker_id.insert(*application_id, worker_id);
+            assert!(
+                WorkerById::<T, I>::contains_key(TeamWorkerId::<T>::from(i.try_into().unwrap())),
+                "Not all workers added"
+            );
+        }
+
+        assert_last_event::<T, I>(
+            RawEvent::OpeningFilled(opening_id, application_id_to_worker_id).into()
+        );
+    }
+
+    update_role_account{
+        let i in 0 .. 1;
+        let (lead_id, lead_worker_id) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let new_account_id = account::<T::AccountId>("new_lead_account", 1, SEED);
+    }: _ (RawOrigin::Signed(lead_id), lead_worker_id, new_account_id.clone())
+    verify {
+        assert_eq!(
+            WorkingTeam::<T, I>::worker_by_id(lead_worker_id).role_account_id,
+            new_account_id,
+            "Role account notupdated"
+        );
+
+        assert_last_event::<T, I>(
+            RawEvent::WorkerRoleAccountUpdated(lead_worker_id, new_account_id).into()
+        );
+    }
+
+    cancel_opening {
+        let i in 0 .. 1;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let opening_id = add_opening_helper::<T, I>(
+            1,
+            &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
+            &StakingRole::WithoutStakes,
+            &JobOpeningType::Regular
+        );
+
+    }: _ (RawOrigin::Signed(lead_id.clone()), opening_id)
+    verify {
+        assert!(!OpeningById::<T, I>::contains_key(opening_id), "Opening not removed");
+        assert_last_event::<T, I>(RawEvent::OpeningCanceled(opening_id).into());
+    }
+
+    withdraw_application {
+        let i in 0 .. 1;
+
+        let (caller_id, member_id) = member_funded_account::<T>("lead", 0);
+        let (_, application_id) = add_and_apply_opening::<T, I>(0,
+            &RawOrigin::Root.into(),
+            &StakingRole::WithStakes,
+            &caller_id,
+            &member_id,
+            &JobOpeningType::Leader
+        );
+
+    }: _ (RawOrigin::Signed(caller_id.clone()), application_id)
+    verify {
+        assert!(!ApplicationById::<T, I>::contains_key(application_id), "Application not removed");
+        assert_last_event::<T, I>(RawEvent::ApplicationWithdrawn(application_id).into());
+    }
+
+    // Regular worker is the worst case scenario since the checks
+    // require access to the storage whilist that's not the case with a lead opening
+    slash_stake {
+        let i in 0 .. MAX_BYTES;
+
+        let (lead_id, lead_worker_id) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let (caller_id, worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Regular,
+            1,
+            Some(lead_id.clone())
+        );
+        let slashing_amount = One::one();
+        let penalty = Penalty {
+            slashing_text: vec![0u8; i.try_into().unwrap()],
+            slashing_amount,
+        };
+    }: _(RawOrigin::Signed(lead_id.clone()), worker_id, penalty)
+    verify {
+        assert_last_event::<T, I>(RawEvent::StakeSlashed(worker_id, slashing_amount).into());
+    }
+
+    terminate_role_worker {
+        let i in 0 .. MAX_BYTES;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let (caller_id, worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Regular,
+            1,
+            Some(lead_id.clone())
+        );
+        // To be able to pay unpaid reward
+        let current_budget = BalanceOfCurrency::<T>::max_value();
+        WorkingTeam::<T, _>::set_budget(RawOrigin::Root.into(), current_budget).unwrap();
+        let penalty = Penalty {
+            slashing_text: vec![0u8; i.try_into().unwrap()],
+            slashing_amount: One::one(),
+        };
+    }: terminate_role(RawOrigin::Signed(lead_id.clone()), worker_id, Some(penalty))
+    verify {
+        assert!(!WorkerById::<T, I>::contains_key(worker_id), "Worker not terminated");
+        assert_last_event::<T, I>(RawEvent::TerminatedWorker(worker_id).into());
+    }
+
+    terminate_role_lead {
+        let i in 0 .. MAX_BYTES;
+
+        let (_, lead_worker_id) =
+            insert_a_worker::<T, I>(StakingRole::WithStakes, JobOpeningType::Leader, 0, None);
+        let current_budget = BalanceOfCurrency::<T>::max_value();
+        // To be able to pay unpaid reward
+        WorkingTeam::<T, _>::set_budget(RawOrigin::Root.into(), current_budget).unwrap();
+        let penalty = Penalty {
+            slashing_text: vec![0u8; i.try_into().unwrap()],
+            slashing_amount: One::one(),
+        };
+    }: terminate_role(RawOrigin::Root, lead_worker_id, Some(penalty))
+    verify {
+        assert!(!WorkerById::<T, I>::contains_key(lead_worker_id), "Worker not terminated");
+        assert_last_event::<T, I>(RawEvent::TerminatedLeader(lead_worker_id).into());
+    }
+
+    // Regular worker is the worst case scenario since the checks
+    // require access to the storage whilist that's not the case with a lead opening
+    increase_stake {
+        let i in 0 .. 1;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let (caller_id, worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Regular,
+            1,
+            Some(lead_id.clone())
+        );
+
+        let old_stake = One::one();
+        WorkingTeam::<T, _>::decrease_stake(
+            RawOrigin::Signed(lead_id.clone()).into(), worker_id.clone(), old_stake).unwrap();
+        let new_stake = old_stake + One::one();
+    }: _ (RawOrigin::Signed(caller_id.clone()), worker_id.clone(), new_stake)
+    verify {
+        assert_last_event::<T, I>(RawEvent::StakeIncreased(worker_id, new_stake).into());
+    }
+
+    // Regular worker is the worst case scenario since the checks
+    // require access to the storage whilist that's not the case with a lead opening
+    decrease_stake {
+        let i in 0 .. 1;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let (_, worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Regular,
+            1,
+            Some(lead_id.clone())
+        );
+
+        // I'm assuming that we will usually have MaxBalance > 1
+        let new_stake = One::one();
+    }: _ (RawOrigin::Signed(lead_id), worker_id, new_stake)
+    verify {
+        assert_last_event::<T, I>(RawEvent::StakeDecreased(worker_id, new_stake).into());
+    }
+
+    spend_from_budget {
+        let i in 0 .. 1;
+
+        let (lead_id, _) = insert_a_worker::<T, I>(
+            StakingRole::WithoutStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+
+        let current_budget = BalanceOfCurrency::<T>::max_value();
+        WorkingTeam::<T, _>::set_budget(RawOrigin::Root.into(), current_budget).unwrap();
+    }: _ (RawOrigin::Signed(lead_id.clone()), lead_id.clone(), current_budget, None)
+    verify {
+        assert_eq!(WorkingTeam::<T, I>::budget(), Zero::zero(), "Budget not updated");
+        assert_last_event::<T, I>(RawEvent::BudgetSpending(lead_id, current_budget).into());
+    }
+
+    // Regular worker is the worst case scenario since the checks
+    // require access to the storage whilist that's not the case with a lead opening
+    update_reward_amount {
+        let i in 0 .. 1;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let (_, worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithoutStakes,
+            JobOpeningType::Regular,
+            1,
+            Some(lead_id.clone())
+        );
+
+        let new_reward = Some(BalanceOfCurrency::<T>::max_value());
+    }: _ (RawOrigin::Signed(lead_id.clone()), worker_id, new_reward)
+    verify {
+        assert_eq!(
+            WorkingTeam::<T, I>::worker_by_id(worker_id).reward_per_block,
+            new_reward,
+            "Reward not updated"
+        );
+
+        assert_last_event::<T, I>(
+            RawEvent::WorkerRewardAmountUpdated(worker_id, new_reward).into()
+        );
+    }
+
+    set_status_text {
+        let i in 0 .. MAX_BYTES;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let status_text = Some(vec![0u8; i.try_into().unwrap()]);
+
+    }: _ (RawOrigin::Signed(lead_id), status_text.clone())
+    verify {
+        let status_text_hash = T::Hashing::hash(&status_text.unwrap()).as_ref().to_vec();
+
+        assert_eq!(
+            WorkingTeam::<T, I>::status_text_hash(),
+            status_text_hash,
+            "Status text not updated"
+        );
+
+        assert_last_event::<T, I>(RawEvent::StatusTextChanged(status_text_hash).into());
+    }
+
+    update_reward_account {
+        let i in 0 .. 1;
+
+        let (caller_id, worker_id) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+        let new_id = account::<T::AccountId>("new_id", 1, 0);
+
+    }: _ (RawOrigin::Signed(caller_id), worker_id, new_id.clone())
+    verify {
+        assert_eq!(
+            WorkingTeam::<T, I>::worker_by_id(worker_id).reward_account_id,
+            new_id,
+            "Reward account not updated"
+        );
+
+        assert_last_event::<T, I>(RawEvent::WorkerRewardAccountUpdated(worker_id, new_id).into());
+    }
+
+    set_budget {
+        let i in 0 .. 1;
+
+        let new_budget = BalanceOfCurrency::<T>::max_value();
+
+    }: _(RawOrigin::Root, new_budget)
+    verify {
+        assert_eq!(WorkingTeam::<T, I>::budget(), new_budget, "Budget isn't updated");
+        assert_last_event::<T, I>(RawEvent::BudgetSet(new_budget).into());
+    }
+
+    // Regular opening is the worst case scenario since the checks
+    // require access to the storage whilist that's not the case with a lead opening
+    add_opening {
+        let i in 0 .. MAX_BYTES;
+
+        let (lead_id, _) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+
+        let stake_policy = StakePolicy {
+            stake_amount: BalanceOfCurrency::<T>::max_value(),
+            leaving_unstaking_period: T::BlockNumber::max_value(),
+        };
+
+        let reward_policy = RewardPolicy {
+            reward_per_block: BalanceOfCurrency::<T>::max_value(),
+        };
+
+        let description = vec![0u8; i.try_into().unwrap()];
+
+    }: _(
+            RawOrigin::Signed(lead_id),
+            description,
+            JobOpeningType::Regular,
+            Some(stake_policy),
+            Some(reward_policy)
+        )
+    verify {
+        assert!(OpeningById::<T, I>::contains_key(T::OpeningId::from(1)));
+        assert_last_event::<T, I>(RawEvent::OpeningAdded(T::OpeningId::from(1)).into());
+    }
+
+    // This is always worse than leave_role_immediatly
+    leave_role_immediatly {
+        let i in 0 .. 1;
+        // Worst case scenario there is a lead(this requires **always** more steps)
+        // could separate into new branch to tighten weight
+        // Also, workers without stake can leave immediatly
+        let (caller_id, lead_worker_id) =
+            insert_a_worker::<T, I>(StakingRole::WithoutStakes, JobOpeningType::Leader, 0, None);
+
+        // To be able to pay unpaid reward
+        WorkingTeam::<T, _>::set_budget(
+            RawOrigin::Root.into(),
+            BalanceOfCurrency::<T>::max_value()
+        ).unwrap();
+
+    }: leave_role(RawOrigin::Signed(caller_id), lead_worker_id)
+    verify {
+        assert!(!WorkerById::<T, I>::contains_key(lead_worker_id), "Worker hasn't left");
+        assert_last_event::<T, I>(RawEvent::WorkerExited(lead_worker_id).into());
+    }
+
+    // Generally speaking this seems to be always the best case scenario
+    // but since it's so obviously a different branch I think it's a good idea
+    // to leave this branch and use tha max between these 2
+    leave_role_later {
+        let i in 0 .. 1;
+
+        // Workers with stake can't leave immediatly
+        let (caller_id, caller_worker_id) = insert_a_worker::<T, I>(
+            StakingRole::WithStakes,
+            JobOpeningType::Leader,
+            0,
+            None
+        );
+    }: leave_role(RawOrigin::Signed(caller_id), caller_worker_id)
+    verify {
+        assert_eq!(
+            WorkingTeam::<T, _>::worker_by_id(caller_worker_id).started_leaving_at,
+            Some(System::<T>::block_number()),
+            "Worker hasn't started leaving"
+        );
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::tests::{build_test_externalities, Test};
+    use frame_support::assert_ok;
+
+    #[test]
+    fn test_leave_role_later() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_leave_role_later::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_leave_role_immediatly() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_leave_role_immediatly::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_add_opening() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_add_opening::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_set_budget() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_set_budget::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_update_reward_account() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_update_reward_account::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_set_status_text() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_set_status_text::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_update_reward_amount() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_update_reward_amount::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_spend_from_budget() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_spend_from_budget::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_decrease_stake() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_decrease_stake::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_increase_stake() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_increase_stake::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_terminate_role_lead() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_terminate_role_lead::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_terminate_role_worker() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_terminate_role_worker::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_slash_stake() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_slash_stake::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_withdraw_application() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_withdraw_application::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_cancel_opening() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_cancel_opening::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_update_role_account() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_update_role_account::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_fill_opening_worker() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_fill_opening_worker::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_fill_opening_lead() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_fill_opening_lead::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_apply_on_opening() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_apply_on_opening::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_on_inintialize_rewarding_without_missing_reward() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_on_initialize_rewarding_without_missing_reward::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_on_inintialize_rewarding_with_missing_reward_cant_pay() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(
+                test_benchmark_on_initialize_rewarding_with_missing_reward_cant_pay::<Test>()
+            );
+        });
+    }
+
+    #[test]
+    fn test_on_inintialize_rewarding_with_missing_reward() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_on_initialize_rewarding_with_missing_reward::<Test>());
+        });
+    }
+
+    #[test]
+    fn test_on_inintialize_leaving() {
+        build_test_externalities().execute_with(|| {
+            assert_ok!(test_benchmark_on_initialize_leaving::<Test>());
+        });
+    }
+}

+ 1 - 0
runtime-modules/working-team/src/checks.rs

@@ -9,6 +9,7 @@ use frame_support::traits::Get;
 use frame_support::{ensure, StorageMap, StorageValue};
 use sp_arithmetic::traits::Zero;
 use sp_std::collections::btree_set::BTreeSet;
+use sp_std::vec::Vec;
 use system::{ensure_root, ensure_signed};
 
 use crate::types::{ApplicationInfo, StakeParameters};

+ 6 - 5
runtime-modules/working-team/src/lib.rs

@@ -29,6 +29,7 @@
 // Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
 //#![warn(missing_docs)]
 
+mod benchmarking;
 mod checks;
 mod errors;
 #[cfg(test)]
@@ -56,7 +57,7 @@ pub use types::{
 use common::origin::ActorOriginValidator;
 
 /// The _Team_ main _Trait_
-pub trait Trait<I: Instance>:
+pub trait Trait<I: Instance = DefaultInstance>:
     system::Trait + membership::Trait + balances::Trait + common::currency::GovernanceCurrency
 {
     /// OpeningId type
@@ -100,7 +101,7 @@ pub trait Trait<I: Instance>:
 
 decl_event!(
     /// _Team_ events
-    pub enum Event<T, I>
+    pub enum Event<T, I = DefaultInstance>
     where
        <T as Trait<I>>::OpeningId,
        <T as Trait<I>>::ApplicationId,
@@ -213,7 +214,7 @@ decl_event!(
 );
 
 decl_storage! {
-    trait Store for Module<T: Trait<I>, I: Instance> as WorkingTeam {
+    trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as WorkingTeam {
         /// Next identifier value for new job opening.
         pub NextOpeningId get(fn next_opening_id): T::OpeningId;
 
@@ -251,7 +252,7 @@ decl_storage! {
 
 decl_module! {
     /// _Working group_ substrate module.
-    pub struct Module<T: Trait<I>, I: Instance> for enum Call where origin: T::Origin {
+    pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: T::Origin {
         /// Default deposit_event() handler
         fn deposit_event() = default;
 
@@ -261,7 +262,7 @@ decl_module! {
         /// Exports const -  max simultaneous active worker number.
         const MaxWorkerNumberLimit: u32 = T::MaxWorkerNumberLimit::get();
 
-        fn on_initialize() -> Weight{
+        fn on_initialize() -> Weight {
             let leaving_workers = Self::get_workers_with_finished_unstaking_period();
 
             leaving_workers.iter().for_each(|wi| {

+ 23 - 36
runtime-modules/working-team/src/tests/fixtures.rs

@@ -1,3 +1,4 @@
+#![cfg(test)]
 use frame_support::dispatch::{DispatchError, DispatchResult};
 use frame_support::StorageMap;
 use sp_runtime::traits::Hash;
@@ -5,29 +6,19 @@ use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
 use system::{EventRecord, Phase, RawOrigin};
 
 use super::hiring_workflow::HiringWorkflow;
-use super::mock::{
-    Balances, LockId, Membership, System, Test, TestEvent, TestWorkingTeam, TestWorkingTeamInstance,
-};
+use super::mock::{Balances, LockId, Membership, System, Test, TestEvent, TestWorkingTeam};
 use crate::types::StakeParameters;
 use crate::{
-    ApplyOnOpeningParameters, JobApplication, JobOpening, JobOpeningType, Penalty, RawEvent,
-    RewardPolicy, StakePolicy, TeamWorker,
+    ApplyOnOpeningParameters, DefaultInstance, JobApplication, JobOpening, JobOpeningType, Penalty,
+    RawEvent, RewardPolicy, StakePolicy, TeamWorker,
 };
 
 pub struct EventFixture;
 impl EventFixture {
     pub fn assert_last_crate_event(
-        expected_raw_event: RawEvent<
-            u64,
-            u64,
-            BTreeMap<u64, u64>,
-            u64,
-            u64,
-            u64,
-            TestWorkingTeamInstance,
-        >,
+        expected_raw_event: RawEvent<u64, u64, BTreeMap<u64, u64>, u64, u64, u64, DefaultInstance>,
     ) {
-        let converted_event = TestEvent::working_team_TestWorkingTeamInstance(expected_raw_event);
+        let converted_event = TestEvent::crate_DefaultInstance(expected_raw_event);
 
         Self::assert_last_global_event(converted_event)
     }
@@ -194,7 +185,7 @@ impl ApplyOnOpeningFixture {
         let saved_application_next_id = TestWorkingTeam::next_application_id();
         TestWorkingTeam::apply_on_opening(
             self.origin.clone().into(),
-            ApplyOnOpeningParameters::<Test, TestWorkingTeamInstance> {
+            ApplyOnOpeningParameters::<Test, DefaultInstance> {
                 member_id: self.member_id,
                 opening_id: self.opening_id,
                 role_account_id: self.role_account_id,
@@ -337,15 +328,13 @@ impl FillOpeningFixture {
             assert_eq!(TestWorkingTeam::next_worker_id(), saved_worker_next_id + 1);
             let worker_id = saved_worker_next_id;
 
-            assert!(
-                !<crate::OpeningById<Test, TestWorkingTeamInstance>>::contains_key(self.opening_id)
-            );
+            assert!(!<crate::OpeningById<Test, DefaultInstance>>::contains_key(
+                self.opening_id
+            ));
 
             for application_id in self.successful_application_ids.iter() {
                 assert!(
-                    !<crate::ApplicationById<Test, TestWorkingTeamInstance>>::contains_key(
-                        application_id
-                    )
+                    !<crate::ApplicationById<Test, DefaultInstance>>::contains_key(application_id)
                 );
             }
 
@@ -559,9 +548,9 @@ impl LeaveWorkerRoleFixture {
                 }
             }
 
-            assert!(
-                !<crate::WorkerById<Test, TestWorkingTeamInstance>>::contains_key(self.worker_id)
-            );
+            assert!(!<crate::WorkerById<Test, DefaultInstance>>::contains_key(
+                self.worker_id
+            ));
         }
     }
 }
@@ -598,11 +587,9 @@ impl TerminateWorkerRoleFixture {
 
         if actual_result.is_ok() {
             if actual_result.is_ok() {
-                assert!(
-                    !<crate::WorkerById<Test, TestWorkingTeamInstance>>::contains_key(
-                        self.worker_id
-                    )
-                );
+                assert!(!<crate::WorkerById<Test, DefaultInstance>>::contains_key(
+                    self.worker_id
+                ));
             }
         }
     }
@@ -866,9 +853,9 @@ impl CancelOpeningFixture {
 
     pub fn call_and_assert(&self, expected_result: DispatchResult) {
         if expected_result.is_ok() {
-            assert!(
-                <crate::OpeningById<Test, TestWorkingTeamInstance>>::contains_key(self.opening_id)
-            );
+            assert!(<crate::OpeningById<Test, DefaultInstance>>::contains_key(
+                self.opening_id
+            ));
         }
 
         let actual_result = self.call().map(|_| ());
@@ -876,9 +863,9 @@ impl CancelOpeningFixture {
         assert_eq!(actual_result.clone(), expected_result);
 
         if actual_result.is_ok() {
-            assert!(
-                !<crate::OpeningById<Test, TestWorkingTeamInstance>>::contains_key(self.opening_id)
-            );
+            assert!(!<crate::OpeningById<Test, DefaultInstance>>::contains_key(
+                self.opening_id
+            ));
         }
     }
 }

+ 4 - 6
runtime-modules/working-team/src/tests/mock.rs

@@ -10,7 +10,7 @@ use sp_runtime::{
 };
 use system;
 
-use crate::{BalanceOfCurrency, Module, StakingHandler, Trait};
+use crate::{BalanceOfCurrency, DefaultInstance, Module, StakingHandler, Trait};
 use common::currency::GovernanceCurrency;
 use frame_support::dispatch::DispatchResult;
 
@@ -19,7 +19,6 @@ impl_outer_origin! {
 }
 
 mod working_team {
-    pub use super::TestWorkingTeamInstance;
     pub use crate::Event;
 }
 
@@ -30,7 +29,7 @@ mod membership_mod {
 impl_outer_event! {
     pub enum TestEvent for Test {
         balances<T>,
-        working_team TestWorkingTeamInstance <T>,
+        crate DefaultInstance <T>,
         membership_mod<T>,
         system<T>,
     }
@@ -114,7 +113,7 @@ parameter_types! {
     pub const LockId: [u8; 8] = [1; 8];
 }
 
-impl Trait<TestWorkingTeamInstance> for Test {
+impl Trait for Test {
     type OpeningId = u64;
     type ApplicationId = u64;
     type Event = TestEvent;
@@ -139,8 +138,7 @@ impl common::origin::ActorOriginValidator<Origin, u64, u64> for () {
     }
 }
 
-pub type TestWorkingTeamInstance = crate::Instance1;
-pub type TestWorkingTeam = Module<Test, TestWorkingTeamInstance>;
+pub type TestWorkingTeam = Module<Test, DefaultInstance>;
 
 pub const STAKING_ACCOUNT_ID_FOR_FAILED_VALIDITY_CHECK: u64 = 111;
 pub const STAKING_ACCOUNT_ID_FOR_FAILED_AMOUNT_CHECK: u64 = 222;

+ 67 - 77
runtime-modules/working-team/src/tests/mod.rs

@@ -2,6 +2,8 @@ mod fixtures;
 mod hiring_workflow;
 mod mock;
 
+pub use mock::{build_test_externalities, Test};
+
 use system::RawOrigin;
 
 use crate::tests::fixtures::{
@@ -15,7 +17,10 @@ use crate::tests::mock::{
     STAKING_ACCOUNT_ID_FOR_FAILED_VALIDITY_CHECK, STAKING_ACCOUNT_ID_FOR_ZERO_STAKE,
 };
 use crate::types::StakeParameters;
-use crate::{Error, JobOpeningType, Penalty, RawEvent, RewardPolicy, StakePolicy, TeamWorker};
+use crate::{
+    DefaultInstance, Error, JobOpeningType, Penalty, RawEvent, RewardPolicy, StakePolicy,
+    TeamWorker,
+};
 use fixtures::{
     increase_total_balance_issuance_using_account_id, setup_members, AddOpeningFixture,
     ApplyOnOpeningFixture, EventFixture, FillOpeningFixture, HireLeadFixture,
@@ -24,10 +29,7 @@ use fixtures::{
 };
 use frame_support::dispatch::DispatchError;
 use frame_support::StorageMap;
-use mock::{
-    build_test_externalities, run_to_block, Balances, RewardPeriod, Test, TestWorkingTeam,
-    TestWorkingTeamInstance, ACTOR_ORIGIN_ERROR,
-};
+use mock::{run_to_block, Balances, RewardPeriod, TestWorkingTeam, ACTOR_ORIGIN_ERROR};
 use sp_runtime::traits::Hash;
 use sp_std::collections::btree_map::BTreeMap;
 
@@ -77,9 +79,8 @@ fn add_opening_fails_with_zero_stake() {
                 leaving_unstaking_period: 0,
             }));
 
-        add_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CannotStakeZero.into(),
-        ));
+        add_opening_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::CannotStakeZero.into()));
     });
 }
 
@@ -94,7 +95,7 @@ fn add_opening_fails_with_zero_reward() {
             }));
 
         add_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CannotRewardWithZero.into(),
+            Error::<Test, DefaultInstance>::CannotRewardWithZero.into(),
         ));
     });
 }
@@ -118,7 +119,7 @@ fn add_opening_fails_with_incorrect_unstaking_period() {
             }));
 
         add_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::UnstakingPeriodLessThanMinimum.into(),
+            Error::<Test, DefaultInstance>::UnstakingPeriodLessThanMinimum.into(),
         ));
     });
 }
@@ -167,7 +168,7 @@ fn apply_on_opening_fails_with_invalid_opening_id() {
             ApplyOnOpeningFixture::default_for_opening_id(invalid_opening_id);
 
         apply_on_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::OpeningDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::OpeningDoesNotExist.into(),
         ));
     });
 }
@@ -351,7 +352,7 @@ fn fill_opening_fails_with_invalid_active_worker_number() {
         );
 
         fill_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::MaxActiveWorkerNumberExceeded.into(),
+            Error::<Test, DefaultInstance>::MaxActiveWorkerNumberExceeded.into(),
         ));
     });
 }
@@ -371,7 +372,7 @@ fn fill_opening_fails_with_invalid_application_id() {
             FillOpeningFixture::default_for_ids(opening_id, vec![invalid_application_id]);
 
         fill_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::SuccessfulWorkerApplicationDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::SuccessfulWorkerApplicationDoesNotExist.into(),
         ));
     });
 }
@@ -382,9 +383,7 @@ fn cannot_hire_a_lead_twice() {
         HireLeadFixture::default().hire_lead();
         HireLeadFixture::default()
             .with_setup_environment(false)
-            .expect(
-                Error::<Test, TestWorkingTeamInstance>::CannotHireLeaderWhenLeaderExists.into(),
-            );
+            .expect(Error::<Test, DefaultInstance>::CannotHireLeaderWhenLeaderExists.into());
     });
 }
 
@@ -397,7 +396,7 @@ fn cannot_hire_muptiple_leaders() {
             .add_default_application()
             .add_application_full(b"leader2".to_vec(), RawOrigin::Signed(2), 2, Some(2))
             .expect(Err(
-                Error::<Test, TestWorkingTeamInstance>::CannotHireMultipleLeaders.into(),
+                Error::<Test, DefaultInstance>::CannotHireMultipleLeaders.into(),
             ))
             .execute();
     });
@@ -481,9 +480,8 @@ fn update_worker_role_fails_with_leaving_worker() {
         let update_worker_account_fixture =
             UpdateWorkerRoleAccountFixture::default_with_ids(worker_id, new_account_id);
 
-        update_worker_account_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerIsLeaving.into(),
-        ));
+        update_worker_account_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::WorkerIsLeaving.into()));
     });
 }
 
@@ -497,7 +495,7 @@ fn update_worker_role_account_fails_with_invalid_origin() {
                 .with_origin(RawOrigin::None);
 
         update_worker_account_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::InvalidMemberOrigin.into(),
+            Error::<Test, DefaultInstance>::InvalidMemberOrigin.into(),
         ));
     });
 }
@@ -612,7 +610,7 @@ fn leave_worker_role_fails_with_invalid_origin_signed_account() {
             .with_origin(RawOrigin::Signed(2));
 
         leave_worker_role_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::SignerIsNotWorkerRoleAccount.into(),
+            Error::<Test, DefaultInstance>::SignerIsNotWorkerRoleAccount.into(),
         ));
     });
 }
@@ -639,9 +637,8 @@ fn leave_worker_role_fails_already_leaving_worker() {
             .with_stake_policy(stake_policy);
 
         leave_worker_role_fixture.call_and_assert(Ok(()));
-        leave_worker_role_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerIsLeaving.into(),
-        ));
+        leave_worker_role_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::WorkerIsLeaving.into()));
     });
 }
 
@@ -655,7 +652,7 @@ fn leave_worker_role_fails_with_invalid_worker_id() {
             LeaveWorkerRoleFixture::default_for_worker_id(invalid_worker_id);
 
         leave_worker_role_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerDoesNotExist.into(),
         ));
     });
 }
@@ -746,9 +743,8 @@ fn terminate_worker_role_fails_with_unset_lead() {
         let terminate_worker_role_fixture =
             TerminateWorkerRoleFixture::default_for_worker_id(worker_id);
 
-        terminate_worker_role_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CurrentLeadNotSet.into(),
-        ));
+        terminate_worker_role_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::CurrentLeadNotSet.into()));
     });
 }
 
@@ -846,7 +842,7 @@ fn apply_on_opening_fails_with_stake_inconsistent_with_opening_stake() {
             .with_stake_parameters(Some(stake_parameters));
 
         apply_on_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::ApplicationStakeDoesntMatchOpening.into(),
+            Error::<Test, DefaultInstance>::ApplicationStakeDoesntMatchOpening.into(),
         ));
     });
 }
@@ -916,7 +912,7 @@ fn apply_on_opening_fails_invalid_staking_check() {
             .with_stake_parameters(Some(stake_parameters));
 
         apply_on_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::InvalidStakingAccountForMember.into(),
+            Error::<Test, DefaultInstance>::InvalidStakingAccountForMember.into(),
         ));
     });
 }
@@ -952,7 +948,7 @@ fn apply_on_opening_fails_stake_amount_check() {
             .with_stake_parameters(Some(stake_parameters));
 
         apply_on_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::InsufficientBalanceToCoverStake.into(),
+            Error::<Test, DefaultInstance>::InsufficientBalanceToCoverStake.into(),
         ));
     });
 }
@@ -988,7 +984,7 @@ fn apply_on_opening_fails_with_conflicting_stakes() {
             .with_stake_parameters(Some(stake_parameters));
 
         apply_on_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::ConflictStakesOnAccount.into(),
+            Error::<Test, DefaultInstance>::ConflictStakesOnAccount.into(),
         ));
     });
 }
@@ -1083,7 +1079,9 @@ fn leave_worker_unlocks_the_stake_with_unstaking_period() {
 
         run_to_block(leaving_unstaking_period);
 
-        assert!(!<crate::WorkerById<Test, TestWorkingTeamInstance>>::contains_key(worker_id));
+        assert!(!<crate::WorkerById<Test, DefaultInstance>>::contains_key(
+            worker_id
+        ));
         assert_eq!(Balances::usable_balance(&account_id), total_balance);
 
         EventFixture::assert_last_crate_event(RawEvent::WorkerExited(worker_id));
@@ -1125,7 +1123,9 @@ fn leave_worker_works_immedietely_stake_is_zero() {
 
         leave_worker_role_fixture.call_and_assert(Ok(()));
 
-        assert!(!<crate::WorkerById<Test, TestWorkingTeamInstance>>::contains_key(worker_id));
+        assert!(!<crate::WorkerById<Test, DefaultInstance>>::contains_key(
+            worker_id
+        ));
     });
 }
 
@@ -1188,7 +1188,7 @@ fn terminate_worker_with_slashing_fails_with_no_staking_account() {
                 .with_penalty(Some(penalty));
 
         terminate_worker_role_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CannotChangeStakeWithoutStakingAccount.into(),
+            Error::<Test, DefaultInstance>::CannotChangeStakeWithoutStakingAccount.into(),
         ));
     });
 }
@@ -1256,7 +1256,7 @@ fn slash_worker_stake_fails_with_no_staking_account() {
             SlashWorkerStakeFixture::default_for_worker_id(worker_id).with_penalty(penalty);
 
         slash_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CannotChangeStakeWithoutStakingAccount.into(),
+            Error::<Test, DefaultInstance>::CannotChangeStakeWithoutStakingAccount.into(),
         ));
     });
 }
@@ -1352,7 +1352,7 @@ fn slash_worker_stake_fails_with_zero_balance() {
             SlashWorkerStakeFixture::default_for_worker_id(worker_id).with_penalty(penalty);
 
         slash_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::StakeBalanceCannotBeZero.into(),
+            Error::<Test, DefaultInstance>::StakeBalanceCannotBeZero.into(),
         ));
     });
 }
@@ -1366,7 +1366,7 @@ fn slash_worker_stake_fails_with_invalid_worker_id() {
         let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
 
         slash_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerDoesNotExist.into(),
         ));
     });
 }
@@ -1378,9 +1378,8 @@ fn slash_worker_stake_fails_with_not_set_lead() {
 
         let slash_stake_fixture = SlashWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
 
-        slash_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CurrentLeadNotSet.into(),
-        ));
+        slash_stake_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::CurrentLeadNotSet.into()));
     });
 }
 
@@ -1440,7 +1439,7 @@ fn decrease_worker_stake_fails_with_no_staking_account() {
             .with_balance(new_stake_balance);
 
         decrease_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CannotChangeStakeWithoutStakingAccount.into(),
+            Error::<Test, DefaultInstance>::CannotChangeStakeWithoutStakingAccount.into(),
         ));
     });
 }
@@ -1518,7 +1517,7 @@ fn decrease_worker_stake_fails_with_zero_balance() {
             DecreaseWorkerStakeFixture::default_for_worker_id(worker_id).with_balance(0);
 
         decrease_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::StakeBalanceCannotBeZero.into(),
+            Error::<Test, DefaultInstance>::StakeBalanceCannotBeZero.into(),
         ));
     });
 }
@@ -1533,7 +1532,7 @@ fn decrease_worker_stake_fails_with_invalid_worker_id() {
             DecreaseWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
 
         decrease_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerDoesNotExist.into(),
         ));
     });
 }
@@ -1546,9 +1545,8 @@ fn decrease_worker_stake_fails_with_not_set_lead() {
         let decrease_stake_fixture =
             DecreaseWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
 
-        decrease_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CurrentLeadNotSet.into(),
-        ));
+        decrease_stake_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::CurrentLeadNotSet.into()));
     });
 }
 
@@ -1650,7 +1648,7 @@ fn increase_worker_stake_fails_with_zero_balance() {
             IncreaseWorkerStakeFixture::default_for_worker_id(worker_id).with_balance(0);
 
         increase_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::StakeBalanceCannotBeZero.into(),
+            Error::<Test, DefaultInstance>::StakeBalanceCannotBeZero.into(),
         ));
     });
 }
@@ -1671,7 +1669,7 @@ fn increase_worker_stake_fails_with_no_staking_account() {
         let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id);
 
         increase_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::CannotChangeStakeWithoutStakingAccount.into(),
+            Error::<Test, DefaultInstance>::CannotChangeStakeWithoutStakingAccount.into(),
         ));
     });
 }
@@ -1687,7 +1685,7 @@ fn increase_worker_stake_fails_with_invalid_worker_id() {
             IncreaseWorkerStakeFixture::default_for_worker_id(invalid_worker_id);
 
         increase_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerDoesNotExist.into(),
         ));
     });
 }
@@ -1715,7 +1713,7 @@ fn increase_worker_stake_fails_external_check() {
             .with_balance(invalid_new_stake);
 
         decrease_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::InsufficientBalanceToCoverStake.into(),
+            Error::<Test, DefaultInstance>::InsufficientBalanceToCoverStake.into(),
         ));
     });
 }
@@ -1772,7 +1770,7 @@ fn withdraw_application_fails_invalid_application_id() {
         let withdraw_application_fixture =
             WithdrawApplicationFixture::default_for_application_id(invalid_application_id);
         withdraw_application_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerApplicationDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerApplicationDoesNotExist.into(),
         ));
     });
 }
@@ -1811,7 +1809,7 @@ fn withdraw_worker_application_fails_with_invalid_application_author() {
             WithdrawApplicationFixture::default_for_application_id(application_id)
                 .with_signer(invalid_author_account_id);
         withdraw_application_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::OriginIsNotApplicant.into(),
+            Error::<Test, DefaultInstance>::OriginIsNotApplicant.into(),
         ));
     });
 }
@@ -1862,7 +1860,7 @@ fn cancel_opening_fails_invalid_opening_id() {
             CancelOpeningFixture::default_for_opening_id(invalid_opening_id);
 
         cancel_opening_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::OpeningDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::OpeningDoesNotExist.into(),
         ));
     });
 }
@@ -1894,9 +1892,8 @@ fn decrease_worker_stake_fails_with_leaving_worker() {
         let decrease_stake_fixture = DecreaseWorkerStakeFixture::default_for_worker_id(worker_id)
             .with_balance(new_stake_balance);
 
-        decrease_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerIsLeaving.into(),
-        ));
+        decrease_stake_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::WorkerIsLeaving.into()));
     });
 }
 
@@ -1927,9 +1924,8 @@ fn increase_worker_stake_fails_with_leaving_worker() {
         let increase_stake_fixture = IncreaseWorkerStakeFixture::default_for_worker_id(worker_id)
             .with_balance(new_stake_balance);
 
-        increase_stake_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerIsLeaving.into(),
-        ));
+        increase_stake_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::WorkerIsLeaving.into()));
     });
 }
 
@@ -2171,7 +2167,7 @@ fn update_reward_account_fails_with_invalid_origin_signed_account() {
                 .with_origin(RawOrigin::Signed(invalid_role_account));
 
         update_account_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::SignerIsNotWorkerRoleAccount.into(),
+            Error::<Test, DefaultInstance>::SignerIsNotWorkerRoleAccount.into(),
         ));
     });
 }
@@ -2192,7 +2188,7 @@ fn update_reward_account_fails_with_invalid_worker_id() {
             UpdateRewardAccountFixture::default_with_ids(invalid_worker_id, new_reward_account);
 
         update_account_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerDoesNotExist.into(),
         ));
     });
 }
@@ -2207,9 +2203,8 @@ fn update_reward_account_fails_with_no_recurring_reward() {
         let update_account_fixture =
             UpdateRewardAccountFixture::default_with_ids(worker_id, new_reward_account);
 
-        update_account_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerHasNoReward.into(),
-        ));
+        update_account_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::WorkerHasNoReward.into()));
     });
 }
 
@@ -2289,9 +2284,8 @@ fn update_reward_amount_fails_with_invalid_origin_signed_account() {
         let update_amount_fixture = UpdateRewardAmountFixture::default_for_worker_id(worker_id)
             .with_origin(RawOrigin::Signed(2));
 
-        update_amount_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::IsNotLeadAccount.into(),
-        ));
+        update_amount_fixture
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::IsNotLeadAccount.into()));
     });
 }
 
@@ -2305,7 +2299,7 @@ fn update_reward_amount_fails_with_invalid_worker_id() {
             UpdateRewardAmountFixture::default_for_worker_id(invalid_worker_id);
 
         update_amount_fixture.call_and_assert(Err(
-            Error::<Test, TestWorkingTeamInstance>::WorkerDoesNotExist.into(),
+            Error::<Test, DefaultInstance>::WorkerDoesNotExist.into(),
         ));
     });
 }
@@ -2337,9 +2331,7 @@ fn set_status_text_fails_with_bad_origin() {
 
         SetStatusTextFixture::default()
             .with_origin(RawOrigin::Signed(leader_account_id))
-            .call_and_assert(Err(
-                Error::<Test, TestWorkingTeamInstance>::IsNotLeadAccount.into(),
-            ));
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::IsNotLeadAccount.into()));
     });
 }
 
@@ -2384,7 +2376,7 @@ fn spend_from_budget_fails_with_empty_budget() {
             .with_account_id(account_id)
             .with_amount(amount)
             .call_and_assert(Err(
-                Error::<Test, TestWorkingTeamInstance>::InsufficientBudgetForSpending.into(),
+                Error::<Test, DefaultInstance>::InsufficientBudgetForSpending.into(),
             ));
     });
 }
@@ -2399,8 +2391,6 @@ fn spend_from_budget_fails_with_zero_amount() {
         SpendFromBudgetFixture::default()
             .with_account_id(account_id)
             .with_amount(amount)
-            .call_and_assert(Err(
-                Error::<Test, TestWorkingTeamInstance>::CannotSpendZero.into()
-            ));
+            .call_and_assert(Err(Error::<Test, DefaultInstance>::CannotSpendZero.into()));
     });
 }

+ 1 - 0
runtime-modules/working-team/src/types.rs

@@ -4,6 +4,7 @@ use codec::{Decode, Encode};
 use common::currency::GovernanceCurrency;
 use frame_support::dispatch::DispatchResult;
 use frame_support::traits::Currency;
+use sp_std::vec::Vec;
 
 #[cfg(feature = "std")]
 use serde::{Deserialize, Serialize};

+ 10 - 8
runtime/Cargo.toml

@@ -10,6 +10,7 @@ version = '7.1.0'
 # Third-party dependencies
 serde = { version = "1.0.101", optional = true, features = ["derive"] }
 codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+hex-literal = { optional = true, version = '0.3.1' }
 
 # Substrate primitives
 sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
@@ -155,17 +156,18 @@ std = [
 ]
 runtime-benchmarks = [
     "system/runtime-benchmarks",
-	"frame-support/runtime-benchmarks",
-	"sp-runtime/runtime-benchmarks",
-	"pallet-balances/runtime-benchmarks",
-	"pallet-collective/runtime-benchmarks",
-	"pallet-im-online/runtime-benchmarks",
-	"pallet-staking/runtime-benchmarks",
-	"pallet-timestamp/runtime-benchmarks",
+    "frame-support/runtime-benchmarks",
+    "sp-runtime/runtime-benchmarks",
+    "pallet-balances/runtime-benchmarks",
+    "pallet-collective/runtime-benchmarks",
+    "pallet-im-online/runtime-benchmarks",
+    "pallet-staking/runtime-benchmarks",
+    "pallet-timestamp/runtime-benchmarks",
     "frame-benchmarking",
     "frame-system-benchmarking",
     "pallet-offences-benchmarking",
-	"pallet-session-benchmarking",
+    "pallet-session-benchmarking",
+    "hex-literal",
 ]
 
 

+ 43 - 0
runtime/src/runtime_api.rs

@@ -201,4 +201,47 @@ impl_runtime_apis! {
             SessionKeys::decode_into_raw_public_keys(&encoded)
         }
     }
+
+
+    #[cfg(feature = "runtime-benchmarks")]
+    impl frame_benchmarking::Benchmark<Block> for Runtime {
+        fn dispatch_benchmark(
+            pallet: Vec<u8>,
+            benchmark: Vec<u8>,
+            lowest_range_values: Vec<u32>,
+            highest_range_values: Vec<u32>,
+            steps: Vec<u32>,
+            repeat: u32,
+        ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
+            use sp_std::vec;
+            use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark};
+            use frame_system_benchmarking::Module as SystemBench;
+            impl frame_system_benchmarking::Trait for Runtime {}
+
+            let whitelist: Vec<Vec<u8>> = vec![
+                // Block Number
+                hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec(),
+                // Total Issuance
+                hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec(),
+                // Execution Phase
+                hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec(),
+                // Event Count
+                hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec(),
+                // System Events
+                hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec(),
+                // Caller 0 Account
+                hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da946c154ffd9992e395af90b5b13cc6f295c77033fce8a9045824a6690bbf99c6db269502f0a8d1d2a008542d5690a0749").to_vec(),
+                // Treasury Account
+                hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec(),
+            ];
+
+            let mut batches = Vec::<BenchmarkBatch>::new();
+            let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat, &whitelist);
+
+            add_benchmark!(params, batches, b"system", SystemBench::<Runtime>);
+
+            if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
+            Ok(batches)
+        }
+    }
 }