Browse Source

Merge branch 'nicaea' of https://github.com/Joystream/substrate-runtime-joystream into feature/working-group-rejection

Gleb Urvanov 4 years ago
parent
commit
83d99eb6ea

+ 39 - 0
.github/workflows/joystream-cli.yml

@@ -0,0 +1,39 @@
+name: joystream-cli
+on: [pull_request, push]
+
+jobs:
+  cli_build_ubuntu:
+    name: Ubuntu Build
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        node-version: [12.x]
+    steps:
+    - uses: actions/checkout@v1
+    - name: Use Node.js ${{ matrix.node-version }}
+      uses: actions/setup-node@v1
+      with:
+        node-version: ${{ matrix.node-version }}
+    - name: build
+      run: |
+        yarn install --frozen-lockfile
+        yarn madge --circular types/
+        yarn workspace joystream-cli build
+
+  cli_build_osx:
+    name: MacOS Build
+    runs-on: macos-latest
+    strategy:
+      matrix:
+        node-version: [12.x]
+    steps:
+    - uses: actions/checkout@v1
+    - name: Use Node.js ${{ matrix.node-version }}
+      uses: actions/setup-node@v1
+      with:
+        node-version: ${{ matrix.node-version }}
+    - name: build
+      run: |
+        yarn install --frozen-lockfile --network-timeout 120000
+        yarn madge --circular types/
+        yarn workspace joystream-cli build

+ 6 - 2
.github/workflows/pioneer-pr.yml → .github/workflows/pioneer.yml

@@ -17,6 +17,7 @@ jobs:
     - name: build
       run: |
         yarn install --frozen-lockfile
+        yarn madge --circular types/
         yarn workspace pioneer build
 
   pioneer_build_osx:
@@ -33,7 +34,8 @@ jobs:
         node-version: ${{ matrix.node-version }}
     - name: build
       run: |
-        yarn install --frozen-lockfile
+        yarn install --frozen-lockfile --network-timeout 120000
+        yarn madge --circular types/
         yarn workspace pioneer build
 
   pioneer_lint_ubuntu:
@@ -51,6 +53,7 @@ jobs:
     - name: lint
       run: |
         yarn install --frozen-lockfile
+        yarn madge --circular types/
         yarn workspace pioneer lint
 
   pioneer_lint_osx:
@@ -67,5 +70,6 @@ jobs:
         node-version: ${{ matrix.node-version }}
     - name: lint
       run: |
-        yarn install --frozen-lockfile
+        yarn install --frozen-lockfile --network-timeout 120000
+        yarn madge --circular types/
         yarn workspace pioneer lint

+ 4 - 4
cli/src/Api.ts

