Browse Source

working group tests reworked to match altered runtime module

Gleb Urvanov 4 years ago
parent
commit
8323ae193c

+ 1 - 1
tests/network-tests/package.json

@@ -6,7 +6,7 @@
     "build": "tsc --build tsconfig.json",
     "test": "tap --files ts-node/register src/constantinople/tests/proposals/*Test.ts --files ts-node/register src/nicaea/tests/bureaucracy/*Test.ts",
     "test-migration": "tap --files src/rome/tests/romeRuntimeUpgradeTest.ts --files src/constantinople/tests/electingCouncilTest.ts",
-    "debug": "tap --files src/nicaea/tests/bureaucracy/manageWorkerAsLeadTest.ts -T",
+    "debug": "tap --files src/nicaea/tests/bureaucracy/workerApplicationHappyCaseTest.ts -T",
     "lint": "tslint --project tsconfig.json",
     "prettier": "prettier --write ./src"
   },

+ 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/council';
+import { Seat } from '@constantinople/types';
 import { assert } from 'chai';
 import { v4 as uuid } from 'uuid';
 import { Utils } from '../../utils/utils';

+ 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/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 { 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';
 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/council';
+import { Seat } from '@constantinople/types';
 
 export class Utils {
   private static LENGTH_ADDRESS = 32 + 1; // publicKey + prefix

+ 129 - 70
tests/network-tests/src/nicaea/tests/bureaucracy/impl/workingGroupModule.ts

@@ -2,7 +2,6 @@ import BN from 'bn.js';
 import { assert } from 'chai';
 import { ApiWrapper } from '../../../utils/apiWrapper';
 import { KeyringPair } from '@polkadot/keyring/types';
-import { WorkerOpening } from '@nicaea/types/lib/working-group';
 import { Keyring } from '@polkadot/api';
 import { v4 as uuid } from 'uuid';
 
@@ -23,18 +22,18 @@ export async function addWorkerOpening(
   roleStake: BN,
   activationDelay: BN
 ): Promise<BN> {
-  let workerOpeningId: BN;
+  let openingId: BN;
 
   // Fee estimation and transfer
-  const addWorkerOpeningFee: BN = apiWrapper.estimateAddWorkerOpeningFee();
-  await apiWrapper.transferBalance(sudo, lead.address, addWorkerOpeningFee);
+  const addOpeningFee: BN = apiWrapper.estimateAddOpeningFee();
+  await apiWrapper.transferBalance(sudo, lead.address, addOpeningFee);
 
   // Worker opening creation
-  workerOpeningId = await apiWrapper.getNextWorkerOpeningId();
+  openingId = await apiWrapper.getNextOpeningId();
   const activateAtBlock: BN | undefined = activationDelay.eqn(0)
     ? undefined
     : (await apiWrapper.getBestBlock()).add(activationDelay);
-  await apiWrapper.addWorkerOpening(
+  await apiWrapper.addOpening(
     activateAtBlock,
     lead,
     new BN(membersKeyPairs.length),
@@ -54,33 +53,71 @@ export async function addWorkerOpening(
     new BN(1),
     new BN(1),
     new BN(1),
-    uuid().substring(0, 8)
+    uuid().substring(0, 8),
+    'Worker'
   );
 
-  return workerOpeningId;
+  return openingId;
 }
 
-export async function acceptWorkerApplications(
+export async function addLeaderOpening(
   apiWrapper: ApiWrapper,
-  lead: KeyringPair,
+  membersKeyPairs: KeyringPair[],
   sudo: KeyringPair,
-  workerOpeningId: BN
-) {
+  applicationStake: BN,
+  roleStake: BN,
+  activationDelay: BN
+): Promise<BN> {
+  let openingId: BN;
+
+  // Leader opening creation
+  openingId = await apiWrapper.getNextOpeningId();
+  const activateAtBlock: BN | undefined = activationDelay.eqn(0)
+    ? undefined
+    : (await apiWrapper.getBestBlock()).add(activationDelay);
+  await apiWrapper.sudoAddOpening(
+    activateAtBlock,
+    sudo,
+    new BN(membersKeyPairs.length),
+    new BN(32),
+    new BN(applicationStake),
+    new BN(0),
+    new BN(0),
+    new BN(roleStake),
+    new BN(0),
+    new BN(0),
+    new BN(1),
+    new BN(100),
+    new BN(1),
+    new BN(1),
+    new BN(1),
+    new BN(1),
+    new BN(1),
+    new BN(1),
+    new BN(1),
+    uuid().substring(0, 8),
+    'Leader'
+  );
+
+  return openingId;
+}
+
+export async function acceptApplications(apiWrapper: ApiWrapper, lead: KeyringPair, sudo: KeyringPair, openingId: BN) {
   // Fee estimation and transfer
-  const acceptWorkerApplicationsFee = apiWrapper.estimateAcceptWorkerApplicationsFee();
-  await apiWrapper.transferBalance(sudo, lead.address, acceptWorkerApplicationsFee);
+  const acceptApplicationsFee = apiWrapper.estimateAcceptApplicationsFee();
+  await apiWrapper.transferBalance(sudo, lead.address, acceptApplicationsFee);
 
   // Begin accepting applications
-  await apiWrapper.acceptWorkerApplications(lead, workerOpeningId);
+  await apiWrapper.acceptApplications(lead, openingId);
 }
 
-export async function applyForWorkerOpening(
+export async function applyForOpening(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   sudo: KeyringPair,
   applicationStake: BN,
   roleStake: BN,
-  workerOpeningId: BN,
+  openingId: BN,
   expectFailure: boolean
 ): Promise<BN> {
   let nextApplicationId: BN;
@@ -91,9 +128,9 @@ export async function applyForWorkerOpening(
 
   // Applying for created worker opening
   nextApplicationId = await apiWrapper.getNextApplicationId();
-  await apiWrapper.batchApplyOnWorkerOpening(
+  await apiWrapper.batchApplyOnOpening(
     membersKeyPairs,
-    workerOpeningId,
+    openingId,
     roleStake,
     applicationStake,
     uuid().substring(0, 8),
@@ -103,21 +140,17 @@ export async function applyForWorkerOpening(
   return nextApplicationId;
 }
 
-export async function withdrawWorkerApplicaiton(
-  apiWrapper: ApiWrapper,
-  membersKeyPairs: KeyringPair[],
-  sudo: KeyringPair
-) {
+export async function withdrawApplicaiton(apiWrapper: ApiWrapper, membersKeyPairs: KeyringPair[], sudo: KeyringPair) {
   // Fee estimation and transfer
-  const withdrawApplicaitonFee: BN = apiWrapper.estimateWithdrawWorkerApplicationFee();
+  const withdrawApplicaitonFee: BN = apiWrapper.estimateWithdrawApplicationFee();
   await apiWrapper.transferBalanceToAccounts(sudo, membersKeyPairs, withdrawApplicaitonFee);
 
   // Application withdrawal
-  await apiWrapper.batchWithdrawWorkerApplication(membersKeyPairs);
+  await apiWrapper.batchWithdrawApplication(membersKeyPairs);
 
   // Assertions
   membersKeyPairs.forEach(async keyPair => {
-    const activeApplications: BN[] = await apiWrapper.getActiveWorkerApplicationsIdsByRoleAccount(keyPair.address);
+    const activeApplications: BN[] = await apiWrapper.getActiveApplicationsIdsByRoleAccount(keyPair.address);
     assert(activeApplications.length === 0, `Unexpected active application found for ${keyPair.address}`);
   });
 }
@@ -126,62 +159,83 @@ export async function beginApplicationReview(
   apiWrapper: ApiWrapper,
   lead: KeyringPair,
   sudo: KeyringPair,
-  workerOpeningId: BN
+  openingId: BN
 ) {
   // Fee estimation and transfer
-  const beginReviewFee: BN = apiWrapper.estimateBeginWorkerApplicantReviewFee();
+  const beginReviewFee: BN = apiWrapper.estimateBeginApplicantReviewFee();
   await apiWrapper.transferBalance(sudo, lead.address, beginReviewFee);
 
   // Begin application review
-  await apiWrapper.beginWorkerApplicationReview(lead, workerOpeningId);
+  await apiWrapper.beginApplicantReview(lead, openingId);
 }
 
-export async function fillWorkerOpening(
+export async function beginLeaderApplicationReview(apiWrapper: ApiWrapper, sudo: KeyringPair, openingId: BN) {
+  // Begin application review
+  await apiWrapper.sudoBeginApplicantReview(sudo, openingId);
+}
+
+export async function fillOpening(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   lead: KeyringPair,
   sudo: KeyringPair,
-  workerOpeningId: BN
+  openingId: BN
 ) {
   // Fee estimation and transfer
-  const beginReviewFee: BN = apiWrapper.estimateBeginWorkerApplicantReviewFee();
+  const beginReviewFee: BN = apiWrapper.estimateBeginApplicantReviewFee();
   await apiWrapper.transferBalance(sudo, lead.address, beginReviewFee);
   const applicationIds: BN[] = (
     await Promise.all(
-      membersKeyPairs.map(async keypair => apiWrapper.getActiveWorkerApplicationsIdsByRoleAccount(keypair.address))
+      membersKeyPairs.map(async keypair => apiWrapper.getActiveApplicationsIdsByRoleAccount(keypair.address))
     )
   ).flat();
 
   // Fill worker opening
-  await apiWrapper.fillWorkerOpening(
-    lead,
-    workerOpeningId,
-    applicationIds,
-    new BN(1),
-    new BN(99999999),
-    new BN(99999999)
-  );
+  await apiWrapper.fillOpening(lead, openingId, applicationIds, new BN(1), new BN(99999999), new BN(99999999));
 
   // Assertions
-  const workerOpening: WorkerOpening = await apiWrapper.getWorkerOpening(workerOpeningId);
   const openingWorkersAccounts: string[] = (await apiWrapper.getWorkers()).map(worker =>
-    worker.role_account.toString()
+    worker.role_account_id.toString()
   );
   membersKeyPairs.forEach(keyPair =>
     assert(openingWorkersAccounts.includes(keyPair.address), `Account ${keyPair.address} is not worker`)
   );
 }
 
-export async function increaseWorkerStake(apiWrapper: ApiWrapper, membersKeyPairs: KeyringPair[], sudo: KeyringPair) {
+export async function fillLeaderOpening(
+  apiWrapper: ApiWrapper,
+  membersKeyPairs: KeyringPair[],
+  sudo: KeyringPair,
+  openingId: BN
+) {
+  const applicationIds: BN[] = (
+    await Promise.all(
+      membersKeyPairs.map(async keypair => apiWrapper.getActiveApplicationsIdsByRoleAccount(keypair.address))
+    )
+  ).flat();
+
+  // Fill worker opening
+  await apiWrapper.sudoFillOpening(sudo, openingId, applicationIds, new BN(1), new BN(99999999), new BN(99999999));
+
+  // Assertions
+  const openingWorkersAccounts: string[] = (await apiWrapper.getWorkers()).map(worker =>
+    worker.role_account_id.toString()
+  );
+  membersKeyPairs.forEach(keyPair =>
+    assert(openingWorkersAccounts.includes(keyPair.address), `Account ${keyPair.address} is not leader`)
+  );
+}
+
+export async function increaseStake(apiWrapper: ApiWrapper, membersKeyPairs: KeyringPair[], sudo: KeyringPair) {
   // Fee estimation and transfer
-  const increaseStakeFee: BN = apiWrapper.estimateIncreaseWorkerStakeFee();
+  const increaseStakeFee: BN = apiWrapper.estimateIncreaseStakeFee();
   const stakeIncrement: BN = new BN(1);
   await apiWrapper.transferBalance(sudo, membersKeyPairs[0].address, increaseStakeFee.add(stakeIncrement));
   const workerId: BN = await apiWrapper.getWorkerIdByRoleAccount(membersKeyPairs[0].address);
 
   // Increase worker stake
   const increasedWorkerStake: BN = (await apiWrapper.getWorkerStakeAmount(workerId)).add(stakeIncrement);
-  await apiWrapper.increaseWorkerStake(membersKeyPairs[0], workerId, stakeIncrement);
+  await apiWrapper.increaseStake(membersKeyPairs[0], workerId, stakeIncrement);
   const newWorkerStake: BN = await apiWrapper.getWorkerStakeAmount(workerId);
   assert(
     increasedWorkerStake.eq(newWorkerStake),
@@ -224,7 +278,7 @@ export async function updateRoleAccount(
   // Update role account
   const createdAccount: KeyringPair = keyring.addFromUri(uuid().substring(0, 8));
   await apiWrapper.updateRoleAccount(membersKeyPairs[0], workerId, createdAccount.address);
-  const newRoleAccount: string = (await apiWrapper.getWorker(workerId)).role_account.toString();
+  const newRoleAccount: string = (await apiWrapper.getWorker(workerId)).role_account_id.toString();
   assert(
     newRoleAccount === createdAccount.address,
     `Unexpected role account ${newRoleAccount}, expected ${createdAccount.address}`
@@ -233,21 +287,21 @@ export async function updateRoleAccount(
   membersKeyPairs[0] = createdAccount;
 }
 
-export async function terminateWorkerApplications(
+export async function terminateApplications(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   lead: KeyringPair,
   sudo: KeyringPair
 ) {
   // Fee estimation and transfer
-  const terminateWorkerApplicationFee = apiWrapper.estimateTerminateWorkerApplicationFee();
-  await apiWrapper.transferBalance(sudo, lead.address, terminateWorkerApplicationFee.muln(membersKeyPairs.length));
+  const terminateApplicationFee = apiWrapper.estimateTerminateApplicationFee();
+  await apiWrapper.transferBalance(sudo, lead.address, terminateApplicationFee.muln(membersKeyPairs.length));
 
   // Terminate worker applications
-  await apiWrapper.batchTerminateWorkerApplication(lead, membersKeyPairs);
+  await apiWrapper.batchTerminateApplication(lead, membersKeyPairs);
 }
 
-export async function decreaseWorkerStake(
+export async function decreaseStake(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   lead: KeyringPair,
@@ -255,14 +309,14 @@ export async function decreaseWorkerStake(
   expectFailure: boolean
 ) {
   // Fee estimation and transfer
-  const decreaseWorkerStakeFee = apiWrapper.estimateDecreaseWorkerStakeFee();
-  await apiWrapper.transferBalance(sudo, lead.address, decreaseWorkerStakeFee);
+  const decreaseStakeFee = apiWrapper.estimateDecreaseStakeFee();
+  await apiWrapper.transferBalance(sudo, lead.address, decreaseStakeFee);
   const workerStakeDecrement = new BN(1);
   const workerId: BN = await apiWrapper.getWorkerIdByRoleAccount(membersKeyPairs[0].address);
 
   // Worker stake decrement
   const decreasedWorkerStake: BN = (await apiWrapper.getWorkerStakeAmount(workerId)).sub(workerStakeDecrement);
-  await apiWrapper.decreaseWorkerStake(lead, workerId, workerStakeDecrement, expectFailure);
+  await apiWrapper.decreaseStake(lead, workerId, workerStakeDecrement, expectFailure);
   const newWorkerStake: BN = await apiWrapper.getWorkerStakeAmount(workerId);
 
   // Assertions
@@ -274,7 +328,7 @@ export async function decreaseWorkerStake(
   }
 }
 
-export async function slashWorker(
+export async function slash(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   lead: KeyringPair,
@@ -282,24 +336,21 @@ export async function slashWorker(
   expectFailure: boolean
 ) {
   // Fee estimation and transfer
-  const slashWorkerStakeFee = apiWrapper.estimateSlashWorkerStakeFee();
-  await apiWrapper.transferBalance(sudo, lead.address, slashWorkerStakeFee);
+  const slashStakeFee = apiWrapper.estimateSlashStakeFee();
+  await apiWrapper.transferBalance(sudo, lead.address, slashStakeFee);
   const slashAmount = new BN(1);
   const workerId: BN = await apiWrapper.getWorkerIdByRoleAccount(membersKeyPairs[0].address);
 
   // Slash worker
-  const slashedWorkerStake: BN = (await apiWrapper.getWorkerStakeAmount(workerId)).sub(slashAmount);
-  await apiWrapper.slashWorkerStake(lead, workerId, slashAmount, expectFailure);
-  const newWorkerStake: BN = await apiWrapper.getWorkerStakeAmount(workerId);
+  const slashedStake: BN = (await apiWrapper.getWorkerStakeAmount(workerId)).sub(slashAmount);
+  await apiWrapper.slashStake(lead, workerId, slashAmount, expectFailure);
+  const newStake: BN = await apiWrapper.getWorkerStakeAmount(workerId);
 
   // Assertions
-  assert(
-    slashedWorkerStake.eq(newWorkerStake),
-    `Unexpected worker stake ${newWorkerStake}, expected ${slashedWorkerStake}`
-  );
+  assert(slashedStake.eq(newStake), `Unexpected worker stake ${newStake}, expected ${slashedStake}`);
 }
 
-export async function terminateWorkerRole(
+export async function terminateRole(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   lead: KeyringPair,
@@ -307,15 +358,23 @@ export async function terminateWorkerRole(
   expectFailure: boolean
 ) {
   // Fee estimation and transfer
-  const terminateWorkerRoleFee = apiWrapper.estimateTerminateWorkerRoleFee();
-  await apiWrapper.transferBalance(sudo, lead.address, terminateWorkerRoleFee);
+  const terminateRoleFee = apiWrapper.estimateTerminateRoleFee();
+  await apiWrapper.transferBalance(sudo, lead.address, terminateRoleFee);
   const workerId: BN = await apiWrapper.getWorkerIdByRoleAccount(membersKeyPairs[0].address);
 
   // Slash worker
-  await apiWrapper.terminateWorkerRole(lead, workerId, uuid().substring(0, 8), expectFailure);
+  await apiWrapper.terminateRole(lead, workerId, uuid().substring(0, 8), expectFailure);
 
   // Assertions
   apiWrapper.getWorkerIdByRoleAccount(membersKeyPairs[0].address);
   const newWorkerId = await apiWrapper.getWorkerIdByRoleAccount(membersKeyPairs[0].address);
   assert(newWorkerId === undefined, `Worker with account ${membersKeyPairs[0].address} is not terminated`);
 }
+
+export async function leaveRole(apiWrapper: ApiWrapper, membersKeyPairs: KeyringPair[], sudo: KeyringPair) {
+  // Fee estimation and transfer
+  const leaveRoleFee = apiWrapper.estimateLeaveRoleFee();
+  await apiWrapper.transferBalanceToAccounts(sudo, membersKeyPairs, leaveRoleFee);
+
+  await apiWrapper.batchLeaveRole(membersKeyPairs, uuid().substring(0, 8), false);
+}

+ 37 - 18
tests/network-tests/src/nicaea/tests/bureaucracy/manageWorkerAsLeadTest.ts

@@ -9,14 +9,18 @@ import { setTestTimeout } from '../../utils/setTestTimeout';
 import { membershipTest } from '../impl/membershipCreation';
 import {
   addWorkerOpening,
-  applyForWorkerOpening,
+  applyForOpening,
   beginApplicationReview,
-  fillWorkerOpening,
+  fillOpening,
   setLead,
   unsetLead,
-  decreaseWorkerStake,
-  slashWorker,
-  terminateWorkerRole,
+  decreaseStake,
+  slash,
+  terminateRole,
+  addLeaderOpening,
+  beginLeaderApplicationReview,
+  fillLeaderOpening,
+  leaveRole,
 } from './impl/workingGroupModule';
 import BN from 'bn.js';
 
@@ -45,7 +49,26 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
   membershipTest(apiWrapper, nKeyPairs, keyring, N, paidTerms, sudoUri);
   membershipTest(apiWrapper, leadKeyPair, keyring, N, paidTerms, sudoUri);
 
-  tap.test('Set lead', async () => setLead(apiWrapper, leadKeyPair[0], sudo));
+  let leadOpenignId: BN;
+  tap.test(
+    'Add lead opening',
+    async () =>
+      (leadOpenignId = await addLeaderOpening(
+        apiWrapper,
+        nKeyPairs,
+        sudo,
+        applicationStake,
+        roleStake,
+        openingActivationDelay
+      ))
+  );
+  tap.test(
+    'Apply for lead opening',
+    async () => await applyForOpening(apiWrapper, leadKeyPair, sudo, applicationStake, roleStake, leadOpenignId, false)
+  );
+  tap.test('Begin lead application review', async () => beginLeaderApplicationReview(apiWrapper, sudo, leadOpenignId));
+  tap.test('Fill lead opening', async () => fillLeaderOpening(apiWrapper, leadKeyPair, sudo, leadOpenignId));
+
   let openignId: BN;
   tap.test(
     'Add worker opening',
@@ -62,25 +85,21 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
   );
   tap.test(
     'Apply for worker opening',
-    async () => await applyForWorkerOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
+    async () => await applyForOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
   );
   tap.test('Begin application review', async () => beginApplicationReview(apiWrapper, leadKeyPair[0], sudo, openignId));
-  tap.test('Fill worker opening', async () =>
-    fillWorkerOpening(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, openignId)
-  );
+  tap.test('Fill worker opening', async () => fillOpening(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, openignId));
 
   tap.test('Unset lead', async () => unsetLead(apiWrapper, sudo));
   tap.test('Decrease worker stake, expect failure', async () =>
-    decreaseWorkerStake(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, true)
+    decreaseStake(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, true)
   );
   tap.test('Set lead', async () => setLead(apiWrapper, leadKeyPair[0], sudo));
-  tap.test('Decrease worker stake', async () =>
-    decreaseWorkerStake(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, false)
-  );
-  tap.test('Slash worker', async () => slashWorker(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, false));
-  tap.test('Terminate worker role', async () =>
-    terminateWorkerRole(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, false)
-  );
+  tap.test('Decrease worker stake', async () => decreaseStake(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, false));
+  tap.test('Slash worker', async () => slash(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, false));
+  tap.test('Terminate worker role', async () => terminateRole(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, false));
+
+  tap.test('Leaving lead role', async () => leaveRole(apiWrapper, leadKeyPair, sudo));
 
   closeApi(apiWrapper);
 });

+ 32 - 10
tests/network-tests/src/nicaea/tests/bureaucracy/manageWorkerAsWorkerTest.ts

@@ -9,13 +9,16 @@ import { setTestTimeout } from '../../utils/setTestTimeout';
 import { membershipTest } from '../impl/membershipCreation';
 import {
   addWorkerOpening,
-  applyForWorkerOpening,
+  applyForOpening,
   beginApplicationReview,
-  fillWorkerOpening,
-  setLead,
-  increaseWorkerStake,
+  fillOpening,
+  increaseStake,
   updateRewardAccount,
   updateRoleAccount,
+  addLeaderOpening,
+  beginLeaderApplicationReview,
+  fillLeaderOpening,
+  leaveRole,
 } from './impl/workingGroupModule';
 import BN from 'bn.js';
 
@@ -44,7 +47,26 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
   membershipTest(apiWrapper, nKeyPairs, keyring, N, paidTerms, sudoUri);
   membershipTest(apiWrapper, leadKeyPair, keyring, N, paidTerms, sudoUri);
 
-  tap.test('Set lead', async () => setLead(apiWrapper, leadKeyPair[0], sudo));
+  let leadOpenignId: BN;
+  tap.test(
+    'Add lead opening',
+    async () =>
+      (leadOpenignId = await addLeaderOpening(
+        apiWrapper,
+        nKeyPairs,
+        sudo,
+        applicationStake,
+        roleStake,
+        openingActivationDelay
+      ))
+  );
+  tap.test(
+    'Apply for lead opening',
+    async () => await applyForOpening(apiWrapper, leadKeyPair, sudo, applicationStake, roleStake, leadOpenignId, false)
+  );
+  tap.test('Begin lead application review', async () => beginLeaderApplicationReview(apiWrapper, sudo, leadOpenignId));
+  tap.test('Fill lead opening', async () => fillLeaderOpening(apiWrapper, leadKeyPair, sudo, leadOpenignId));
+
   let openignId: BN;
   tap.test(
     'Add worker opening',
@@ -61,16 +83,16 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
   );
   tap.test(
     'Apply for worker opening',
-    async () => await applyForWorkerOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
+    async () => await applyForOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
   );
   tap.test('Begin application review', async () => beginApplicationReview(apiWrapper, leadKeyPair[0], sudo, openignId));
-  tap.test('Fill worker opening', async () =>
-    fillWorkerOpening(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, openignId)
-  );
+  tap.test('Fill worker opening', async () => fillOpening(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, openignId));
 
-  tap.test('Increase worker stake', async () => increaseWorkerStake(apiWrapper, nKeyPairs, sudo));
+  tap.test('Increase worker stake', async () => increaseStake(apiWrapper, nKeyPairs, sudo));
   tap.test('Update reward account', async () => updateRewardAccount(apiWrapper, nKeyPairs, keyring, sudo));
   tap.test('Update role account', async () => updateRoleAccount(apiWrapper, nKeyPairs, keyring, sudo));
 
+  tap.test('Leaving lead role', async () => leaveRole(apiWrapper, leadKeyPair, sudo));
+
   closeApi(apiWrapper);
 });

+ 39 - 14
tests/network-tests/src/nicaea/tests/bureaucracy/workerApplicationHappyCaseTest.ts

@@ -9,11 +9,14 @@ import { setTestTimeout } from '../../utils/setTestTimeout';
 import { membershipTest } from '../impl/membershipCreation';
 import {
   addWorkerOpening,
-  applyForWorkerOpening,
+  applyForOpening,
   beginApplicationReview,
-  fillWorkerOpening,
-  setLead,
-  withdrawWorkerApplicaiton,
+  fillOpening,
+  withdrawApplicaiton,
+  addLeaderOpening,
+  beginLeaderApplicationReview,
+  fillLeaderOpening,
+  leaveRole,
 } from './impl/workingGroupModule';
 import BN from 'bn.js';
 
@@ -31,7 +34,7 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const applicationStake: BN = new BN(process.env.WORKING_GROUP_APPLICATION_STAKE!);
   const roleStake: BN = new BN(process.env.WORKING_GROUP_ROLE_STAKE!);
-  const durationInBlocks: number = 28;
+  const durationInBlocks: number = 48;
   const openingActivationDelay: BN = new BN(0);
 
   const provider = new WsProvider(nodeUrl);
@@ -40,14 +43,33 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
 
   setTestTimeout(apiWrapper, durationInBlocks);
   membershipTest(apiWrapper, nKeyPairs, keyring, N, paidTerms, sudoUri);
-  membershipTest(apiWrapper, leadKeyPair, keyring, N, paidTerms, sudoUri);
+  membershipTest(apiWrapper, leadKeyPair, keyring, 1, paidTerms, sudoUri);
 
-  tap.test('Set lead', async () => setLead(apiWrapper, leadKeyPair[0], sudo));
-  let openignId: BN;
+  let leadOpenignId: BN;
+  tap.test(
+    'Add lead opening',
+    async () =>
+      (leadOpenignId = await addLeaderOpening(
+        apiWrapper,
+        nKeyPairs,
+        sudo,
+        applicationStake,
+        roleStake,
+        openingActivationDelay
+      ))
+  );
+  tap.test(
+    'Apply for lead opening',
+    async () => await applyForOpening(apiWrapper, leadKeyPair, sudo, applicationStake, roleStake, leadOpenignId, false)
+  );
+  tap.test('Begin lead application review', async () => beginLeaderApplicationReview(apiWrapper, sudo, leadOpenignId));
+  tap.test('Fill lead opening', async () => fillLeaderOpening(apiWrapper, leadKeyPair, sudo, leadOpenignId));
+
+  let workerOpenignId: BN;
   tap.test(
     'Add worker opening',
     async () =>
-      (openignId = await addWorkerOpening(
+      (workerOpenignId = await addWorkerOpening(
         apiWrapper,
         nKeyPairs,
         leadKeyPair[0],
@@ -58,16 +80,19 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
       ))
   );
   tap.test('Apply for worker opening', async () =>
-    applyForWorkerOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
+    applyForOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, workerOpenignId, false)
   );
-  tap.test('Withdraw worker application', async () => withdrawWorkerApplicaiton(apiWrapper, nKeyPairs, sudo));
+  tap.test('Withdraw worker application', async () => withdrawApplicaiton(apiWrapper, nKeyPairs, sudo));
   tap.test('Apply for worker opening', async () =>
-    applyForWorkerOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
+    applyForOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, workerOpenignId, false)
+  );
+  tap.test('Begin application review', async () =>
+    beginApplicationReview(apiWrapper, leadKeyPair[0], sudo, workerOpenignId)
   );
-  tap.test('Begin application review', async () => beginApplicationReview(apiWrapper, leadKeyPair[0], sudo, openignId));
   tap.test('Fill worker opening', async () =>
-    fillWorkerOpening(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, openignId)
+    fillOpening(apiWrapper, nKeyPairs, leadKeyPair[0], sudo, workerOpenignId)
   );
+  tap.test('Leaving lead role', async () => leaveRole(apiWrapper, leadKeyPair, sudo));
 
   closeApi(apiWrapper);
 });

+ 34 - 10
tests/network-tests/src/nicaea/tests/bureaucracy/workerApplicationRejectionCaseTest.ts

@@ -9,11 +9,14 @@ import { setTestTimeout } from '../../utils/setTestTimeout';
 import { membershipTest, createKeyPairs } from '../impl/membershipCreation';
 import {
   addWorkerOpening,
-  applyForWorkerOpening,
-  setLead,
-  acceptWorkerApplications,
-  terminateWorkerApplications,
+  applyForOpening,
+  acceptApplications,
+  terminateApplications,
   unsetLead,
+  addLeaderOpening,
+  beginLeaderApplicationReview,
+  fillLeaderOpening,
+  leaveRole,
 } from './impl/workingGroupModule';
 import BN from 'bn.js';
 
@@ -43,7 +46,26 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   membershipTest(apiWrapper, nKeyPairs, keyring, N, paidTerms, sudoUri);
   membershipTest(apiWrapper, leadKeyPair, keyring, N, paidTerms, sudoUri);
 
-  tap.test('Set lead', async () => setLead(apiWrapper, leadKeyPair[0], sudo));
+  let leadOpenignId: BN;
+  tap.test(
+    'Add lead opening',
+    async () =>
+      (leadOpenignId = await addLeaderOpening(
+        apiWrapper,
+        nKeyPairs,
+        sudo,
+        applicationStake,
+        roleStake,
+        openingActivationDelay
+      ))
+  );
+  tap.test(
+    'Apply for lead opening',
+    async () => await applyForOpening(apiWrapper, leadKeyPair, sudo, applicationStake, roleStake, leadOpenignId, false)
+  );
+  tap.test('Begin lead application review', async () => beginLeaderApplicationReview(apiWrapper, sudo, leadOpenignId));
+  tap.test('Fill lead opening', async () => fillLeaderOpening(apiWrapper, leadKeyPair, sudo, leadOpenignId));
+
   let openignId: BN;
   tap.test(
     'Add worker opening',
@@ -59,21 +81,23 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
       ))
   );
   tap.test('Apply for worker opening, expect failure', async () =>
-    applyForWorkerOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, true)
+    applyForOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, true)
   );
   tap.test('Begin accepting worker applications', async () =>
-    acceptWorkerApplications(apiWrapper, leadKeyPair[0], sudo, openignId)
+    acceptApplications(apiWrapper, leadKeyPair[0], sudo, openignId)
   );
   tap.test('Apply for worker opening as non-member, expect failure', async () =>
-    applyForWorkerOpening(apiWrapper, nonMemberKeyPairs, sudo, applicationStake, roleStake, openignId, true)
+    applyForOpening(apiWrapper, nonMemberKeyPairs, sudo, applicationStake, roleStake, openignId, true)
   );
   tap.test('Apply for worker opening as member', async () =>
-    applyForWorkerOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
+    applyForOpening(apiWrapper, nKeyPairs, sudo, applicationStake, roleStake, openignId, false)
   );
   tap.test('Terminate worker applicaitons', async () =>
-    terminateWorkerApplications(apiWrapper, nKeyPairs, leadKeyPair[0], sudo)
+    terminateApplications(apiWrapper, nKeyPairs, leadKeyPair[0], sudo)
   );
   tap.test('Unset lead', async () => unsetLead(apiWrapper, sudo));
 
+  tap.test('Leaving lead role', async () => leaveRole(apiWrapper, leadKeyPair, sudo));
+
   closeApi(apiWrapper);
 });

+ 186 - 112
tests/network-tests/src/nicaea/utils/apiWrapper.ts

@@ -2,26 +2,21 @@ 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 '@nicaea/types/lib/members';
-import { Mint, MintId } from '@nicaea/types/lib/mint';
-import { Lead, LeadId } from '@nicaea/types/lib/content-working-group';
-import {
-  WorkerOpening,
-  Worker,
-  WorkerId,
-  WorkerApplication,
-  WorkerApplicationId,
-} from '@nicaea/types/lib/working-group';
-import { RoleParameters } from '@nicaea/types/lib/roles';
+import { UserInfo, PaidMembershipTerms, MemberId } from '@nicaea/types/members';
+import { Mint, MintId } from '@nicaea/types/mint';
+import { Lead, LeadId } from '@nicaea/types/content-working-group';
+import { Application, WorkerId, Worker } from '@nicaea/types/working-group';
+import { Application as HiringApplication } from '@nicaea/types/hiring';
+import { RoleParameters } from '@nicaea/types/roles';
 import { Seat } from '@nicaea/types/lib/council';
 import { Balance, EventRecord, AccountId, BlockNumber, BalanceOf } from '@polkadot/types/interfaces';
 import BN from 'bn.js';
 import { SubmittableExtrinsic } from '@polkadot/api/types';
 import { Sender } from './sender';
 import { Utils } from './utils';
-import { Stake, StakedState } from '@nicaea/types/lib/stake';
-import { RewardRelationship } from '@nicaea/types/lib/recurring-rewards';
-import { Application } from '@nicaea/types/lib/hiring';
+import { Stake, StakedState } from '@nicaea/types/stake';
+import { RewardRelationship } from '@nicaea/types/recurring-rewards';
+import { Opening, ApplicationId } from '@nicaea/types/hiring';
 
 export class ApiWrapper {
   private readonly api: ApiPromise;
@@ -226,9 +221,9 @@ export class ApiWrapper {
     return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'));
   }
 
-  public estimateAddWorkerOpeningFee(): BN {
+  public estimateAddOpeningFee(): BN {
     return this.estimateTxFee(
-      this.api.tx.storageWorkingGroup.addWorkerOpening(
+      this.api.tx.storageWorkingGroup.addOpening(
         'CurrentBlock',
         {
           application_rationing_policy: { max_active_applicants: '32' },
@@ -259,18 +254,19 @@ export class ApiWrapper {
           exit_curator_role_application_stake_unstaking_period: 0,
           exit_curator_role_stake_unstaking_period: 0,
         },
-        'Opening readable text'
+        'Opening readable text',
+        'Worker'
       )
     );
   }
 
-  public estimateAcceptWorkerApplicationsFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.acceptWorkerApplications(0));
+  public estimateAcceptApplicationsFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.acceptApplications(0));
   }
 
   public estimateApplyOnOpeningFee(account: KeyringPair): BN {
     return this.estimateTxFee(
-      this.api.tx.storageWorkingGroup.applyOnWorkerOpening(
+      this.api.tx.storageWorkingGroup.applyOnOpening(
         0,
         0,
         account.address,
@@ -281,13 +277,13 @@ export class ApiWrapper {
     );
   }
 
-  public estimateBeginWorkerApplicantReviewFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.beginWorkerApplicantReview(0));
+  public estimateBeginApplicantReviewFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.beginApplicantReview(0));
   }
 
-  public estimateFillWorkerOpeningFee(): BN {
+  public estimateFillOpeningFee(): BN {
     return this.estimateTxFee(
-      this.api.tx.storageWorkingGroup.fillWorkerOpening(0, [0], {
+      this.api.tx.storageWorkingGroup.fillOpening(0, [0], {
         amount_per_payout: 0,
         next_payment_at_block: 0,
         payout_interval: 0,
@@ -295,41 +291,41 @@ export class ApiWrapper {
     );
   }
 
-  public estimateIncreaseWorkerStakeFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.increaseWorkerStake(0, 0));
+  public estimateIncreaseStakeFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.increaseStake(0, 0));
   }
 
-  public estimateDecreaseWorkerStakeFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.decreaseWorkerStake(0, 0));
+  public estimateDecreaseStakeFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.decreaseStake(0, 0));
   }
 
   public estimateUpdateRoleAccountFee(address: string): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.updateWorkerRoleAccount(0, address));
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.updateRoleAccount(0, address));
   }
 
   public estimateUpdateRewardAccountFee(address: string): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.updateWorkerRewardAccount(0, address));
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.updateRewardAccount(0, address));
   }
 
-  public estimateLeaveWorkerRoleFee(text: string): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.leaveWorkerRole(0, text));
+  public estimateLeaveRoleFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.leaveRole(0, 'Long justification text'));
   }
 
-  public estimateWithdrawWorkerApplicationFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.withdrawWorkerApplication(0));
+  public estimateWithdrawApplicationFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.withdrawApplication(0));
   }
 
-  public estimateTerminateWorkerApplicationFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.terminateWorkerApplication(0));
+  public estimateTerminateApplicationFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.terminateApplication(0));
   }
 
