Browse Source

worker application happy case implemented

Gleb Urvanov 4 years ago
parent
commit
80c1b56703

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

@@ -4,7 +4,7 @@
   "license": "GPL-3.0-only",
   "scripts": {
     "build": "tsc --build tsconfig.json",
-    "test": "tap --files ts-node/register src/constantinople/tests/proposals/*Test.ts",
+    "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/workerApplicationHappyCaseTest.ts -T",
     "lint": "tslint --project tsconfig.json",

+ 18 - 7
tests/network-tests/src/nicaea/tests/bureaucracy/impl/workerApplicationHappyCase.ts

@@ -1,9 +1,11 @@
 import tap from 'tap';
+import BN from 'bn.js';
+import { assert } from 'chai';
 import { ApiWrapper } from '../../../utils/apiWrapper';
+import { Utils } from '../../../utils/utils';
 import { KeyringPair } from '@polkadot/keyring/types';
 import { Keyring } from '@polkadot/api';
-import BN from 'bn.js';
-import { Utils } from '../../../utils/utils';
+import { WorkerOpening } from '@nicaea/types/lib/bureaucracy';
 
 export function workerApplicationHappyCase(
   apiWrapper: ApiWrapper,
@@ -24,7 +26,7 @@ export function workerApplicationHappyCase(
   });
 
   tap.test('Add worker opening', async () => {
-    //Fee estimation and transfer
+    // Fee estimation and transfer
     const addWorkerOpeningFee: BN = apiWrapper.estimateAddWorkerOpeningFee();
     const beginReviewFee: BN = apiWrapper.estimateBeginWorkerApplicantReviewFee();
     const fillWorkerOpeningFee: BN = apiWrapper.estimateFillWorkerOpeningFee();
@@ -34,7 +36,7 @@ export function workerApplicationHappyCase(
       addWorkerOpeningFee.add(beginReviewFee).add(fillWorkerOpeningFee)
     );
 
-    //Worker opening creation
+    // Worker opening creation
     const workerOpeningId: BN = await apiWrapper.getNextWorkerOpeningId();
     await apiWrapper.addWorkerOpening(
       lead,
@@ -58,16 +60,16 @@ export function workerApplicationHappyCase(
       ''
     );
 
-    //Applying for created worker opening
+    // Applying for created worker opening
     const nextApplicationId: BN = await apiWrapper.getNextApplicationId();
     const applyOnOpeningFee: BN = apiWrapper.estimateApplyOnOpeningFee(lead).add(applicationStake).add(roleStake);
     await apiWrapper.transferBalanceToAccounts(sudo, membersKeyPairs, applyOnOpeningFee);
     await apiWrapper.batchApplyOnWorkerOpening(membersKeyPairs, workerOpeningId, roleStake, applicationStake, '');
 
-    //Begin application review
+    // Begin application review
     await apiWrapper.beginWorkerApplicationReview(lead, workerOpeningId);
 
-    //Fill worker opening
+    // Fill worker opening
     await apiWrapper.fillWorkerOpening(
       lead,
       workerOpeningId,
@@ -76,5 +78,14 @@ export function workerApplicationHappyCase(
       new BN(99999999),
       new BN(99999999)
     );
+
+    // Assertions
+    const workerOpening: WorkerOpening = await apiWrapper.getWorkerOpening(workerOpeningId);
+    const openingWorkersAccounts: string[] = await Promise.all(
+      workerOpening.worker_applications.map(async id => (await apiWrapper.getWorker(id)).role_account.toString())
+    );
+    membersKeyPairs.forEach(keyPair =>
+      assert(openingWorkersAccounts.includes(keyPair.address), `Account ${keyPair.address} is not worker`)
+    );
   });
 }

+ 13 - 0
tests/network-tests/src/nicaea/utils/apiWrapper.ts

@@ -5,6 +5,7 @@ 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 } from '@nicaea/types/lib/bureaucracy';
 import { RoleParameters } from '@nicaea/types/lib/roles';
 import { Seat } from '@nicaea/types';
 import { Balance, EventRecord, AccountId, BlockNumber, BalanceOf } from '@polkadot/types/interfaces';
@@ -904,4 +905,16 @@ export class ApiWrapper {
   public async getNextApplicationId(): Promise<BN> {
     return this.api.query.forumBureaucracy.nextWorkerApplicationId<u32>();
   }
+
+  public async getWorkerOpening(id: BN): Promise<WorkerOpening> {
+    return ((await this.api.query.forumBureaucracy.workerOpeningById<Codec[]>(id))[0] as unknown) as WorkerOpening;
+  }
+
+  public async getWorkers(): Promise<Worker[]> {
+    return ((await this.api.query.forumBureaucracy.workerById<Codec[]>())[1] as unknown) as Worker[];
+  }
+
+  public async getWorker(id: BN): Promise<Worker> {
+    return ((await this.api.query.forumBureaucracy.workerById<Codec[]>(id))[0] as unknown) as Worker;
+  }
 }

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

@@ -48,7 +48,7 @@ export class Utils {
   }
 
   public static getNextNIds(firstId: BN, n: number): BN[] {
-    let result: BN[] = new Array();
+    const result: BN[] = new Array();
     for (let i = 0; i < n; i++) {
       result.push(firstId.addn(i));
     }