@@ -18,10 +18,10 @@ import {
 import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types';
 import { CLIError } from '@oclif/errors';
 import ExitCodes from './ExitCodes';
-import { Worker, Lead as WorkerLead, WorkerId, WorkerRoleStakeProfile } from '@joystream/types/lib/working-group';
-import { MemberId, Profile } from '@joystream/types/lib/members';
-import { RewardRelationship, RewardRelationshipId } from '@joystream/types/lib/recurring-rewards';
-import { Stake, StakeId } from '@joystream/types/lib/stake';
+import { Worker, Lead as WorkerLead, WorkerId, WorkerRoleStakeProfile } from '@joystream/types/working-group';
+import { MemberId, Profile } from '@joystream/types/members';
+import { RewardRelationship, RewardRelationshipId } from '@joystream/types/recurring-rewards';
+import { Stake, StakeId } from '@joystream/types/stake';
 import { LinkageResult } from '@polkadot/types/codec/Linkage';
 
 export const DEFAULT_API_URI = 'wss://rome-rpc-endpoint.joystream.org:9944/';

+ 3 - 3
cli/src/Types.ts

@@ -1,11 +1,11 @@
 import BN from 'bn.js';
-import { ElectionStage, Seat } from '@joystream/types/lib/council';
+import { ElectionStage, Seat } from '@joystream/types/council';
 import { Option } from '@polkadot/types';
 import { BlockNumber, Balance, AccountId } from '@polkadot/types/interfaces';
 import { DerivedBalances } from '@polkadot/api-derive/types';
 import { KeyringPair } from '@polkadot/keyring/types';
-import { WorkerId, Lead } from '@joystream/types/lib/working-group';
-import { Profile, MemberId } from '@joystream/types/lib/members';
+import { WorkerId, Lead } from '@joystream/types/working-group';
+import { Profile, MemberId } from '@joystream/types/members';
 
 // KeyringPair type extended with mandatory "meta.name"
 // It's used for accounts/keys management within CLI.

+ 1 - 1
cli/src/commands/council/info.ts

@@ -1,4 +1,4 @@
-import { ElectionStage } from '@joystream/types/lib/council';
+import { ElectionStage } from '@joystream/types/council';
 import { formatNumber, formatBalance } from '@polkadot/util';
 import { BlockNumber } from '@polkadot/types/interfaces';
 import { CouncilInfoObj, NameValueObj } from '../../Types';

+ 6 - 6
runtime-modules/working-group/src/errors.rs

@@ -23,8 +23,8 @@ decl_error! {
         /// Opening text too long.
         OpeningTextTooLong,
 
-        /// Worker opening does not exist.
-        WorkerOpeningDoesNotExist,
+        /// Opening does not exist.
+        OpeningDoesNotExist,
 
         /// Insufficient balance to apply.
         InsufficientBalanceToApply,
@@ -63,10 +63,10 @@ decl_error! {
         SuccessfulWorkerApplicationDoesNotExist,
 
         /// Reward policy has invalid next payment block number.
-        FillWorkerOpeningInvalidNextPaymentBlock,
+        FillOpeningInvalidNextPaymentBlock,
 
         /// Working group mint does not exist.
-        FillWorkerOpeningMintDoesNotExist,
+        FillOpeningMintDoesNotExist,
 
         ///Relationship must exist.
         RelationshipMustExist,
@@ -324,10 +324,10 @@ impl<T: hiring::Trait> rstd::convert::From<WrappedError<hiring::FillOpeningError
             ) => match stake_purpose {
                 hiring::StakePurpose::Application => match outcome_in_filled_opening {
                     hiring::ApplicationOutcomeInFilledOpening::Success => {
-                        Error::FullWorkerOpeningUnsuccessfulApplicationStakeUnstakingPeriodTooShort
+                        Error::FullWorkerOpeningSuccessfulApplicationStakeUnstakingPeriodTooShort
                     }
                     hiring::ApplicationOutcomeInFilledOpening::Failure => {
-                        Error::FullWorkerOpeningSuccessfulApplicationStakeUnstakingPeriodTooShort
+                        Error::FullWorkerOpeningUnsuccessfulApplicationStakeUnstakingPeriodTooShort
                     }
                 },
                 hiring::StakePurpose::Role => match outcome_in_filled_opening {

+ 253 - 201
runtime-modules/working-group/src/lib.rs

@@ -11,30 +11,28 @@
 //! ## Supported extrinsics
 //! ### Hiring flow
 //!
-//! - [add_worker_opening](./struct.Module.html#method.add_worker_opening) - Add an opening for a worker role.
-//! - [accept_worker_applications](./struct.Module.html#method.accept_worker_applications)- Begin accepting worker applications.
-//! - [begin_worker_applicant_review](./struct.Module.html#method.begin_worker_applicant_review) - Begin reviewing worker applications.
-//! - [fill_worker_opening](./struct.Module.html#method.fill_worker_opening) - Fill opening for worker.
-//! - [withdraw_worker_application](./struct.Module.html#method.withdraw_worker_application) - Withdraw the worker application.
-//! - [terminate_worker_application](./struct.Module.html#method.terminate_worker_application) - Terminate the worker application.
-//! - [apply_on_worker_opening](./struct.Module.html#method.apply_on_worker_opening) - Apply on a worker opening.
+//! - [add_opening](./struct.Module.html#method.add_opening) - Add an opening for a worker/lead role.
+//! - [accept_applications](./struct.Module.html#method.accept_applications)- Begin accepting worker/lead applications.
+//! - [begin_applicant_review](./struct.Module.html#method.begin_applicant_review) - Begin reviewing worker/lead applications.
+//! - [fill_opening](./struct.Module.html#method.fill_opening) - Fill opening for worker/lead.
+//! - [withdraw_application](./struct.Module.html#method.withdraw_application) - Withdraw the worker/lead application.
+//! - [terminate_application](./struct.Module.html#method.terminate_application) - Terminate the worker/lead application.
+//! - [apply_on_opening](./struct.Module.html#method.apply_on_opening) - Apply on a worker/lead opening.
 //!
 //! ### Roles lifecycle
 //!
-//! - [update_worker_role_account](./struct.Module.html#method.update_worker_role_account) -  Update the role account of the worker.
-//! - [update_worker_reward_account](./struct.Module.html#method.update_worker_reward_account) -  Update the reward account of the worker.
-//! - [leave_worker_role](./struct.Module.html#method.leave_worker_role) - Leave the role by the active worker.
-//! - [terminate_worker_role](./struct.Module.html#method.terminate_worker_role) - Terminate the worker role by the lead.
-//! - [set_lead](./struct.Module.html#method.set_lead) - Set lead.
-//! - [unset_lead](./struct.Module.html#method.unset_lead) - Unset lead.
-//! - [unstake](./struct.Module.html#method.unstake) - Unstake.
+//! - [update_role_account](./struct.Module.html#method.update_role_account) -  Update the role account of the worker/lead.
+//! - [update_reward_account](./struct.Module.html#method.update_reward_account) -  Update the reward account of the worker/lead.
+//! - [update_reward_amount](./struct.Module.html#method.update_reward_amount) -  Update the reward amount of the worker/lead.
+//! - [leave_role](./struct.Module.html#method.leave_role) - Leave the role by the active worker/lead.
+//! - [terminate_role](./struct.Module.html#method.terminate_role) - Terminate the worker role by the lead.
 //! - [set_mint_capacity](./struct.Module.html#method.set_mint_capacity) -  Sets the capacity to enable working group budget.
 //!
-//! ### Worker stakes
+//! ### Stakes
 //!
-//! - [slash_worker_stake](./struct.Module.html#method.slash_worker_stake) - Slashes the worker stake.
-//! - [decrease_worker_stake](./struct.Module.html#method.decrease_worker_stake) - Decreases the worker stake and returns the remainder to the worker _role_account_.
-//! - [increase_worker_stake](./struct.Module.html#method.increase_worker_stake) - Increases the worker stake, demands a worker origin.
+//! - [slash_stake](./struct.Module.html#method.slash_stake) - Slashes the worker/lead stake.
+//! - [decrease_stake](./struct.Module.html#method.decrease_stake) - Decreases the worker/lead stake and returns the remainder to the worker _role_account_.
+//! - [increase_stake](./struct.Module.html#method.increase_stake) - Increases the worker stake, demands a worker origin.
 //!
 
 // Ensure we're `no_std` when compiling for Wasm.
@@ -58,14 +56,14 @@ use srml_support::traits::{Currency, ExistenceRequirement, WithdrawReasons};
 use srml_support::{decl_event, decl_module, decl_storage, ensure};
 use system::{ensure_root, ensure_signed};
 
-use crate::types::WorkerExitInitiationOrigin;
+use crate::types::ExitInitiationOrigin;
 use common::constraints::InputValidationLengthConstraint;
 use errors::WrappedError;
 
 pub use errors::Error;
 pub use types::{
-    Lead, OpeningPolicyCommitment, RewardPolicy, Worker, WorkerApplication, WorkerOpening,
-    WorkerRoleStakeProfile,
+    Application, Lead, Opening, OpeningPolicyCommitment, OpeningType, RewardPolicy,
+    RoleStakeProfile, Worker,
 };
 
 /// Alias for the _Lead_ type
@@ -78,18 +76,22 @@ pub type StakeId<T> = <T as stake::Trait>::StakeId;
 pub type MemberId<T> = <T as membership::members::Trait>::MemberId;
 
 /// Workaround for BTreeSet type
-pub type WorkerApplicationIdSet<T> = BTreeSet<WorkerApplicationId<T>>;
+pub type ApplicationIdSet<T> = BTreeSet<ApplicationId<T>>;
 
-/// Type for the identifier for an opening for a worker.
-pub type WorkerOpeningId<T> = <T as hiring::Trait>::OpeningId;
+/// Type for the identifier for an opening for a worker/lead.
+pub type OpeningId<T> = <T as hiring::Trait>::OpeningId;
 
-/// Type for the identifier for an application as a worker.
-pub type WorkerApplicationId<T> = <T as hiring::Trait>::ApplicationId;
+/// Type for the identifier for an application as a worker/lead.
+pub type ApplicationId<T> = <T as hiring::Trait>::ApplicationId;
 
 /// Balance type of runtime
 pub type BalanceOf<T> =
     <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
 
+/// Balance type of runtime reward
+pub type BalanceOfMint<T> =
+    <<T as minting::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
+
 /// Balance type of runtime
 pub type CurrencyOf<T> = <T as stake::Trait>::Currency;
 
@@ -98,18 +100,18 @@ pub type NegativeImbalance<T> =
     <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
 
 /// Alias for the worker application id to the worker id dictionary
-pub type WorkerApplicationIdToWorkerIdMap<T> = BTreeMap<WorkerApplicationId<T>, WorkerId<T>>;
+pub type ApplicationIdToWorkerIdMap<T> = BTreeMap<ApplicationId<T>, WorkerId<T>>;
 
 /// Type identifier for worker role, which must be same as membership actor identifier
 pub type WorkerId<T> = <T as membership::members::Trait>::ActorId;
 
 // Type simplification
-type WorkerOpeningInfo<T> = (
-    WorkerOpening<
+type OpeningInfo<T> = (
+    Opening<
         <T as hiring::Trait>::OpeningId,
         <T as system::Trait>::BlockNumber,
         BalanceOf<T>,
-        WorkerApplicationId<T>,
+        ApplicationId<T>,
     >,
     hiring::Opening<
         BalanceOf<T>,
@@ -119,19 +121,19 @@ type WorkerOpeningInfo<T> = (
 );
 
 // Type simplification
-type WorkerApplicationInfo<T> = (
-    WorkerApplication<
+type ApplicationInfo<T> = (
+    Application<
         <T as system::Trait>::AccountId,
-        WorkerOpeningId<T>,
+        OpeningId<T>,
         MemberId<T>,
         <T as hiring::Trait>::ApplicationId,
     >,
-    WorkerApplicationId<T>,
-    WorkerOpening<
+    ApplicationId<T>,
+    Opening<
         <T as hiring::Trait>::OpeningId,
         <T as system::Trait>::BlockNumber,
         BalanceOf<T>,
-        WorkerApplicationId<T>,
+        ApplicationId<T>,
     >,
 );
 
@@ -165,9 +167,9 @@ decl_event!(
         WorkerId = WorkerId<T>,
         <T as membership::members::Trait>::ActorId,
         <T as system::Trait>::AccountId,
-        WorkerOpeningId = WorkerOpeningId<T>,
-        WorkerApplicationId = WorkerApplicationId<T>,
-        WorkerApplicationIdToWorkerIdMap = WorkerApplicationIdToWorkerIdMap<T>,
+        OpeningId = OpeningId<T>,
+        ApplicationId = ApplicationId<T>,
+        ApplicationIdToWorkerIdMap = ApplicationIdToWorkerIdMap<T>,
         RationaleText = Vec<u8>,
         MintBalanceOf = minting::BalanceOf<T>,
         <T as minting::Trait>::MintId,
@@ -208,57 +210,62 @@ decl_event!(
         /// - Reward account id of the worker.
         WorkerRewardAccountUpdated(ActorId, AccountId),
 
+        /// Emits on updating the reward amount of the worker.
+        /// Params:
+        /// - Member id of the worker.
+        WorkerRewardAmountUpdated(ActorId),
+
         /// Emits on adding new worker opening.
         /// Params:
-        /// - Worker opening id
-        WorkerOpeningAdded(WorkerOpeningId),
+        /// - Opening id
+        OpeningAdded(OpeningId),
 
         /// Emits on accepting application for the worker opening.
         /// Params:
-        /// - Worker opening id
-        AcceptedWorkerApplications(WorkerOpeningId),
+        /// - Opening id
+        AcceptedApplications(OpeningId),
 
         /// Emits on adding the application for the worker opening.
         /// Params:
-        /// - Worker opening id
-        /// - Worker application id
-        AppliedOnWorkerOpening(WorkerOpeningId, WorkerApplicationId),
+        /// - Opening id
+        /// - Application id
+        AppliedOnOpening(OpeningId, ApplicationId),
 
-        /// Emits on withdrawing the application for the worker opening.
+        /// Emits on withdrawing the application for the worker/lead opening.
         /// Params:
         /// - Worker application id
-        WorkerApplicationWithdrawn(WorkerApplicationId),
+        ApplicationWithdrawn(ApplicationId),
 
-        /// Emits on terminating the application for the worker opening.
+        /// Emits on terminating the application for the worker/lead opening.
         /// Params:
         /// - Worker application id
-        WorkerApplicationTerminated(WorkerApplicationId),
+        ApplicationTerminated(ApplicationId),
 
-        /// Emits on beginning the application review for the worker opening.
+        /// Emits on beginning the application review for the worker/lead opening.
         /// Params:
-        /// - Worker opening id
-        BeganWorkerApplicationReview(WorkerOpeningId),
+        /// - Opening id
+        BeganApplicationReview(OpeningId),
 
         /// Emits on filling the worker opening.
         /// Params:
         /// - Worker opening id
         /// - Worker application id to the worker id dictionary
-        WorkerOpeningFilled(WorkerOpeningId, WorkerApplicationIdToWorkerIdMap),
+        OpeningFilled(OpeningId, ApplicationIdToWorkerIdMap),
 
-        /// Emits on increasing the worker stake.
+        /// Emits on increasing the worker/lead stake.
         /// Params:
-        /// - worker id.
-        WorkerStakeIncreased(WorkerId),
+        /// - worker/lead id.
+        StakeIncreased(WorkerId),
 
-        /// Emits on decreasing the worker stake.
+        /// Emits on decreasing the worker/lead stake.
         /// Params:
-        /// - worker id.
-        WorkerStakeDecreased(WorkerId),
+        /// - worker/lead id.
+        StakeDecreased(WorkerId),
 
-        /// Emits on slashing the worker stake.
+        /// Emits on slashing the worker/lead stake.
         /// Params:
-        /// - worker id.
-        WorkerStakeSlashed(WorkerId),
+        /// - worker/lead id.
+        StakeSlashed(WorkerId),
 
         /// Emits on changing working group mint capacity.
         /// Params:
@@ -277,22 +284,22 @@ decl_storage! {
         pub CurrentLead get(current_lead) : Option<LeadOf<T>>;
 
         /// Next identifier value for new worker opening.
-        pub NextWorkerOpeningId get(next_worker_opening_id): WorkerOpeningId<T>;
+        pub NextOpeningId get(next_opening_id): OpeningId<T>;
 
         /// Maps identifier to worker opening.
-        pub WorkerOpeningById get(worker_opening_by_id): linked_map WorkerOpeningId<T> => WorkerOpening<T::OpeningId, T::BlockNumber, BalanceOf<T>, WorkerApplicationId<T>>;
+        pub OpeningById get(opening_by_id): linked_map OpeningId<T> => Opening<T::OpeningId, T::BlockNumber, BalanceOf<T>, ApplicationId<T>>;
 
         /// Opening human readable text length limits
         pub OpeningHumanReadableText get(opening_human_readable_text): InputValidationLengthConstraint;
 
         /// Maps identifier to worker application on opening.
-        pub WorkerApplicationById get(worker_application_by_id) : linked_map WorkerApplicationId<T> => WorkerApplication<T::AccountId, WorkerOpeningId<T>, T::MemberId, T::ApplicationId>;
+        pub ApplicationById get(application_by_id) : linked_map ApplicationId<T> => Application<T::AccountId, OpeningId<T>, T::MemberId, T::ApplicationId>;
 
         /// Next identifier value for new worker application.
-        pub NextWorkerApplicationId get(next_worker_application_id) : WorkerApplicationId<T>;
+        pub NextApplicationId get(next_application_id) : ApplicationId<T>;
 
         /// Worker application human readable text length limits
-        pub WorkerApplicationHumanReadableText get(worker_application_human_readable_text) : InputValidationLengthConstraint;
+        pub WorkerApplicationHumanReadableText get(application_human_readable_text) : InputValidationLengthConstraint;
 
         /// Maps identifier to corresponding worker.
         pub WorkerById get(worker_by_id) : linked_map WorkerId<T> => WorkerOf<T>;
@@ -365,8 +372,8 @@ decl_module! {
             Self::deposit_event(RawEvent::LeaderUnset(lead.member_id, lead.role_account_id));
         }
 
-        /// Update the associated role account of the active worker.
-        pub fn update_worker_role_account(
+        /// Update the associated role account of the active worker/lead.
+        pub fn update_role_account(
             origin,
             worker_id: WorkerId<T>,
             new_role_account_id: T::AccountId
@@ -393,7 +400,7 @@ decl_module! {
         }
 
         /// Update the reward account associated with a set reward relationship for the active worker.
-        pub fn update_worker_reward_account(
+        pub fn update_reward_account(
             origin,
             worker_id: WorkerId<T>,
             new_reward_account_id: T::AccountId
@@ -422,8 +429,41 @@ decl_module! {
             Self::deposit_event(RawEvent::WorkerRewardAccountUpdated(worker_id, new_reward_account_id));
         }
 
+        /// Update the reward amount associated with a set reward relationship for the active worker.
+        pub fn update_reward_amount(
+            origin,
+            worker_id: WorkerId<T>,
+            new_amount: BalanceOfMint<T>
+        ) {
+            // Ensure lead is set and is origin signer
+            Self::ensure_origin_is_active_leader(origin)?;
+
+            // Ensuring worker actually exists
+            let worker = Self::ensure_worker_exists(&worker_id)?;
+
+            // Ensure the worker actually has a recurring reward
+            let relationship_id = Self::ensure_worker_has_recurring_reward(&worker)?;
+
+            //
+            // == MUTATION SAFE ==
+            //
+
+            // Update only the reward account.
+            ensure_on_wrapped_error!(
+                recurringrewards::Module::<T>::set_reward_relationship(
+                    relationship_id,
+                    None, // new_account
+                    Some(new_amount), // new_payout
+                    None, //new_next_payment_at
+                    None) //new_payout_interval
+            )?;
+
+            // Trigger event
+            Self::deposit_event(RawEvent::WorkerRewardAmountUpdated(worker_id));
+        }
+
         /// Leave the role by the active worker.
-        pub fn leave_worker_role(
+        pub fn leave_role(
             origin,
             worker_id: WorkerId<T>,
             rationale_text: Vec<u8>
@@ -438,13 +478,13 @@ decl_module! {
             Self::deactivate_worker(
                 &worker_id,
                 &active_worker,
-                &WorkerExitInitiationOrigin::Worker,
+                &ExitInitiationOrigin::Worker,
                 &rationale_text
             )?;
         }
 
         /// Terminate the active worker by the lead.
-        pub fn terminate_worker_role(
+        pub fn terminate_role(
             origin,
             worker_id: WorkerId<T>,
             rationale_text: Vec<u8>
@@ -466,7 +506,7 @@ decl_module! {
             Self::deactivate_worker(
                 &worker_id,
                 &worker,
-                &WorkerExitInitiationOrigin::Lead,
+                &ExitInitiationOrigin::Lead,
                 &rationale_text
             )?;
         }
@@ -474,15 +514,15 @@ decl_module! {
         // ****************** Hiring flow **********************
 
          /// Add an opening for a worker role.
-        pub fn add_worker_opening(
+        pub fn add_opening(
             origin,
             activate_at: hiring::ActivateOpeningAt<T::BlockNumber>,
             commitment: OpeningPolicyCommitment<T::BlockNumber,
             BalanceOf<T>>,
-            human_readable_text: Vec<u8>
+            human_readable_text: Vec<u8>,
+            opening_type: OpeningType,
         ){
-            // Ensure lead is set and is origin signer
-            Self::ensure_origin_is_active_leader(origin)?;
+            Self::ensure_origin_for_opening_type(origin, opening_type)?;
 
             Self::ensure_opening_human_readable_text_is_valid(&human_readable_text)?;
 
@@ -506,35 +546,34 @@ decl_module! {
                     human_readable_text,
             ))?;
 
-            let new_worker_opening_id = NextWorkerOpeningId::<T, I>::get();
+            let new_opening_id = NextOpeningId::<T, I>::get();
 
             // Create and add worker opening.
-            let new_opening_by_id = WorkerOpening::<WorkerOpeningId<T>, T::BlockNumber, BalanceOf<T>, WorkerApplicationId<T>> {
+            let new_opening_by_id = Opening::<OpeningId<T>, T::BlockNumber, BalanceOf<T>, ApplicationId<T>> {
                 opening_id,
-                worker_applications: BTreeSet::new(),
-                policy_commitment
+                applications: BTreeSet::new(),
+                policy_commitment,
+                opening_type,
             };
 
-            WorkerOpeningById::<T, I>::insert(new_worker_opening_id, new_opening_by_id);
+            OpeningById::<T, I>::insert(new_opening_id, new_opening_by_id);
 
-            // Update NextWorkerOpeningId
-            NextWorkerOpeningId::<T, I>::mutate(|id| *id += <WorkerOpeningId<T> as One>::one());
+            // Update NextOpeningId
+            NextOpeningId::<T, I>::mutate(|id| *id += <OpeningId<T> as One>::one());
 
             // Trigger event
-            Self::deposit_event(RawEvent::WorkerOpeningAdded(new_worker_opening_id));
+            Self::deposit_event(RawEvent::OpeningAdded(new_opening_id));
         }
 
         /// Begin accepting worker applications to an opening that is active.
-        pub fn accept_worker_applications(origin, worker_opening_id: WorkerOpeningId<T>)  {
-
-            // Ensure lead is set and is origin signer
-            Self::ensure_origin_is_active_leader(origin)?;
-
+        pub fn accept_applications(origin, opening_id: OpeningId<T>)  {
             // Ensure opening exists in this working group
             // NB: Even though call to hiring module will have implicit check for
             // existence of opening as well, this check is to make sure that the opening is for
             // this working group, not something else.
-            let (worker_opening, _opening) = Self::ensure_worker_opening_exists(&worker_opening_id)?;
+            let (opening, _opening) = Self::ensure_opening_exists(&opening_id)?;
+
+            Self::ensure_origin_for_opening_type(origin, opening.opening_type)?;
 
             // Attempt to begin accepting applications
             // NB: Combined ensure check and mutation in hiring module
@@ -544,19 +583,19 @@ decl_module! {
             //
 
             ensure_on_wrapped_error!(
-                hiring::Module::<T>::begin_accepting_applications(worker_opening.opening_id)
+                hiring::Module::<T>::begin_accepting_applications(opening.opening_id)
             )?;
 
 
             // Trigger event
-            Self::deposit_event(RawEvent::AcceptedWorkerApplications(worker_opening_id));
+            Self::deposit_event(RawEvent::AcceptedApplications(opening_id));
         }
 
         /// Apply on a worker opening.
-        pub fn apply_on_worker_opening(
+        pub fn apply_on_opening(
             origin,
             member_id: T::MemberId,
-            worker_opening_id: WorkerOpeningId<T>,
+            opening_id: OpeningId<T>,
             role_account: T::AccountId,
             opt_role_stake_balance: Option<BalanceOf<T>>,
             opt_application_stake_balance: Option<BalanceOf<T>>,
@@ -576,7 +615,7 @@ decl_module! {
             );
 
             // Ensure worker opening exists
-            let (worker_opening, _opening) = Self::ensure_worker_opening_exists(&worker_opening_id)?;
+            let (opening, _opening) = Self::ensure_opening_exists(&opening_id)?;
 
             // Ensure that there is sufficient balance to cover stake proposed
             Self::ensure_can_make_stake_imbalance(
@@ -585,16 +624,16 @@ decl_module! {
                 .map_err(|_| Error::InsufficientBalanceToApply)?;
 
             // Ensure application text is valid
-            Self::ensure_worker_application_text_is_valid(&human_readable_text)?;
+            Self::ensure_application_text_is_valid(&human_readable_text)?;
 
             // Ensure application can actually be added
             ensure_on_wrapped_error!(
-                hiring::Module::<T>::ensure_can_add_application(worker_opening.opening_id, opt_role_stake_balance, opt_application_stake_balance)
+                hiring::Module::<T>::ensure_can_add_application(opening.opening_id, opt_role_stake_balance, opt_application_stake_balance)
             )?;
 
             // Ensure member does not have an active application to this opening
             Self::ensure_member_has_no_active_application_on_opening(
-                worker_opening.worker_applications,
+                opening.applications,
                 member_id
             )?;
 
@@ -608,7 +647,7 @@ decl_module! {
 
             // Call hiring module to add application
             let add_application_result = hiring::Module::<T>::add_application(
-                worker_opening.opening_id,
+                opening.opening_id,
                 opt_role_stake_imbalance,
                 opt_application_stake_imbalance,
                 human_readable_text
@@ -619,41 +658,41 @@ decl_module! {
 
             let application_id = add_application_result.unwrap().application_id_added;
 
-            // Get id of new worker application
-            let new_worker_application_id = NextWorkerApplicationId::<T, I>::get();
+            // Get id of new worker/lead application
+            let new_application_id = NextApplicationId::<T, I>::get();
 
-            // Make worker application
-            let worker_application = WorkerApplication::new(&role_account, &worker_opening_id, &member_id, &application_id);
+            // Make worker/lead application
+            let application = Application::new(&role_account, &opening_id, &member_id, &application_id);
 
             // Store application
-            WorkerApplicationById::<T, I>::insert(new_worker_application_id, worker_application);
+            ApplicationById::<T, I>::insert(new_application_id, application);
 
-            // Update next worker application identifier value
-            NextWorkerApplicationId::<T, I>::mutate(|id| *id += <WorkerApplicationId<T> as One>::one());
+            // Update next application identifier value
+            NextApplicationId::<T, I>::mutate(|id| *id += <ApplicationId<T> as One>::one());
 
             // Add application to set of application in worker opening
-            WorkerOpeningById::<T, I>::mutate(worker_opening_id, |worker_opening| {
-                worker_opening.worker_applications.insert(new_worker_application_id);
+            OpeningById::<T, I>::mutate(opening_id, |opening| {
+                opening.applications.insert(new_application_id);
             });
 
             // Trigger event
-            Self::deposit_event(RawEvent::AppliedOnWorkerOpening(worker_opening_id, new_worker_application_id));
+            Self::deposit_event(RawEvent::AppliedOnOpening(opening_id, new_application_id));
         }
 
         /// Withdraw the worker application. Can be done by the worker itself only.
-        pub fn withdraw_worker_application(
+        pub fn withdraw_application(
             origin,
-            worker_application_id: WorkerApplicationId<T>
+            application_id: ApplicationId<T>
         ) {
             // Ensuring worker application actually exists
-            let (worker_application, _, worker_opening) = Self::ensure_worker_application_exists(&worker_application_id)?;
+            let (application, _, opening) = Self::ensure_application_exists(&application_id)?;
 
             // Ensure that it is signed
             let signer_account = ensure_signed(origin)?;
 
             // Ensure that signer is applicant role account
             ensure!(
-                signer_account == worker_application.role_account,
+                signer_account == application.role_account,
                 Error::OriginIsNotApplicant
             );
 
@@ -665,36 +704,36 @@ decl_module! {
             // NB: Combined ensure check and mutation in hiring module
             ensure_on_wrapped_error!(
                 hiring::Module::<T>::deactive_application(
-                    worker_application.application_id,
-                    worker_opening.policy_commitment.exit_worker_role_application_stake_unstaking_period,
-                    worker_opening.policy_commitment.exit_worker_role_stake_unstaking_period
+                    application.hiring_application_id,
+                    opening.policy_commitment.exit_worker_role_application_stake_unstaking_period,
+                    opening.policy_commitment.exit_worker_role_stake_unstaking_period
                 )
             )?;
 
 
             // Trigger event
-            Self::deposit_event(RawEvent::WorkerApplicationWithdrawn(worker_application_id));
+            Self::deposit_event(RawEvent::ApplicationWithdrawn(application_id));
         }
 
         /// Terminate the worker application. Can be done by the lead only.
-        pub fn terminate_worker_application(
+        pub fn terminate_application(
             origin,
-            worker_application_id: WorkerApplicationId<T>
+            application_id: ApplicationId<T>
         ) {
 
             // Ensure lead is set and is origin signer
             Self::ensure_origin_is_active_leader(origin)?;
 
             // Ensuring worker application actually exists
-            let (worker_application, _, worker_opening) = Self::ensure_worker_application_exists(&worker_application_id)?;
+            let (application, _, opening) = Self::ensure_application_exists(&application_id)?;
 
             // Attempt to deactivate application
             // NB: Combined ensure check and mutation in hiring module
             ensure_on_wrapped_error!(
                 hiring::Module::<T>::deactive_application(
-                    worker_application.application_id,
-                    worker_opening.policy_commitment.terminate_worker_application_stake_unstaking_period,
-                    worker_opening.policy_commitment.terminate_worker_role_stake_unstaking_period
+                    application.hiring_application_id,
+                    opening.policy_commitment.terminate_application_stake_unstaking_period,
+                    opening.policy_commitment.terminate_worker_role_stake_unstaking_period
                 )
             )?;
 
@@ -703,20 +742,18 @@ decl_module! {
             //
 
             // Trigger event
-            Self::deposit_event(RawEvent::WorkerApplicationTerminated(worker_application_id));
+            Self::deposit_event(RawEvent::ApplicationTerminated(application_id));
         }
 
         /// Begin reviewing, and therefore not accepting new applications.
-        pub fn begin_worker_applicant_review(origin, worker_opening_id: WorkerOpeningId<T>) {
-
-            // Ensure lead is set and is origin signer
-            Self::ensure_origin_is_active_leader(origin)?;
-
+        pub fn begin_applicant_review(origin, opening_id: OpeningId<T>) {
             // Ensure opening exists
             // NB: Even though call to hiring modul will have implicit check for
             // existence of opening as well, this check is to make sure that the opening is for
             // this working group, not something else.
-            let (worker_opening, _opening) = Self::ensure_worker_opening_exists(&worker_opening_id)?;
+            let (opening, _opening) = Self::ensure_opening_exists(&opening_id)?;
+
+            Self::ensure_origin_for_opening_type(origin, opening.opening_type)?;
 
             //
             // == MUTATION SAFE ==
@@ -725,25 +762,24 @@ decl_module! {
             // Attempt to begin review of applications
             // NB: Combined ensure check and mutation in hiring module
             ensure_on_wrapped_error!(
-                hiring::Module::<T>::begin_review(worker_opening.opening_id)
+                hiring::Module::<T>::begin_review(opening.opening_id)
                 )?;
 
             // Trigger event
-            Self::deposit_event(RawEvent::BeganWorkerApplicationReview(worker_opening_id));
+            Self::deposit_event(RawEvent::BeganApplicationReview(opening_id));
         }
 
-        /// Fill opening for worker.
-        pub fn fill_worker_opening(
+        /// Fill opening for worker/lead.
+        pub fn fill_opening(
             origin,
-            worker_opening_id: WorkerOpeningId<T>,
-            successful_worker_application_ids: WorkerApplicationIdSet<T>,
+            opening_id: OpeningId<T>,
+            successful_application_ids: ApplicationIdSet<T>,
             reward_policy: Option<RewardPolicy<minting::BalanceOf<T>, T::BlockNumber>>
         ) {
-            // Ensure lead is set and is origin signer
-            Self::ensure_origin_is_active_leader(origin)?;
-
             // Ensure worker opening exists
-            let (worker_opening, _) = Self::ensure_worker_opening_exists(&worker_opening_id)?;
+            let (opening, _) = Self::ensure_opening_exists(&opening_id)?;
+
+            Self::ensure_origin_for_opening_type(origin, opening.opening_type)?;
 
             // Ensure a mint exists if lead is providing a reward for positions being filled
             let create_reward_settings = if let Some(policy) = reward_policy {
@@ -751,11 +787,11 @@ decl_module! {
                 let mint_id = Self::mint();
 
                 // Technically this is a bug-check and should not be here.
-                ensure!(<minting::Mints<T>>::exists(mint_id), Error::FillWorkerOpeningMintDoesNotExist);
+                ensure!(<minting::Mints<T>>::exists(mint_id), Error::FillOpeningMintDoesNotExist);
 
                 // Make sure valid parameters are selected for next payment at block number
                 ensure!(policy.next_payment_at_block > <system::Module<T>>::block_number(),
-                    Error::FillWorkerOpeningInvalidNextPaymentBlock);
+                    Error::FillOpeningInvalidNextPaymentBlock);
 
                 // The verified reward settings to use
                 Some((mint_id, policy))
@@ -764,15 +800,15 @@ decl_module! {
             };
 
             // Make iterator over successful worker application
-            let successful_iter = successful_worker_application_ids
+            let successful_iter = successful_application_ids
                                     .iter()
                                     // recover worker application from id
-                                    .map(|worker_application_id| { Self::ensure_worker_application_exists(worker_application_id)})
+                                    .map(|application_id| { Self::ensure_application_exists(application_id)})
                                     // remove Err cases, i.e. non-existing applications
                                     .filter_map(|result| result.ok());
 
             // Count number of successful workers provided
-            let num_provided_successful_worker_application_ids = successful_worker_application_ids.len();
+            let num_provided_successful_application_ids = successful_application_ids.len();
 
             // Ensure all worker applications exist
             let number_of_successful_applications = successful_iter
@@ -780,24 +816,24 @@ decl_module! {
                                                     .count();
 
             ensure!(
-                number_of_successful_applications == num_provided_successful_worker_application_ids,
+                number_of_successful_applications == num_provided_successful_application_ids,
                 Error::SuccessfulWorkerApplicationDoesNotExist
             );
 
             // Attempt to fill opening
             let successful_application_ids = successful_iter
                                             .clone()
-                                            .map(|(successful_worker_application, _, _)| successful_worker_application.application_id)
+                                            .map(|(successful_application, _, _)| successful_application.hiring_application_id)
                                             .collect::<BTreeSet<_>>();
 
             // NB: Combined ensure check and mutation in hiring module
             ensure_on_wrapped_error!(
                 hiring::Module::<T>::fill_opening(
-                    worker_opening.opening_id,
+                    opening.opening_id,
                     successful_application_ids,
-                    worker_opening.policy_commitment.fill_opening_successful_applicant_application_stake_unstaking_period,
-                    worker_opening.policy_commitment.fill_opening_failed_applicant_application_stake_unstaking_period,
-                    worker_opening.policy_commitment.fill_opening_failed_applicant_role_stake_unstaking_period
+                    opening.policy_commitment.fill_opening_successful_applicant_application_stake_unstaking_period,
+                    opening.policy_commitment.fill_opening_failed_applicant_application_stake_unstaking_period,
+                    opening.policy_commitment.fill_opening_failed_applicant_role_stake_unstaking_period
                 )
             )?;
 
@@ -805,11 +841,11 @@ decl_module! {
             // == MUTATION SAFE ==
             //
 
-            let mut worker_application_id_to_worker_id = BTreeMap::new();
+            let mut application_id_to_worker_id = BTreeMap::new();
 
             successful_iter
             .clone()
-            .for_each(|(successful_worker_application, id, _)| {
+            .for_each(|(successful_application, id, _)| {
                 // Create a reward relationship
                 let reward_relationship = if let Some((mint_id, checked_policy)) = create_reward_settings.clone() {
 
@@ -817,7 +853,7 @@ decl_module! {
                     let recipient = <recurringrewards::Module<T>>::add_recipient();
 
                     // member must exist, since it was checked that it can enter the role
-                    let member_profile = <membership::members::Module<T>>::member_profile(successful_worker_application.member_id).unwrap();
+                    let member_profile = <membership::members::Module<T>>::member_profile(successful_application.member_id).unwrap();
 
                     // rewards are deposited in the member's root account
                     let reward_destination_account = member_profile.root_account;
@@ -838,16 +874,16 @@ decl_module! {
                 };
 
                 // Get possible stake for role
-                let application = hiring::ApplicationById::<T>::get(successful_worker_application.application_id);
+                let application = hiring::ApplicationById::<T>::get(successful_application.hiring_application_id);
 
                 // Staking profile for worker
                 let stake_profile =
                     if let Some(ref stake_id) = application.active_role_staking_id {
                         Some(
-                            WorkerRoleStakeProfile::new(
+                            RoleStakeProfile::new(
                                 stake_id,
-                                &worker_opening.policy_commitment.terminate_worker_role_stake_unstaking_period,
-                                &worker_opening.policy_commitment.exit_worker_role_stake_unstaking_period
+                                &opening.policy_commitment.terminate_worker_role_stake_unstaking_period,
+                                &opening.policy_commitment.exit_worker_role_stake_unstaking_period
                             )
                         )
                     } else {
@@ -859,30 +895,30 @@ decl_module! {
 
                 // Construct worker
                 let worker = Worker::new(
-                    &successful_worker_application.member_id,
-                    &successful_worker_application.role_account,
+                    &successful_application.member_id,
+                    &successful_application.role_account,
                     &reward_relationship,
                     &stake_profile,
                 );
 
-                // Store worker
+                // Store a worker
                 <WorkerById<T, I>>::insert(new_worker_id, worker);
 
                 // Update next worker id
                 <NextWorkerId<T, I>>::mutate(|id| *id += <WorkerId<T> as One>::one());
 
-                worker_application_id_to_worker_id.insert(id, new_worker_id);
+                application_id_to_worker_id.insert(id, new_worker_id);
             });
 
             // Trigger event
-            Self::deposit_event(RawEvent::WorkerOpeningFilled(worker_opening_id, worker_application_id_to_worker_id));
+            Self::deposit_event(RawEvent::OpeningFilled(opening_id, application_id_to_worker_id));
         }
 
-        // ****************** Worker stakes **********************
+        // ****************** Stakes **********************
 
         /// Slashes the worker stake, demands a leader origin. No limits, no actions on zero stake.
         /// If slashing balance greater than the existing stake - stake is slashed to zero.
-        pub fn slash_worker_stake(origin, worker_id: WorkerId<T>, balance: BalanceOf<T>) {
+        pub fn slash_stake(origin, worker_id: WorkerId<T>, balance: BalanceOf<T>) {
             Self::ensure_origin_is_active_leader(origin)?;
 
             let worker = Self::ensure_worker_exists(&worker_id)?;
@@ -904,12 +940,12 @@ decl_module! {
                 )
             )?;
 
-            Self::deposit_event(RawEvent::WorkerStakeSlashed(worker_id));
+            Self::deposit_event(RawEvent::StakeSlashed(worker_id));
         }
 
-        /// Decreases the worker stake and returns the remainder to the worker role_account,
+        /// Decreases the worker/lead stake and returns the remainder to the worker role_account,
         /// demands a leader origin. Can be decreased to zero, no actions on zero stake.
-        pub fn decrease_worker_stake(origin, worker_id: WorkerId<T>, balance: BalanceOf<T>) {
+        pub fn decrease_stake(origin, worker_id: WorkerId<T>, balance: BalanceOf<T>) {
             Self::ensure_origin_is_active_leader(origin)?;
 
             let worker = Self::ensure_worker_exists(&worker_id)?;
@@ -931,12 +967,12 @@ decl_module! {
                 )
             )?;
 
-            Self::deposit_event(RawEvent::WorkerStakeDecreased(worker_id));
+            Self::deposit_event(RawEvent::StakeDecreased(worker_id));
         }
 
-        /// Increases the worker stake, demands a worker origin. Transfers tokens from the worker
+        /// Increases the worker/lead stake, demands a worker origin. Transfers tokens from the worker
         /// role_account to the stake. No limits on the stake.
-        pub fn increase_worker_stake(origin, worker_id: WorkerId<T>, balance: BalanceOf<T>) {
+        pub fn increase_stake(origin, worker_id: WorkerId<T>, balance: BalanceOf<T>) {
             // Checks worker origin, worker existence
             let worker = Self::ensure_worker_signed(origin, &worker_id)?;
 
@@ -957,7 +993,7 @@ decl_module! {
                 )
             )?;
 
-            Self::deposit_event(RawEvent::WorkerStakeIncreased(worker_id));
+            Self::deposit_event(RawEvent::StakeIncreased(worker_id));
         }
 
         /// Sets the capacity to enable working group budget.
@@ -1013,6 +1049,24 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         <WorkerById<T, I>>::enumerate()
             .map(|(worker_id, _)| worker_id)
             .collect()
+
+        //TODO not lead
+    }
+
+    fn ensure_origin_for_opening_type(
+        origin: T::Origin,
+        opening_type: OpeningType,
+    ) -> Result<(), Error> {
+        match opening_type {
+            OpeningType::Worker => {
+                // Ensure lead is set and is origin signer.
+                Self::ensure_origin_is_active_leader(origin)
+            }
+            OpeningType::Leader => {
+                // Council proposal.
+                ensure_root(origin).map_err(|err| err.into())
+            }
+        }
     }
 
     fn ensure_lead_is_set() -> Result<Lead<MemberId<T>, T::AccountId>, Error> {
@@ -1043,19 +1097,17 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         Self::ensure_is_lead_account(signer)
     }
 
-    fn ensure_worker_opening_exists(
-        worker_opening_id: &WorkerOpeningId<T>,
-    ) -> Result<WorkerOpeningInfo<T>, Error> {
+    fn ensure_opening_exists(opening_id: &OpeningId<T>) -> Result<OpeningInfo<T>, Error> {
         ensure!(
-            WorkerOpeningById::<T, I>::exists(worker_opening_id),
-            Error::WorkerOpeningDoesNotExist
+            OpeningById::<T, I>::exists(opening_id),
+            Error::OpeningDoesNotExist
         );
 
-        let worker_opening = WorkerOpeningById::<T, I>::get(worker_opening_id);
+        let opening = OpeningById::<T, I>::get(opening_id);
 
-        let opening = hiring::OpeningById::<T>::get(worker_opening.opening_id);
+        let hiring_opening = hiring::OpeningById::<T>::get(opening.opening_id);
 
-        Ok((worker_opening, opening))
+        Ok((opening, hiring_opening))
     }
 
     fn make_stake_opt_imbalance(
@@ -1079,17 +1131,17 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
     }
 
     fn ensure_member_has_no_active_application_on_opening(
-        worker_applications: WorkerApplicationIdSet<T>,
+        applications: ApplicationIdSet<T>,
         member_id: T::MemberId,
     ) -> Result<(), Error> {
-        for worker_application_id in worker_applications {
-            let worker_application = WorkerApplicationById::<T, I>::get(worker_application_id);
+        for application_id in applications {
+            let application = ApplicationById::<T, I>::get(application_id);
             // Look for application by the member for the opening
-            if worker_application.member_id != member_id {
+            if application.member_id != member_id {
                 continue;
             }
             // Get application details
-            let application = <hiring::ApplicationById<T>>::get(worker_application.application_id);
+            let application = <hiring::ApplicationById<T>>::get(application.hiring_application_id);
             // Return error if application is in active stage
             if application.stage == hiring::ApplicationStage::Active {
                 return Err(Error::MemberHasActiveApplicationOnOpening);
@@ -1099,7 +1151,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         Ok(())
     }
 
-    fn ensure_worker_application_text_is_valid(text: &[u8]) -> Result<(), Error> {
+    fn ensure_application_text_is_valid(text: &[u8]) -> Result<(), Error> {
         <WorkerApplicationHumanReadableText<I>>::get()
             .ensure_valid(
                 text.len(),
@@ -1151,19 +1203,19 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         }
     }
 
-    fn ensure_worker_application_exists(
-        worker_application_id: &WorkerApplicationId<T>,
-    ) -> Result<WorkerApplicationInfo<T>, Error> {
+    fn ensure_application_exists(
+        application_id: &ApplicationId<T>,
+    ) -> Result<ApplicationInfo<T>, Error> {
         ensure!(
-            WorkerApplicationById::<T, I>::exists(worker_application_id),
+            ApplicationById::<T, I>::exists(application_id),
             Error::WorkerApplicationDoesNotExist
         );
 
-        let worker_application = WorkerApplicationById::<T, I>::get(worker_application_id);
+        let application = ApplicationById::<T, I>::get(application_id);
 
-        let worker_opening = WorkerOpeningById::<T, I>::get(worker_application.worker_opening_id);
+        let opening = OpeningById::<T, I>::get(application.opening_id);
 
-        Ok((worker_application, *worker_application_id, worker_opening))
+        Ok((application, *application_id, opening))
     }
 
     /// Ensures the origin contains signed account that belongs to existing worker.
@@ -1210,7 +1262,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
     fn deactivate_worker(
         worker_id: &WorkerId<T>,
         worker: &WorkerOf<T>,
-        exit_initiation_origin: &WorkerExitInitiationOrigin,
+        exit_initiation_origin: &ExitInitiationOrigin,
         rationale_text: &[u8],
     ) -> Result<(), Error> {
         // Stop any possible recurring rewards
@@ -1225,8 +1277,8 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
         if let Some(ref stake_profile) = worker.role_stake_profile {
             // Determine unstaking period based on who initiated deactivation
             let unstaking_period = match exit_initiation_origin {
-                WorkerExitInitiationOrigin::Lead => stake_profile.termination_unstaking_period,
-                WorkerExitInitiationOrigin::Worker => stake_profile.exit_unstaking_period,
+                ExitInitiationOrigin::Lead => stake_profile.termination_unstaking_period,
+                ExitInitiationOrigin::Worker => stake_profile.exit_unstaking_period,
             };
 
             // Unstake
@@ -1240,10 +1292,10 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
 
         // Trigger the event
         let event = match exit_initiation_origin {
-            WorkerExitInitiationOrigin::Lead => {
+            ExitInitiationOrigin::Lead => {
                 RawEvent::TerminatedWorker(*worker_id, rationale_text.to_vec())
             }
-            WorkerExitInitiationOrigin::Worker => {
+            ExitInitiationOrigin::Worker => {
                 RawEvent::WorkerExited(*worker_id, rationale_text.to_vec())
             }
         };

+ 81 - 46
runtime-modules/working-group/src/tests/fixtures.rs

@@ -2,8 +2,8 @@ use super::mock::{
     Balances, Membership, System, Test, TestEvent, TestWorkingGroup, TestWorkingGroupInstance,
 };
 use crate::types::{
-    OpeningPolicyCommitment, RewardPolicy, Worker, WorkerApplication, WorkerOpening,
-    WorkerRoleStakeProfile,
+    Application, Opening, OpeningPolicyCommitment, OpeningType, RewardPolicy, RoleStakeProfile,
+    Worker,
 };
 use crate::Error;
 use crate::RawEvent;
@@ -41,7 +41,7 @@ impl IncreaseWorkerStakeFixture {
         let stake_id = 0;
         let old_stake = <stake::Module<Test>>::stakes(stake_id);
         let old_balance = Balances::free_balance(&self.account_id);
-        let actual_result = TestWorkingGroup::increase_worker_stake(
+        let actual_result = TestWorkingGroup::increase_stake(
             self.origin.clone().into(),
             self.worker_id,
             self.balance,
@@ -96,7 +96,7 @@ impl TerminateWorkerRoleFixture {
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
         <crate::WorkerExitRationaleText<TestWorkingGroupInstance>>::put(self.constraint.clone());
 
-        let actual_result = TestWorkingGroup::terminate_worker_role(
+        let actual_result = TestWorkingGroup::terminate_role(
             self.origin.clone().into(),
             self.worker_id,
             self.text.clone(),
@@ -131,7 +131,7 @@ impl LeaveWorkerRoleFixture {
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
         let rationale_text = b"rationale_text".to_vec();
-        let actual_result = TestWorkingGroup::leave_worker_role(
+        let actual_result = TestWorkingGroup::leave_role(
             self.origin.clone().into(),
             self.worker_id,
             rationale_text.clone(),
@@ -144,6 +144,35 @@ impl LeaveWorkerRoleFixture {
     }
 }
 
+pub struct UpdateWorkerRewardAmountFixture {
+    worker_id: u64,
+    amount: u64,
+    origin: RawOrigin<u64>,
+}
+
+impl UpdateWorkerRewardAmountFixture {
+    pub fn default_for_worker_id(worker_id: u64) -> Self {
+        UpdateWorkerRewardAmountFixture {
+            worker_id,
+            amount: 100,
+            origin: RawOrigin::Signed(1),
+        }
+    }
+    pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
+        UpdateWorkerRewardAmountFixture { origin, ..self }
+    }
+
+    pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
+        assert_eq!(
+            TestWorkingGroup::update_reward_amount(
+                self.origin.clone().into(),
+                self.worker_id,
+                self.amount
+            ),
+            expected_result
+        );
+    }
+}
 pub struct UpdateWorkerRewardAccountFixture {
     worker_id: u64,
     new_role_account_id: u64,
@@ -164,7 +193,7 @@ impl UpdateWorkerRewardAccountFixture {
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
         assert_eq!(
-            TestWorkingGroup::update_worker_reward_account(
+            TestWorkingGroup::update_reward_account(
                 self.origin.clone().into(),
                 self.worker_id,
                 self.new_role_account_id
@@ -193,7 +222,7 @@ impl UpdateWorkerRoleAccountFixture {
     }
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
-        let actual_result = TestWorkingGroup::update_worker_role_account(
+        let actual_result = TestWorkingGroup::update_role_account(
             self.origin.clone().into(),
             self.worker_id,
             self.new_role_account_id,
@@ -230,7 +259,7 @@ pub fn create_mint() -> u64 {
 pub struct FillWorkerOpeningFixture {
     origin: RawOrigin<u64>,
     opening_id: u64,
-    successful_worker_application_ids: BTreeSet<u64>,
+    successful_application_ids: BTreeSet<u64>,
     role_account: u64,
     reward_policy: Option<RewardPolicy<u64, u64>>,
 }
@@ -242,7 +271,7 @@ impl FillWorkerOpeningFixture {
         FillWorkerOpeningFixture {
             origin: RawOrigin::Signed(1),
             opening_id,
-            successful_worker_application_ids: application_ids,
+            successful_application_ids: application_ids,
             role_account: 1,
             reward_policy: None,
         }
@@ -261,10 +290,10 @@ impl FillWorkerOpeningFixture {
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) -> u64 {
         let saved_worker_next_id = TestWorkingGroup::next_worker_id();
-        let actual_result = TestWorkingGroup::fill_worker_opening(
+        let actual_result = TestWorkingGroup::fill_opening(
             self.origin.clone().into(),
             self.opening_id,
-            self.successful_worker_application_ids.clone(),
+            self.successful_application_ids.clone(),
             self.reward_policy.clone(),
         );
         assert_eq!(actual_result.clone(), expected_result);
@@ -273,7 +302,7 @@ impl FillWorkerOpeningFixture {
             assert_eq!(TestWorkingGroup::next_worker_id(), saved_worker_next_id + 1);
             let worker_id = saved_worker_next_id;
 
-            let opening = TestWorkingGroup::worker_opening_by_id(self.opening_id);
+            let opening = TestWorkingGroup::opening_by_id(self.opening_id);
 
             let role_stake_profile = if opening
                 .policy_commitment
@@ -282,7 +311,7 @@ impl FillWorkerOpeningFixture {
                 || opening.policy_commitment.role_staking_policy.is_some()
             {
                 let stake_id = 0;
-                Some(WorkerRoleStakeProfile::new(
+                Some(RoleStakeProfile::new(
                     &stake_id,
                     &opening
                         .policy_commitment
@@ -328,10 +357,8 @@ impl BeginReviewWorkerApplicationsFixture {
         BeginReviewWorkerApplicationsFixture { origin, ..self }
     }
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
-        let actual_result = TestWorkingGroup::begin_worker_applicant_review(
-            self.origin.clone().into(),
-            self.opening_id,
-        );
+        let actual_result =
+            TestWorkingGroup::begin_applicant_review(self.origin.clone().into(), self.opening_id);
         assert_eq!(actual_result, expected_result);
     }
 }
@@ -358,7 +385,7 @@ impl TerminateApplicationFixture {
         }
     }
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
-        let actual_result = TestWorkingGroup::terminate_worker_application(
+        let actual_result = TestWorkingGroup::terminate_application(
             self.origin.clone().into(),
             self.worker_application_id,
         );
@@ -387,7 +414,7 @@ impl WithdrawApplicationFixture {
         }
     }
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
-        let actual_result = TestWorkingGroup::withdraw_worker_application(
+        let actual_result = TestWorkingGroup::withdraw_application(
             self.origin.clone().into(),
             self.worker_application_id,
         );
@@ -465,8 +492,8 @@ impl ApplyOnWorkerOpeningFixture {
     }
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) -> u64 {
-        let saved_application_next_id = TestWorkingGroup::next_worker_application_id();
-        let actual_result = TestWorkingGroup::apply_on_worker_opening(
+        let saved_application_next_id = TestWorkingGroup::next_application_id();
+        let actual_result = TestWorkingGroup::apply_on_opening(
             self.origin.clone().into(),
             self.member_id,
             self.worker_opening_id,
@@ -479,26 +506,24 @@ impl ApplyOnWorkerOpeningFixture {
 
         if actual_result.is_ok() {
             assert_eq!(
-                TestWorkingGroup::next_worker_application_id(),
+                TestWorkingGroup::next_application_id(),
                 saved_application_next_id + 1
             );
             let application_id = saved_application_next_id;
 
-            let actual_application = TestWorkingGroup::worker_application_by_id(application_id);
+            let actual_application = TestWorkingGroup::application_by_id(application_id);
 
-            let expected_application = WorkerApplication {
+            let expected_application = Application {
                 role_account: self.role_account,
-                worker_opening_id: self.worker_opening_id,
+                opening_id: self.worker_opening_id,
                 member_id: self.member_id,
-                application_id,
+                hiring_application_id: application_id,
             };
 
             assert_eq!(actual_application, expected_application);
 
-            let current_opening = TestWorkingGroup::worker_opening_by_id(self.worker_opening_id);
-            assert!(current_opening
-                .worker_applications
-                .contains(&application_id));
+            let current_opening = TestWorkingGroup::opening_by_id(self.worker_opening_id);
+            assert!(current_opening.applications.contains(&application_id));
         }
 
         saved_application_next_id
@@ -519,10 +544,8 @@ impl AcceptWorkerApplicationsFixture {
     }
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) {
-        let actual_result = TestWorkingGroup::accept_worker_applications(
-            self.origin.clone().into(),
-            self.opening_id,
-        );
+        let actual_result =
+            TestWorkingGroup::accept_applications(self.origin.clone().into(), self.opening_id);
         assert_eq!(actual_result, expected_result);
     }
 }
@@ -554,6 +577,7 @@ pub struct AddWorkerOpeningFixture {
     activate_at: hiring::ActivateOpeningAt<u64>,
     commitment: OpeningPolicyCommitment<u64, u64>,
     human_readable_text: Vec<u8>,
+    opening_type: OpeningType,
 }
 
 impl Default for AddWorkerOpeningFixture {
@@ -563,6 +587,7 @@ impl Default for AddWorkerOpeningFixture {
             activate_at: hiring::ActivateOpeningAt::CurrentBlock,
             commitment: <OpeningPolicyCommitment<u64, u64>>::default(),
             human_readable_text: b"human_text".to_vec(),
+            opening_type: OpeningType::Worker,
         }
     }
 }
@@ -579,28 +604,30 @@ impl AddWorkerOpeningFixture {
     }
 
     pub fn call_and_assert(&self, expected_result: Result<(), Error>) -> u64 {
-        let saved_opening_next_id = TestWorkingGroup::next_worker_opening_id();
-        let actual_result = TestWorkingGroup::add_worker_opening(
+        let saved_opening_next_id = TestWorkingGroup::next_opening_id();
+        let actual_result = TestWorkingGroup::add_opening(
             self.origin.clone().into(),
             self.activate_at.clone(),
             self.commitment.clone(),
             self.human_readable_text.clone(),
+            self.opening_type,
         );
         assert_eq!(actual_result.clone(), expected_result);
 
         if actual_result.is_ok() {
             assert_eq!(
-                TestWorkingGroup::next_worker_opening_id(),
+                TestWorkingGroup::next_opening_id(),
                 saved_opening_next_id + 1
             );
             let opening_id = saved_opening_next_id;
 
-            let actual_opening = TestWorkingGroup::worker_opening_by_id(opening_id);
+            let actual_opening = TestWorkingGroup::opening_by_id(opening_id);
 
-            let expected_opening = WorkerOpening::<u64, u64, u64, u64> {
+            let expected_opening = Opening::<u64, u64, u64, u64> {
                 opening_id,
-                worker_applications: BTreeSet::new(),
+                applications: BTreeSet::new(),
                 policy_commitment: self.commitment.clone(),
+                opening_type: self.opening_type,
             };
 
             assert_eq!(actual_opening, expected_opening);
@@ -616,6 +643,17 @@ impl AddWorkerOpeningFixture {
         }
     }
 
+    pub fn with_opening_type(self, opening_type: OpeningType) -> Self {
+        AddWorkerOpeningFixture {
+            opening_type,
+            ..self
+        }
+    }
+
+    pub fn with_origin(self, origin: RawOrigin<u64>) -> Self {
+        AddWorkerOpeningFixture { origin, ..self }
+    }
+
     pub fn with_activate_at(self, activate_at: hiring::ActivateOpeningAt<u64>) -> Self {
         AddWorkerOpeningFixture {
             activate_at,
@@ -723,7 +761,7 @@ impl DecreaseWorkerStakeFixture {
         let stake_id = 0;
         let old_balance = Balances::free_balance(&self.account_id);
         let old_stake = <stake::Module<Test>>::stakes(stake_id);
-        let actual_result = TestWorkingGroup::decrease_worker_stake(
+        let actual_result = TestWorkingGroup::decrease_stake(
             self.origin.clone().into(),
             self.worker_id,
             self.balance,
@@ -785,11 +823,8 @@ impl SlashWorkerStakeFixture {
         let stake_id = 0;
         let old_balance = Balances::free_balance(&self.account_id);
         let old_stake = <stake::Module<Test>>::stakes(stake_id);
-        let actual_result = TestWorkingGroup::slash_worker_stake(
-            self.origin.clone().into(),
-            self.worker_id,
-            self.balance,
-        );
+        let actual_result =
+            TestWorkingGroup::slash_stake(self.origin.clone().into(), self.worker_id, self.balance);
 
         assert_eq!(actual_result, expected_result);
 

+ 264 - 181
runtime-modules/working-group/src/tests/mod.rs

@@ -1,7 +1,7 @@
 mod fixtures;
 mod mock;
 
-use crate::types::{OpeningPolicyCommitment, RewardPolicy};
+use crate::types::{OpeningPolicyCommitment, OpeningType, RewardPolicy};
 use crate::{Error, Lead, RawEvent};
 use common::constraints::InputValidationLengthConstraint;
 use mock::{
@@ -54,11 +54,38 @@ fn add_worker_opening_succeeds() {
 
         EventFixture::assert_crate_events(vec![
             RawEvent::LeaderSet(1, lead_account_id),
-            RawEvent::WorkerOpeningAdded(0),
+            RawEvent::OpeningAdded(0),
         ]);
     });
 }
 
+#[test]
+fn add_leader_opening_succeeds_fails_with_incorrect_origin_for_opening_type() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        SetLeadFixture::set_lead(lead_account_id);
+
+        let add_worker_opening_fixture =
+            AddWorkerOpeningFixture::default().with_opening_type(OpeningType::Leader);
+
+        add_worker_opening_fixture.call_and_assert(Err(Error::RequireRootOrigin));
+    });
+}
+
+#[test]
+fn add_leader_opening_succeeds() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        SetLeadFixture::set_lead(lead_account_id);
+
+        let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
+            .with_opening_type(OpeningType::Leader)
+            .with_origin(RawOrigin::Root);
+
+        add_worker_opening_fixture.call_and_assert(Ok(()));
+    });
+}
+
 #[test]
 fn add_worker_opening_fails_with_lead_is_not_set() {
     build_test_externalities().execute_with(|| {
@@ -111,9 +138,7 @@ fn accept_worker_applications_succeeds() {
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
             .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(5));
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let accept_worker_applications_fixture =
             AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -121,21 +146,37 @@ fn accept_worker_applications_succeeds() {
 
         EventFixture::assert_crate_events(vec![
             RawEvent::LeaderSet(1, lead_account_id),
-            RawEvent::WorkerOpeningAdded(opening_id),
-            RawEvent::AcceptedWorkerApplications(opening_id),
+            RawEvent::OpeningAdded(opening_id),
+            RawEvent::AcceptedApplications(opening_id),
         ]);
     });
 }
 
+#[test]
+fn accept_worker_applications_fails_for_invalid_opening_type() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        SetLeadFixture::set_lead(lead_account_id);
+
+        let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
+            .with_origin(RawOrigin::Root)
+            .with_opening_type(OpeningType::Leader)
+            .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(5));
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
+
+        let accept_worker_applications_fixture =
+            AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
+        accept_worker_applications_fixture.call_and_assert(Err(Error::RequireRootOrigin));
+    });
+}
+
 #[test]
 fn accept_worker_applications_fails_with_hiring_error() {
     build_test_externalities().execute_with(|| {
         SetLeadFixture::set_lead(1);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let accept_worker_applications_fixture =
             AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -151,12 +192,10 @@ fn accept_worker_applications_fails_with_not_lead() {
         SetLeadFixture::set_lead(1);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         SetLeadFixture::set_lead(2);
 
-        let opening_id = 0; // newly created opening
-
         let accept_worker_applications_fixture =
             AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
         accept_worker_applications_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
@@ -168,11 +207,11 @@ fn accept_worker_applications_fails_with_no_opening() {
     build_test_externalities().execute_with(|| {
         SetLeadFixture::set_lead(1);
 
-        let opening_id = 0; // newly created opening
+        let opening_id = 0; // random opening id
 
         let accept_worker_applications_fixture =
             AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
-        accept_worker_applications_fixture.call_and_assert(Err(Error::WorkerOpeningDoesNotExist));
+        accept_worker_applications_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
     });
 }
 
@@ -185,9 +224,7 @@ fn apply_on_worker_opening_succeeds() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
@@ -200,10 +237,8 @@ fn apply_on_worker_opening_succeeds() {
             )),
             TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
             TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
-            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::WorkerOpeningAdded(
-                opening_id,
-            )),
-            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::AppliedOnWorkerOpening(
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::OpeningAdded(opening_id)),
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::AppliedOnOpening(
                 opening_id, 0,
             )),
         ]);
@@ -218,11 +253,11 @@ fn apply_on_worker_opening_fails_with_no_opening() {
 
         setup_members(2);
 
-        let opening_id = 0; // newly created opening
+        let opening_id = 0; // random opening id
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Err(Error::WorkerOpeningDoesNotExist));
+        appy_on_worker_opening_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
     });
 }
 
@@ -233,9 +268,7 @@ fn apply_on_worker_opening_fails_with_not_set_members() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
@@ -255,9 +288,7 @@ fn apply_on_worker_opening_fails_with_hiring_error() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
@@ -276,9 +307,7 @@ fn apply_on_worker_opening_fails_with_invalid_application_stake() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
@@ -296,9 +325,7 @@ fn apply_on_worker_opening_fails_with_invalid_role_stake() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_role_stake(100);
@@ -315,9 +342,7 @@ fn apply_on_worker_opening_fails_with_invalid_text() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         <crate::WorkerApplicationHumanReadableText<TestWorkingGroupInstance>>::put(
             InputValidationLengthConstraint {
@@ -348,9 +373,7 @@ fn apply_on_worker_opening_fails_with_already_active_application() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
@@ -370,15 +393,11 @@ fn withdraw_worker_application_succeeds() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let withdraw_application_fixture =
             WithdrawApplicationFixture::default_for_application_id(application_id);
@@ -391,16 +410,14 @@ fn withdraw_worker_application_succeeds() {
             )),
             TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
             TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
-            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::WorkerOpeningAdded(
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::OpeningAdded(opening_id)),
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::AppliedOnOpening(
                 opening_id,
+                application_id,
             )),
-            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::AppliedOnWorkerOpening(
-                opening_id,
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::ApplicationWithdrawn(
                 application_id,
             )),
-            TestEvent::working_group_TestWorkingGroupInstance(
-                RawEvent::WorkerApplicationWithdrawn(application_id),
-            ),
         ]);
     });
 }
@@ -425,15 +442,11 @@ fn withdraw_worker_application_fails_invalid_origin() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let withdraw_application_fixture =
             WithdrawApplicationFixture::default_for_application_id(application_id)
@@ -451,15 +464,12 @@ fn withdraw_worker_application_fails_with_invalid_application_author() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
-        let application_id = 0; // newly created application
         let invalid_author_account_id = 55;
         let withdraw_application_fixture =
             WithdrawApplicationFixture::default_for_application_id(application_id)
@@ -477,15 +487,11 @@ fn withdraw_worker_application_fails_with_hiring_error() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let withdraw_application_fixture =
             WithdrawApplicationFixture::default_for_application_id(application_id);
@@ -504,15 +510,11 @@ fn terminate_worker_application_succeeds() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let terminate_application_fixture =
             TerminateApplicationFixture::default_for_application_id(application_id);
@@ -525,16 +527,14 @@ fn terminate_worker_application_succeeds() {
             )),
             TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
             TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
-            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::WorkerOpeningAdded(
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::OpeningAdded(opening_id)),
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::AppliedOnOpening(
                 opening_id,
+                application_id,
             )),
-            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::AppliedOnWorkerOpening(
-                opening_id,
+            TestEvent::working_group_TestWorkingGroupInstance(RawEvent::ApplicationTerminated(
                 application_id,
             )),
-            TestEvent::working_group_TestWorkingGroupInstance(
-                RawEvent::WorkerApplicationTerminated(application_id),
-            ),
         ]);
     });
 }
@@ -548,15 +548,12 @@ fn terminate_worker_application_fails_with_invalid_application_author() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
-        let application_id = 0; // newly created application
         let invalid_author_account_id = 55;
         let terminate_application_fixture =
             TerminateApplicationFixture::default_for_application_id(application_id)
@@ -574,15 +571,11 @@ fn terminate_worker_application_fails_invalid_origin() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let terminate_application_fixture =
             TerminateApplicationFixture::default_for_application_id(application_id)
@@ -614,15 +607,11 @@ fn terminate_worker_application_fails_with_hiring_error() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let terminate_application_fixture =
             TerminateApplicationFixture::default_for_application_id(application_id);
@@ -639,9 +628,7 @@ fn begin_review_worker_applications_succeeds() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -649,12 +636,29 @@ fn begin_review_worker_applications_succeeds() {
 
         EventFixture::assert_crate_events(vec![
             RawEvent::LeaderSet(1, lead_account_id),
-            RawEvent::WorkerOpeningAdded(opening_id),
-            RawEvent::BeganWorkerApplicationReview(opening_id),
+            RawEvent::OpeningAdded(opening_id),
+            RawEvent::BeganApplicationReview(opening_id),
         ]);
     });
 }
 
+#[test]
+fn begin_review_worker_applications_fails_with_invalid_origin_for_opening_type() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        SetLeadFixture::set_lead(lead_account_id);
+
+        let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
+            .with_origin(RawOrigin::Root)
+            .with_opening_type(OpeningType::Leader);
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
+
+        let begin_review_worker_applications_fixture =
+            BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
+        begin_review_worker_applications_fixture.call_and_assert(Err(Error::RequireRootOrigin));
+    });
+}
+
 #[test]
 fn begin_review_worker_applications_fails_with_not_a_lead() {
     build_test_externalities().execute_with(|| {
@@ -662,13 +666,11 @@ fn begin_review_worker_applications_fails_with_not_a_lead() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let new_lead_account_id = 33;
         SetLeadFixture::set_lead(new_lead_account_id);
 
-        let opening_id = 0; // newly created opening
-
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
         begin_review_worker_applications_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
@@ -681,12 +683,11 @@ fn begin_review_worker_applications_fails_with_invalid_opening() {
         let lead_account_id = 1;
         SetLeadFixture::set_lead(lead_account_id);
 
-        let invalid_opening_id = 6; // newly created opening
+        let invalid_opening_id = 6;
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(invalid_opening_id);
-        begin_review_worker_applications_fixture
-            .call_and_assert(Err(Error::WorkerOpeningDoesNotExist));
+        begin_review_worker_applications_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
     });
 }
 
@@ -697,9 +698,7 @@ fn begin_review_worker_applications_with_hiring_error() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -717,9 +716,7 @@ fn begin_review_worker_applications_fails_with_invalid_origin() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id)
@@ -747,15 +744,11 @@ fn fill_worker_opening_succeeds() {
                 }),
                 ..OpeningPolicyCommitment::default()
             });
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_role_stake(10);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -771,19 +764,62 @@ fn fill_worker_opening_succeeds() {
                     next_payment_at_block: 20,
                     payout_interval: None,
                 });
-        fill_worker_opening_fixture.call_and_assert(Ok(()));
+        let worker_id = fill_worker_opening_fixture.call_and_assert(Ok(()));
 
-        let worker_id = 0; // newly created worker
         let mut worker_application_dictionary = BTreeMap::new();
         worker_application_dictionary.insert(application_id, worker_id);
 
-        EventFixture::assert_last_crate_event(RawEvent::WorkerOpeningFilled(
+        EventFixture::assert_last_crate_event(RawEvent::OpeningFilled(
             opening_id,
             worker_application_dictionary,
         ));
     });
 }
 
+#[test]
+fn fill_worker_opening_fails_with_invalid_origin_for_opening_type() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        SetLeadFixture::set_lead(lead_account_id);
+        increase_total_balance_issuance_using_account_id(1, 10000);
+        setup_members(2);
+
+        let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
+            .with_policy_commitment(OpeningPolicyCommitment {
+                role_staking_policy: Some(hiring::StakingPolicy {
+                    amount: 10,
+                    amount_mode: hiring::StakingAmountLimitMode::AtLeast,
+                    crowded_out_unstaking_period_length: None,
+                    review_period_expired_unstaking_period_length: None,
+                }),
+                ..OpeningPolicyCommitment::default()
+            })
+            .with_opening_type(OpeningType::Leader)
+            .with_origin(RawOrigin::Root);
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
+
+        let appy_on_worker_opening_fixture =
+            ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_role_stake(10);
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
+
+        let begin_review_worker_applications_fixture =
+            BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id)
+                .with_origin(RawOrigin::Root);
+        begin_review_worker_applications_fixture.call_and_assert(Ok(()));
+
+        set_mint_id(create_mint());
+
+        let fill_worker_opening_fixture =
+            FillWorkerOpeningFixture::default_for_ids(opening_id, vec![application_id])
+                .with_reward_policy(RewardPolicy {
+                    amount_per_payout: 1000,
+                    next_payment_at_block: 20,
+                    payout_interval: None,
+                });
+        fill_worker_opening_fixture.call_and_assert(Err(Error::RequireRootOrigin));
+    });
+}
+
 #[test]
 fn fill_worker_opening_fails_with_invalid_origin() {
     build_test_externalities().execute_with(|| {
@@ -791,9 +827,7 @@ fn fill_worker_opening_fails_with_invalid_origin() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let fill_worker_opening_fixture =
             FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new())
@@ -809,13 +843,11 @@ fn fill_worker_opening_fails_with_not_a_lead() {
         SetLeadFixture::set_lead(lead_account_id);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let new_lead_account_id = 33;
         SetLeadFixture::set_lead(new_lead_account_id);
 
-        let opening_id = 0; // newly created opening
-
         let fill_worker_opening_fixture =
             FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
         fill_worker_opening_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
@@ -828,11 +860,11 @@ fn fill_worker_opening_fails_with_invalid_opening() {
         let lead_account_id = 1;
         SetLeadFixture::set_lead(lead_account_id);
 
-        let invalid_opening_id = 6; // newly created opening
+        let invalid_opening_id = 6;
 
         let fill_worker_opening_fixture =
             FillWorkerOpeningFixture::default_for_ids(invalid_opening_id, Vec::new());
-        fill_worker_opening_fixture.call_and_assert(Err(Error::WorkerOpeningDoesNotExist));
+        fill_worker_opening_fixture.call_and_assert(Err(Error::OpeningDoesNotExist));
     });
 }
 
@@ -845,15 +877,11 @@ fn fill_worker_opening_fails_with_invalid_application_list() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -878,9 +906,7 @@ fn fill_worker_opening_fails_with_invalid_application_with_hiring_error() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let fill_worker_opening_fixture =
             FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
@@ -898,15 +924,11 @@ fn fill_worker_opening_fails_with_invalid_reward_policy() {
         setup_members(2);
 
         let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
-        add_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let opening_id = 0; // newly created opening
+        let opening_id = add_worker_opening_fixture.call_and_assert(Ok(()));
 
         let appy_on_worker_opening_fixture =
             ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
-        appy_on_worker_opening_fixture.call_and_assert(Ok(()));
-
-        let application_id = 0; // newly created application
+        let application_id = appy_on_worker_opening_fixture.call_and_assert(Ok(()));
 
         let begin_review_worker_applications_fixture =
             BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
@@ -921,7 +943,6 @@ fn fill_worker_opening_fails_with_invalid_reward_policy() {
                     payout_interval: None,
                 });
         fill_worker_opening_fixture
-            .call_and_assert(Err(Error::FillWorkerOpeningInvalidNextPaymentBlock));
     });
 }
 
@@ -1043,6 +1064,95 @@ fn update_worker_reward_account_fails_with_invalid_origin_signed_account() {
     });
 }
 
+#[test]
+fn update_worker_reward_account_fails_with_invalid_worker_id() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        let invalid_worker_id = 1;
+        fill_default_worker_position();
+
+        let update_worker_account_fixture =
+            UpdateWorkerRewardAccountFixture::default_with_ids(invalid_worker_id, lead_account_id);
+
+        update_worker_account_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
+    });
+}
+
+#[test]
+fn update_worker_reward_account_fails_with_no_recurring_reward() {
+    build_test_externalities().execute_with(|| {
+        let lead_account_id = 1;
+        let worker_id = fill_worker_position_with_no_reward();
+
+        let update_worker_account_fixture =
+            UpdateWorkerRewardAccountFixture::default_with_ids(worker_id, lead_account_id);
+
+        update_worker_account_fixture.call_and_assert(Err(Error::WorkerHasNoReward));
+    });
+}
+
+#[test]
+fn update_worker_reward_amount_succeeds() {
+    build_test_externalities().execute_with(|| {
+        let worker_id = fill_default_worker_position();
+
+        let update_worker_amount_fixture =
+            UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id);
+
+        update_worker_amount_fixture.call_and_assert(Ok(()));
+
+        EventFixture::assert_last_crate_event(RawEvent::WorkerRewardAmountUpdated(worker_id));
+    });
+}
+
+#[test]
+fn update_worker_reward_amount_fails_with_invalid_origin() {
+    build_test_externalities().execute_with(|| {
+        let update_worker_amount_fixture =
+            UpdateWorkerRewardAmountFixture::default_for_worker_id(1).with_origin(RawOrigin::None);
+
+        update_worker_amount_fixture.call_and_assert(Err(Error::Other("RequireSignedOrigin")));
+    });
+}
+
+#[test]
+fn update_worker_reward_amount_fails_with_invalid_origin_signed_account() {
+    build_test_externalities().execute_with(|| {
+        let worker_id = fill_default_worker_position();
+
+        let update_worker_amount_fixture =
+            UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id)
+                .with_origin(RawOrigin::Signed(2));
+
+        update_worker_amount_fixture.call_and_assert(Err(Error::IsNotLeadAccount));
+    });
+}
+
+#[test]
+fn update_worker_reward_amount_fails_with_invalid_worker_id() {
+    build_test_externalities().execute_with(|| {
+        let invalid_worker_id = 1;
+        fill_default_worker_position();
+
+        let update_worker_amount_fixture =
+            UpdateWorkerRewardAmountFixture::default_for_worker_id(invalid_worker_id);
+
+        update_worker_amount_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
+    });
+}
+
+#[test]
+fn update_worker_reward_amount_fails_with_no_recurring_reward() {
+    build_test_externalities().execute_with(|| {
+        let worker_id = fill_worker_position_with_no_reward();
+
+        let update_worker_amount_fixture =
+            UpdateWorkerRewardAmountFixture::default_for_worker_id(worker_id);
+
+        update_worker_amount_fixture.call_and_assert(Err(Error::WorkerHasNoReward));
+    });
+}
+
 fn fill_default_worker_position() -> u64 {
     fill_worker_position(
         Some(RewardPolicy {
@@ -1126,33 +1236,6 @@ fn fill_worker_position(
     worker_id
 }
 
-#[test]
-fn update_worker_reward_account_fails_with_invalid_worker_id() {
-    build_test_externalities().execute_with(|| {
-        let lead_account_id = 1;
-        let invalid_worker_id = 1;
-        fill_default_worker_position();
-
-        let update_worker_account_fixture =
-            UpdateWorkerRewardAccountFixture::default_with_ids(invalid_worker_id, lead_account_id);
-
-        update_worker_account_fixture.call_and_assert(Err(Error::WorkerDoesNotExist));
-    });
-}
-
-#[test]
-fn update_worker_reward_account_fails_with_no_recurring_reward() {
-    build_test_externalities().execute_with(|| {
-        let lead_account_id = 1;
-        let worker_id = fill_worker_position_with_no_reward();
-
-        let update_worker_account_fixture =
-            UpdateWorkerRewardAccountFixture::default_with_ids(worker_id, lead_account_id);
-
-        update_worker_account_fixture.call_and_assert(Err(Error::WorkerHasNoReward));
-    });
-}
-
 #[test]
 fn leave_worker_role_succeeds() {
     build_test_externalities().execute_with(|| {
@@ -1321,7 +1404,7 @@ fn increase_worker_stake_succeeds() {
 
         increase_stake_fixture.call_and_assert(Ok(()));
 
-        EventFixture::assert_last_crate_event(RawEvent::WorkerStakeIncreased(worker_id));
+        EventFixture::assert_last_crate_event(RawEvent::StakeIncreased(worker_id));
     });
 }
 
@@ -1393,7 +1476,7 @@ fn decrease_worker_stake_succeeds() {
 
         decrease_stake_fixture.call_and_assert(Ok(()));
 
-        EventFixture::assert_last_crate_event(RawEvent::WorkerStakeDecreased(worker_id));
+        EventFixture::assert_last_crate_event(RawEvent::StakeDecreased(worker_id));
     });
 }
 
@@ -1477,7 +1560,7 @@ fn slash_worker_stake_succeeds() {
 
         slash_stake_fixture.call_and_assert(Ok(()));
 
-        EventFixture::assert_last_crate_event(RawEvent::WorkerStakeSlashed(worker_id));
+        EventFixture::assert_last_crate_event(RawEvent::StakeSlashed(worker_id));
     });
 }
 
@@ -1618,7 +1701,7 @@ fn ensure_setting_genesis_constraints_succeeds() {
             WORKING_GROUP_CONSTRAINT_DIFF,
         );
         let opening_text_constraint = TestWorkingGroup::opening_human_readable_text();
-        let worker_text_constraint = TestWorkingGroup::worker_application_human_readable_text();
+        let worker_text_constraint = TestWorkingGroup::application_human_readable_text();
         let worker_exit_text_constraint = TestWorkingGroup::worker_exit_rationale_text();
 
         assert_eq!(opening_text_constraint, default_constraint);

+ 44 - 21
runtime-modules/working-group/src/types.rs

@@ -67,7 +67,7 @@ pub struct OpeningPolicyCommitment<BlockNumber, Balance> {
     pub fill_opening_failed_applicant_role_stake_unstaking_period: Option<BlockNumber>,
 
     /// When terminating a worker: unstaking period for application stake.
-    pub terminate_worker_application_stake_unstaking_period: Option<BlockNumber>,
+    pub terminate_application_stake_unstaking_period: Option<BlockNumber>,
 
     /// When terminating a worker: unstaking period for role stake.
     pub terminate_worker_role_stake_unstaking_period: Option<BlockNumber>,
@@ -79,18 +79,40 @@ pub struct OpeningPolicyCommitment<BlockNumber, Balance> {
     pub exit_worker_role_stake_unstaking_period: Option<BlockNumber>,
 }
 
-/// An opening for a worker role.
+/// An opening for a worker or lead role.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-pub struct WorkerOpening<OpeningId, BlockNumber, Balance, WorkerApplicationId: core::cmp::Ord> {
-    /// Identifer for underlying opening in the hiring module.
+pub struct Opening<OpeningId, BlockNumber, Balance, WorkerApplicationId: core::cmp::Ord> {
+    /// Identifier for underlying opening in the hiring module.
     pub opening_id: OpeningId,
 
     /// Set of identifiers for all worker applications ever added.
-    pub worker_applications: BTreeSet<WorkerApplicationId>,
+    pub applications: BTreeSet<WorkerApplicationId>,
 
     /// Commitment to policies in opening.
     pub policy_commitment: OpeningPolicyCommitment<BlockNumber, Balance>,
+
+    /// Defines opening type: Leader or worker.
+    pub opening_type: OpeningType,
+}
+
+/// Defines type of the opening: regular working group fellow or group leader.
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, Copy)]
+pub enum OpeningType {
+    /// Group leader.
+    Leader,
+
+    /// Regular worker.
+    Worker,
+}
+
+/// Must be default constructible because it indirectly is a value in a storage map.
+/// ***SHOULD NEVER ACTUALLY GET CALLED, IS REQUIRED TO DUE BAD STORAGE MODEL IN SUBSTRATE***
+impl Default for OpeningType {
+    fn default() -> Self {
+        Self::Worker
+    }
 }
 
 /// Working group lead: worker lead.
@@ -107,43 +129,43 @@ pub struct Lead<MemberId, AccountId> {
 /// An application for the worker role.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-pub struct WorkerApplication<AccountId, WorkerOpeningId, MemberId, ApplicationId> {
+pub struct Application<AccountId, OpeningId, MemberId, ApplicationId> {
     /// Account used to authenticate in this role.
     pub role_account: AccountId,
 
     /// Opening on which this application applies.
-    pub worker_opening_id: WorkerOpeningId,
+    pub opening_id: OpeningId,
 
     /// Member applying.
     pub member_id: MemberId,
 
     /// Underlying application in hiring module.
-    pub application_id: ApplicationId,
+    pub hiring_application_id: ApplicationId,
 }
 
-impl<AccountId: Clone, WorkerOpeningId: Clone, MemberId: Clone, ApplicationId: Clone>
-    WorkerApplication<AccountId, WorkerOpeningId, MemberId, ApplicationId>
+impl<AccountId: Clone, OpeningId: Clone, MemberId: Clone, ApplicationId: Clone>
+    Application<AccountId, OpeningId, MemberId, ApplicationId>
 {
     /// Creates a new worker application using parameters.
     pub fn new(
         role_account: &AccountId,
-        worker_opening_id: &WorkerOpeningId,
+        opening_id: &OpeningId,
         member_id: &MemberId,
         application_id: &ApplicationId,
     ) -> Self {
-        WorkerApplication {
+        Application {
             role_account: role_account.clone(),
-            worker_opening_id: worker_opening_id.clone(),
+            opening_id: opening_id.clone(),
             member_id: member_id.clone(),
-            application_id: application_id.clone(),
+            hiring_application_id: application_id.clone(),
         }
     }
 }
 
-/// Role stake information for a worker.
+/// Role stake information for a worker/ledd.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-pub struct WorkerRoleStakeProfile<StakeId, BlockNumber> {
+pub struct RoleStakeProfile<StakeId, BlockNumber> {
     /// Whether participant is staked, and if so, the identifier for this staking in the staking module.
     pub stake_id: StakeId,
 
@@ -154,7 +176,7 @@ pub struct WorkerRoleStakeProfile<StakeId, BlockNumber> {
     pub exit_unstaking_period: Option<BlockNumber>,
 }
 
-impl<StakeId: Clone, BlockNumber: Clone> WorkerRoleStakeProfile<StakeId, BlockNumber> {
+impl<StakeId: Clone, BlockNumber: Clone> RoleStakeProfile<StakeId, BlockNumber> {
     /// Creates a new worker role stake profile using stake parameters.
     pub fn new(
         stake_id: &StakeId,
@@ -169,7 +191,7 @@ impl<StakeId: Clone, BlockNumber: Clone> WorkerRoleStakeProfile<StakeId, BlockNu
     }
 }
 
-/// Working group participant: worker.
+/// Working group participant: worker/lead.
 /// This role can be staked, have reward and be inducted through the hiring module.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
@@ -181,7 +203,7 @@ pub struct Worker<AccountId, RewardRelationshipId, StakeId, BlockNumber, MemberI
     /// Whether the role has recurring reward, and if so an identifier for this.
     pub reward_relationship: Option<RewardRelationshipId>,
     /// When set, describes role stake of worker.
-    pub role_stake_profile: Option<WorkerRoleStakeProfile<StakeId, BlockNumber>>,
+    pub role_stake_profile: Option<RoleStakeProfile<StakeId, BlockNumber>>,
 }
 
 impl<
@@ -197,7 +219,7 @@ impl<
         member_id: &MemberId,
         role_account: &AccountId,
         reward_relationship: &Option<RewardRelationshipId>,
-        role_stake_profile: &Option<WorkerRoleStakeProfile<StakeId, BlockNumber>>,
+        role_stake_profile: &Option<RoleStakeProfile<StakeId, BlockNumber>>,
     ) -> Self {
         Worker {
             member_id: member_id.clone(),
@@ -211,12 +233,13 @@ impl<
 /// Origin of exit initiation on behalf of a curator.'
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Debug, Clone, PartialEq)]
-pub enum WorkerExitInitiationOrigin {
+pub enum ExitInitiationOrigin {
     /// Lead is origin.
     Lead,
 
     /// The curator exiting is the origin.
     Worker,
+    //TODO
 }
 
 /// The recurring reward if any to be assigned to an actor when filling in the position.

+ 1 - 3
scripts/run-test-chain.sh

@@ -7,8 +7,6 @@ perl -i -pe's/"setElectionParametersProposalGracePeriod":.*/"setElectionParamete
 perl -i -pe's/"textProposalGracePeriod":.*/"textProposalGracePeriod": 0,/' .tmp/chainspec.json
 perl -i -pe's/"setContentWorkingGroupMintCapacityProposalGracePeriod":.*/"setContentWorkingGroupMintCapacityProposalGracePeriod": 0,/' .tmp/chainspec.json
 perl -i -pe's/"setLeadProposalGracePeriod":.*/"setLeadProposalGracePeriod": 0,/' .tmp/chainspec.json
-perl -i -pe's/"spendingProposalGracePeriod":.*/"spendingProposalGracePeriod": 0,/' .tmp/chainspec.json
-perl -i -pe's/"evictStorageProviderProposalGracePeriod":.*/"evictStorageProviderProposalGracePeriod": 0,/' .tmp/chainspec.json
-perl -i -pe's/"setStorageRoleParametersProposalGracePeriod":.*/"setStorageRoleParametersProposalGracePeriod": 0/' .tmp/chainspec.json
+perl -i -pe's/"spendingProposalGracePeriod":.*/"spendingProposalGracePeriod": 0/' .tmp/chainspec.json
 yes | cargo run --release -p joystream-node -- purge-chain --dev
 cargo run --release -p joystream-node -- --chain=.tmp/chainspec.json --alice --validator

+ 1 - 1
tests/network-tests/src/constantinople/tests/impl/electingCouncil.ts

@@ -2,7 +2,7 @@ import { KeyringPair } from '@polkadot/keyring/types';
 import { ApiWrapper } from '../../utils/apiWrapper';
 import { Keyring } from '@polkadot/api';
 import BN from 'bn.js';
-import { Seat } from '@constantinople/types/lib/council';
+import { Seat } from '@constantinople/types/council';
 import { assert } from 'chai';
 import { v4 as uuid } from 'uuid';
 import { Utils } from '../../utils/utils';

+ 1 - 1
tests/network-tests/src/constantinople/tests/proposals/impl/storageRoleParametersProposal.ts

@@ -4,7 +4,7 @@ import { ApiWrapper } from '../../../utils/apiWrapper';
 import { v4 as uuid } from 'uuid';
 import BN from 'bn.js';
 import { assert } from 'chai';
-import { RoleParameters } from '@constantinople/types/lib/roles';
+import { RoleParameters } from '@constantinople/types/roles';
 import tap from 'tap';
 
 export function storageRoleParametersProposalTest(

+ 5 - 5
tests/network-tests/src/constantinople/utils/apiWrapper.ts

@@ -2,11 +2,11 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
 import { Option, Vec, Bytes, u32 } from '@polkadot/types';
 import { Codec } from '@polkadot/types/types';
 import { KeyringPair } from '@polkadot/keyring/types';
-import { UserInfo, PaidMembershipTerms, MemberId } from '@constantinople/types/lib/members';
-import { Mint, MintId } from '@constantinople/types/lib/mint';
-import { Lead, LeadId } from '@constantinople/types/lib/content-working-group';
-import { RoleParameters } from '@constantinople/types/lib/roles';
-import { Seat } from '@constantinople/types/lib/council';
+import { UserInfo, PaidMembershipTerms, MemberId } from '@constantinople/types/members';
+import { Mint, MintId } from '@constantinople/types/mint';
+import { Lead, LeadId } from '@constantinople/types/content-working-group';
+import { RoleParameters } from '@constantinople/types/roles';
+import { Seat } from '@constantinople/types/council';
 import { Balance, EventRecord, AccountId, BlockNumber, BalanceOf } from '@polkadot/types/interfaces';
 import BN from 'bn.js';
 import { SubmittableExtrinsic } from '@polkadot/api/types';

+ 1 - 1
tests/network-tests/src/constantinople/utils/utils.ts

@@ -4,7 +4,7 @@ import { blake2AsHex } from '@polkadot/util-crypto';
 import BN from 'bn.js';
 import fs from 'fs';
 import { decodeAddress } from '@polkadot/keyring';
-import { Seat } from '@constantinople/types/lib/council';
+import { Seat } from '@constantinople/types/council';
 
 export class Utils {
   private static LENGTH_ADDRESS = 32 + 1; // publicKey + prefix

+ 12 - 1
types/.gitignore

@@ -1 +1,12 @@
-/lib/
+# Don't track build artifacts
+**/*.js
+**/*.d.ts
+
+# JSON files imported by hiring types
+hiring/schemas/role.schema.json
+
+# from prior versions
+lib/
+
+# artifact of webpack when building pioneer?
+build/

+ 6 - 0
types/.npmignore

@@ -0,0 +1,6 @@
+# keep src/ files, packages is compiled when installed
+# src/
+
+# old build artifacts
+lib/
+build/

+ 8 - 8
types/package.json

@@ -2,7 +2,8 @@
   "name": "@joystream/types",
   "version": "0.11.0",
   "description": "Types for Joystream Substrate Runtime - nicaea release",
-  "main": "lib/index.js",
+  "main": "index.js",
+  "types": "index.d.ts",
   "scripts": {
     "prepublish": "npm run build",
     "build": "tsc --build tsconfig.json"
@@ -11,15 +12,14 @@
   "maintainers": [],
   "dependencies": {
     "@polkadot/types": "^0.96.1",
+    "@polkadot/keyring": "^1.7.0-beta.5",
+    "@types/lodash": "^4.14.157",
     "@types/vfile": "^4.0.0",
     "ajv": "^6.11.0",
     "lodash": "^4.17.15"
   },
-  "directories": {
-    "lib": "lib"
-  },
   "devDependencies": {
-    "typescript": "^3.6.4"
+    "typescript": "^3.7.2"
   },
   "engines": {
     "node": ">=10.0"
@@ -30,7 +30,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/Joystream/apps.git"
+    "url": "git+https://github.com/Joystream/joystream.git"
   },
   "keywords": [
     "substrate",
@@ -39,7 +39,7 @@
   ],
   "license": "Apache-2.0",
   "bugs": {
-    "url": "https://github.com/Joystream/apps/issues"
+    "url": "https://github.com/Joystream/joystream/issues"
   },
-  "homepage": "https://github.com/Joystream/packages/joy-types/README.md"
+  "homepage": "https://github.com/Joystream/joystream"
 }

+ 11 - 6
types/tsconfig.json

@@ -11,14 +11,19 @@
     "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
     "experimentalDecorators": true,           /* Enables experimental support for ES7 decorators. */
     "declaration": true,
-    "outDir": "lib",
-	"resolveJsonModule": true,
-	"types" : [
-		"node"
-	]
-
+    "outDir": "./",
+    "resolveJsonModule": true,
+    "types" : [
+      "node"
+    ],
+    "forceConsistentCasingInFileNames": true
   },
   "include": [
     "src/**/*.ts"
   ],
+  "exclude": [
+    "node_modules",
+    "**/*.spec.ts",
+    "**/*.d.ts"
+  ]
 }

+ 6 - 0
yarn.lock

@@ -1362,6 +1362,7 @@
   integrity sha512-RDZizqGKWGYpLR5PnUWM4aGa7InpWNh2Txlr7Al3ROFYOHoyQf62/omPfEz29F6scwlFxysOdmEfQaLeVRaUxA==
   dependencies:
     "@polkadot/types" "^0.96.1"
+    "@types/lodash" "^4.14.157"
     "@types/vfile" "^4.0.0"
     ajv "^6.11.0"
     lodash "^4.17.15"
@@ -3817,6 +3818,11 @@
   resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
   integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==
 
+"@types/lodash@^4.14.157":
+  version "4.14.157"
+  resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.157.tgz#fdac1c52448861dfde1a2e1515dbc46e54926dc8"
+  integrity sha512-Ft5BNFmv2pHDgxV5JDsndOWTRJ+56zte0ZpYLowp03tW+K+t8u8YMOzAnpuqPgzX6WO1XpDIUm7u04M8vdDiVQ==
+
 "@types/marked@^0.7.0":
   version "0.7.2"
   resolved "https://registry.yarnpkg.com/@types/marked/-/marked-0.7.2.tgz#1393f076773b55cc7078c0fbeb86a497c69db97e"