-  public estimateSlashWorkerStakeFee(): BN {
-    return this.estimateTxFee(this.api.tx.storageWorkingGroup.slashWorkerStake(0, 0));
+  public estimateSlashStakeFee(): BN {
+    return this.estimateTxFee(this.api.tx.storageWorkingGroup.slashStake(0, 0));
   }
 
-  public estimateTerminateWorkerRoleFee(): BN {
+  public estimateTerminateRoleFee(): BN {
     return this.estimateTxFee(
-      this.api.tx.storageWorkingGroup.terminateWorkerRole(
+      this.api.tx.storageWorkingGroup.terminateRole(
         0,
         'Long justification text explaining why the worker role will be terminated'
       )
@@ -739,7 +735,7 @@ export class ApiWrapper {
     return this.sender.signAndSend(this.api.tx.sudo.sudo(this.api.tx.storageWorkingGroup.unsetLead()), sudo, false);
   }
 
-  public async addWorkerOpening(
+  public async addOpening(
     activateAtBlock: BN | undefined,
     account: KeyringPair,
     maxActiveApplicants: BN,
@@ -759,7 +755,8 @@ export class ApiWrapper {
     terminateCuratorRoleStakeUnstakingPeriod: BN,
     exitCuratorRoleApplicationStakeUnstakingPeriod: BN,
     exitCuratorRoleStakeUnstakingPeriod: BN,
-    text: string
+    text: string,
+    openingType: string
   ): Promise<void> {
     const activateAt = activateAtBlock == undefined ? 'CurrentBlock' : { ExactBlock: activateAtBlock };
     const commitment = {
@@ -792,31 +789,91 @@ export class ApiWrapper {
       exit_curator_role_stake_unstaking_period: exitCuratorRoleStakeUnstakingPeriod,
     };
     await this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.addWorkerOpening(activateAt, commitment, text),
+      this.api.tx.storageWorkingGroup.addOpening(activateAt, commitment, text, openingType),
       account,
       false
     );
   }
 
-  public async acceptWorkerApplications(account: KeyringPair, workerOpeningId: BN): Promise<void> {
-    return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.acceptWorkerApplications(workerOpeningId),
-      account,
+  public async sudoAddOpening(
+    activateAtBlock: BN | undefined,
+    sudo: KeyringPair,
+    maxActiveApplicants: BN,
+    maxReviewPeriodLength: BN,
+    applicationStakingPolicyAmount: BN,
+    applicationCrowdedOutUnstakingPeriodLength: BN,
+    applicationExpiredUnstakingPeriodLength: BN,
+    roleStakingPolicyAmount: BN,
+    roleCrowdedOutUnstakingPeriodLength: BN,
+    roleExpiredUnstakingPeriodLength: BN,
+    slashableMaxCount: BN,
+    slashableMaxPercentPtsPerTime: BN,
+    successfulApplicantApplicationStakeUnstakingPeriod: BN,
+    failedApplicantApplicationStakeUnstakingPeriod: BN,
+    failedApplicantRoleStakeUnstakingPeriod: BN,
+    terminateCuratorApplicationStakeUnstakingPeriod: BN,
+    terminateCuratorRoleStakeUnstakingPeriod: BN,
+    exitCuratorRoleApplicationStakeUnstakingPeriod: BN,
+    exitCuratorRoleStakeUnstakingPeriod: BN,
+    text: string,
+    openingType: string
+  ): Promise<void> {
+    const activateAt = activateAtBlock == undefined ? 'CurrentBlock' : { ExactBlock: activateAtBlock };
+    const commitment = {
+      application_rationing_policy: { max_active_applicants: maxActiveApplicants },
+      max_review_period_length: maxReviewPeriodLength,
+      application_staking_policy: {
+        amount: applicationStakingPolicyAmount,
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: applicationCrowdedOutUnstakingPeriodLength,
+        review_period_expired_unstaking_period_length: applicationExpiredUnstakingPeriodLength,
+      },
+      role_staking_policy: {
+        amount: roleStakingPolicyAmount,
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: roleCrowdedOutUnstakingPeriodLength,
+        review_period_expired_unstaking_period_length: roleExpiredUnstakingPeriodLength,
+      },
+      role_slashing_terms: {
+        Slashable: {
+          max_count: slashableMaxCount,
+          max_percent_pts_per_time: slashableMaxPercentPtsPerTime,
+        },
+      },
+      fill_opening_successful_applicant_application_stake_unstaking_period: successfulApplicantApplicationStakeUnstakingPeriod,
+      fill_opening_failed_applicant_application_stake_unstaking_period: failedApplicantApplicationStakeUnstakingPeriod,
+      fill_opening_failed_applicant_role_stake_unstaking_period: failedApplicantRoleStakeUnstakingPeriod,
+      terminate_curator_application_stake_unstaking_period: terminateCuratorApplicationStakeUnstakingPeriod,
+      terminate_curator_role_stake_unstaking_period: terminateCuratorRoleStakeUnstakingPeriod,
+      exit_curator_role_application_stake_unstaking_period: exitCuratorRoleApplicationStakeUnstakingPeriod,
+      exit_curator_role_stake_unstaking_period: exitCuratorRoleStakeUnstakingPeriod,
+    };
+    await this.sender.signAndSend(
+      this.api.tx.sudo.sudo(this.api.tx.storageWorkingGroup.addOpening(activateAt, commitment, text, openingType)),
+      sudo,
       false
     );
   }
 
-  public async beginWorkerApplicationReview(account: KeyringPair, workerOpeningId: BN): Promise<void> {
+  public async acceptApplications(account: KeyringPair, openingId: BN): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.acceptApplications(openingId), account, false);
+  }
+
+  public async beginApplicantReview(account: KeyringPair, openingId: BN): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.beginApplicantReview(openingId), account, false);
+  }
+
+  public async sudoBeginApplicantReview(sudo: KeyringPair, openingId: BN): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.beginWorkerApplicantReview(workerOpeningId),
-      account,
+      this.api.tx.sudo.sudo(this.api.tx.storageWorkingGroup.beginApplicantReview(openingId)),
+      sudo,
       false
     );
   }
 
-  public async applyOnWorkerOpening(
+  public async applyOnOpening(
     account: KeyringPair,
-    workerOpeningId: BN,
+    openingId: BN,
     roleStake: BN,
     applicantStake: BN,
     text: string,
@@ -824,9 +881,9 @@ export class ApiWrapper {
   ): Promise<void> {
     const memberId: BN = (await this.getMemberIds(account.address))[0];
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.applyOnWorkerOpening(
+      this.api.tx.storageWorkingGroup.applyOnOpening(
         memberId,
-        workerOpeningId,
+        openingId,
         account.address,
         roleStake,
         applicantStake,
@@ -837,9 +894,9 @@ export class ApiWrapper {
     );
   }
 
-  public async batchApplyOnWorkerOpening(
+  public async batchApplyOnOpening(
     accounts: KeyringPair[],
-    workerOpeningId: BN,
+    openingId: BN,
     roleStake: BN,
     applicantStake: BN,
     text: string,
@@ -847,21 +904,21 @@ export class ApiWrapper {
   ): Promise<void[]> {
     return Promise.all(
       accounts.map(async keyPair => {
-        await this.applyOnWorkerOpening(keyPair, workerOpeningId, roleStake, applicantStake, text, expectFailure);
+        await this.applyOnOpening(keyPair, openingId, roleStake, applicantStake, text, expectFailure);
       })
     );
   }
 
-  public async fillWorkerOpening(
+  public async fillOpening(
     account: KeyringPair,
-    workerOpeningId: BN,
+    openingId: BN,
     applicationId: BN[],
     amountPerPayout: BN,
     nextPaymentBlock: BN,
     payoutInterval: BN
   ): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.fillWorkerOpening(workerOpeningId, applicationId, {
+      this.api.tx.storageWorkingGroup.fillOpening(openingId, applicationId, {
         amount_per_payout: amountPerPayout,
         next_payment_at_block: nextPaymentBlock,
         payout_interval: payoutInterval,
@@ -871,38 +928,46 @@ export class ApiWrapper {
     );
   }
 
-  public async increaseWorkerStake(account: KeyringPair, workerId: BN, stake: BN): Promise<void> {
+  public async sudoFillOpening(
+    sudo: KeyringPair,
+    openingId: BN,
+    applicationId: BN[],
+    amountPerPayout: BN,
+    nextPaymentBlock: BN,
+    payoutInterval: BN
+  ): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.increaseWorkerStake(workerId, stake),
-      account,
+      this.api.tx.sudo.sudo(
+        this.api.tx.storageWorkingGroup.fillOpening(openingId, applicationId, {
+          amount_per_payout: amountPerPayout,
+          next_payment_at_block: nextPaymentBlock,
+          payout_interval: payoutInterval,
+        })
+      ),
+      sudo,
       false
     );
   }
 
-  public async decreaseWorkerStake(
-    account: KeyringPair,
-    workerId: BN,
-    stake: BN,
-    expectFailure: boolean
-  ): Promise<void> {
-    return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.decreaseWorkerStake(workerId, stake),
-      account,
-      expectFailure
-    );
+  public async increaseStake(account: KeyringPair, workerId: BN, stake: BN): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.increaseStake(workerId, stake), account, false);
   }
 
-  public async slashWorkerStake(account: KeyringPair, workerId: BN, stake: BN, expectFailure: boolean): Promise<void> {
+  public async decreaseStake(account: KeyringPair, workerId: BN, stake: BN, expectFailure: boolean): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.slashWorkerStake(workerId, stake),
+      this.api.tx.storageWorkingGroup.decreaseStake(workerId, stake),
       account,
       expectFailure
     );
   }
 
+  public async slashStake(account: KeyringPair, workerId: BN, stake: BN, expectFailure: boolean): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.slashStake(workerId, stake), account, expectFailure);
+  }
+
   public async updateRoleAccount(account: KeyringPair, workerId: BN, newRoleAccount: string): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.updateWorkerRoleAccount(workerId, newRoleAccount),
+      this.api.tx.storageWorkingGroup.updateRoleAccount(workerId, newRoleAccount),
       account,
       false
     );
@@ -910,55 +975,64 @@ export class ApiWrapper {
 
   public async updateRewardAccount(account: KeyringPair, workerId: BN, newRewardAccount: string): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.updateWorkerRewardAccount(workerId, newRewardAccount),
+      this.api.tx.storageWorkingGroup.updateRewardAccount(workerId, newRewardAccount),
       account,
       false
     );
   }
 
-  public async withdrawWorkerApplication(account: KeyringPair, workerId: BN): Promise<void> {
-    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.withdrawWorkerApplication(workerId), account, false);
+  public async withdrawApplication(account: KeyringPair, workerId: BN): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.withdrawApplication(workerId), account, false);
   }
 
-  public async batchWithdrawWorkerApplication(accounts: KeyringPair[]): Promise<void[]> {
+  public async batchWithdrawApplication(accounts: KeyringPair[]): Promise<void[]> {
     return Promise.all(
       accounts.map(async keyPair => {
-        const applicationIds: BN[] = await this.getWorkerApplicationsIdsByRoleAccount(keyPair.address);
-        await this.withdrawWorkerApplication(keyPair, applicationIds[0]);
+        const applicationIds: BN[] = await this.getApplicationsIdsByRoleAccount(keyPair.address);
+        await this.withdrawApplication(keyPair, applicationIds[0]);
       })
     );
   }
 
-  public async terminateWorkerApplication(account: KeyringPair, applicationId: BN): Promise<void> {
-    return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.terminateWorkerApplication(applicationId),
-      account,
-      false
-    );
+  public async terminateApplication(account: KeyringPair, applicationId: BN): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.terminateApplication(applicationId), account, false);
   }
 
-  public async batchTerminateWorkerApplication(account: KeyringPair, roleAccounts: KeyringPair[]): Promise<void[]> {
+  public async batchTerminateApplication(account: KeyringPair, roleAccounts: KeyringPair[]): Promise<void[]> {
     return Promise.all(
       roleAccounts.map(async keyPair => {
-        const applicationIds: BN[] = await this.getActiveWorkerApplicationsIdsByRoleAccount(keyPair.address);
-        await this.terminateWorkerApplication(account, applicationIds[0]);
+        const applicationIds: BN[] = await this.getActiveApplicationsIdsByRoleAccount(keyPair.address);
+        await this.terminateApplication(account, applicationIds[0]);
       })
     );
   }
 
-  public async terminateWorkerRole(
+  public async terminateRole(
     account: KeyringPair,
     applicationId: BN,
     text: string,
     expectFailure: boolean
   ): Promise<void> {
     return this.sender.signAndSend(
-      this.api.tx.storageWorkingGroup.terminateWorkerRole(applicationId, text),
+      this.api.tx.storageWorkingGroup.terminateRole(applicationId, text),
       account,
       expectFailure
     );
   }
 
+  public async leaveRole(account: KeyringPair, text: string, expectFailure: boolean): Promise<void> {
+    const workerId: BN = await this.getWorkerIdByRoleAccount(account.address);
+    return this.sender.signAndSend(this.api.tx.storageWorkingGroup.leaveRole(workerId, text), account, expectFailure);
+  }
+
+  public async batchLeaveRole(roleAccounts: KeyringPair[], text: string, expectFailure: boolean): Promise<void[]> {
+    return Promise.all(
+      roleAccounts.map(async keyPair => {
+        await this.leaveRole(keyPair, text, expectFailure);
+      })
+    );
+  }
+
   public async getStorageRoleParameters(): Promise<RoleParameters> {
     return (await this.api.query.actors.parameters<Option<RoleParameters>>('StorageProvider')).unwrap();
   }
@@ -995,16 +1069,16 @@ export class ApiWrapper {
     return this.api.query.councilElection.minVotingStake<BalanceOf>();
   }
 
-  public async getNextWorkerOpeningId(): Promise<BN> {
-    return this.api.query.storageWorkingGroup.nextWorkerOpeningId<u32>();
+  public async getNextOpeningId(): Promise<BN> {
+    return this.api.query.storageWorkingGroup.nextOpeningId<u32>();
   }
 
   public async getNextApplicationId(): Promise<BN> {
-    return this.api.query.storageWorkingGroup.nextWorkerApplicationId<u32>();
+    return this.api.query.storageWorkingGroup.nextApplicationId<u32>();
   }
 
-  public async getWorkerOpening(id: BN): Promise<WorkerOpening> {
-    return ((await this.api.query.storageWorkingGroup.workerOpeningById<Codec[]>(id))[0] as unknown) as WorkerOpening;
+  public async getOpening(id: BN): Promise<Opening> {
+    return ((await this.api.query.storageWorkingGroup.openingById<Codec[]>(id))[0] as unknown) as Opening;
   }
 
   public async getWorkers(): Promise<Worker[]> {
@@ -1021,33 +1095,33 @@ export class ApiWrapper {
     const ids: WorkerId[] = (workersAndIds[0] as unknown) as WorkerId[];
     let index: number;
     workers.forEach((worker, i) => {
-      if (worker.role_account.toString() === address) index = i;
+      if (worker.role_account_id.toString() === address) index = i;
     });
     return ids[index!];
   }
 
-  public async getWorkerApplicationsIdsByRoleAccount(address: string): Promise<BN[]> {
-    const applicationsAndIds = await this.api.query.storageWorkingGroup.workerApplicationById<Codec[]>();
-    const applications: WorkerApplication[] = (applicationsAndIds[1] as unknown) as WorkerApplication[];
-    const ids: WorkerApplicationId[] = (applicationsAndIds[0] as unknown) as WorkerApplicationId[];
+  public async getApplicationsIdsByRoleAccount(address: string): Promise<BN[]> {
+    const applicationsAndIds = await this.api.query.storageWorkingGroup.applicationById<Codec[]>();
+    const applications: Application[] = (applicationsAndIds[1] as unknown) as Application[];
+    const ids: ApplicationId[] = (applicationsAndIds[0] as unknown) as ApplicationId[];
     return applications
-      .map((application, index) => (application.role_account.toString() === address ? ids[index] : undefined))
+      .map((application, index) => (application.role_account_id.toString() === address ? ids[index] : undefined))
       .filter(index => index !== undefined) as BN[];
   }
 
-  public async getApplicationById(id: BN): Promise<Application> {
-    return ((await this.api.query.hiring.applicationById<Codec[]>(id))[0] as unknown) as Application;
+  public async getApplicationById(id: BN): Promise<HiringApplication> {
+    return ((await this.api.query.hiring.applicationById<Codec[]>(id))[0] as unknown) as HiringApplication;
   }
 
-  public async getActiveWorkerApplicationsIdsByRoleAccount(address: string): Promise<BN[]> {
-    const applicationsAndIds = await this.api.query.storageWorkingGroup.workerApplicationById<Codec[]>();
-    const applications: WorkerApplication[] = (applicationsAndIds[1] as unknown) as WorkerApplication[];
-    const ids: WorkerApplicationId[] = (applicationsAndIds[0] as unknown) as WorkerApplicationId[];
+  public async getActiveApplicationsIdsByRoleAccount(address: string): Promise<BN[]> {
+    const applicationsAndIds = await this.api.query.storageWorkingGroup.applicationById<Codec[]>();
+    const applications: Application[] = (applicationsAndIds[1] as unknown) as Application[];
+    const ids: ApplicationId[] = (applicationsAndIds[0] as unknown) as ApplicationId[];
     return (
       await Promise.all(
         applications.map(async (application, index) => {
           if (
-            application.role_account.toString() === address &&
+            application.role_account_id.toString() === address &&
             (await this.getApplicationById(application.application_id)).stage.type === 'Active'
           ) {
             return ids[index];

+ 2 - 1
yarn.lock

@@ -1362,7 +1362,6 @@
   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"
@@ -1741,7 +1740,9 @@
 "@joystream/types@./types", "@nicaea/types@./types":
   version "0.11.0"
   dependencies:
+    "@polkadot/keyring" "^1.7.0-beta.5"
     "@polkadot/types" "^0.96.1"
+    "@types/lodash" "^4.14.157"
     "@types/vfile" "^4.0.0"
     ajv "^6.11.0"
     lodash "^4.17.15"