Quellcode durchsuchen

worker opening happy case test implementation

Gleb Urvanov vor 4 Jahren
Ursprung
Commit
63b8fe8e36

+ 33 - 3
tests/network-tests/src/nicaea/tests/bureaucracy/impl/workerApplicationHappyCase.ts

@@ -7,19 +7,49 @@ import BN from 'bn.js';
 export function workerApplicationHappyCase(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
+  leadArray: KeyringPair[],
   keyring: Keyring,
   sudoUri: string
 ) {
   let sudo: KeyringPair;
+  //   let lead = leadArray[0];
 
   tap.test('Set lead test', async () => {
     sudo = keyring.addFromUri(sudoUri);
-    await apiWrapper.sudoSetLead(sudo, membersKeyPairs[0]);
+    const lead = leadArray[0];
+    await apiWrapper.sudoSetLead(sudo, lead);
   });
 
   tap.test('Add worker opening', async () => {
     const addWorkerOpeningFee: BN = apiWrapper.estimateAddWorkerOpeningFee();
-    apiWrapper.transferBalance(sudo, membersKeyPairs[0].address, addWorkerOpeningFee.muln(membersKeyPairs.length));
-    apiWrapper.addWorkerOpening(membersKeyPairs[0], 'CurrentBlock', 'some text');
+    await apiWrapper.transferBalance(sudo, lead.address, addWorkerOpeningFee);
+    const workerOpeningId: BN = await apiWrapper.getNextWorkerOpeningId();
+    await apiWrapper.addWorkerOpening(lead, membersKeyPairs.length, 'some text');
+    console.log('test in process 1');
+
+    const beginAcceptingApplicationsFee = apiWrapper.estimateAcceptWorkerApplicationsFee();
+    await apiWrapper.transferBalance(sudo, lead.address, beginAcceptingApplicationsFee);
+    await apiWrapper.acceptWorkerApplications(lead, workerOpeningId);
+    console.log('test in process 2');
+    //   });
+
+    //   tap.test('Apply for worker opening', async () => {
+    const nextApplicationId: BN = await apiWrapper.getNextApplicationId();
+    const applyOnOpeningFee: BN = apiWrapper.estimateApplyOnOpeningFee(lead);
+    await apiWrapper.transferBalanceToAccounts(sudo, membersKeyPairs, applyOnOpeningFee);
+    await apiWrapper.batchApplyOnWorkerOpening(membersKeyPairs, workerOpeningId);
+    console.log('test in process 3');
+    //   });
+
+    //   tap.test('Begin worker application review', async () => {
+    const beginReviewFee: BN = apiWrapper.estimateBeginWorkerApplicantReviewFee();
+    await apiWrapper.beginWorkerApplicationReview(lead);
+    console.log('test in process 4');
+    //   });
+
+    //   tap.test('Fill worker opening', async () => {
+    const fillWorkerOpeningFee: BN = apiWrapper.estimateFillWorkerOpeningFee();
+    await apiWrapper.transferBalance(sudo, lead.address, fillWorkerOpeningFee.muln(membersKeyPairs.length));
+    await apiWrapper.batchFillWorkerOpening(lead, membersKeyPairs, nextApplicationId, workerOpeningId);
   });
 }

+ 3 - 1
tests/network-tests/src/nicaea/tests/bureaucracy/workerApplicationHappyCaseTest.ts

@@ -14,6 +14,7 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   registerJoystreamTypes();
 
   const nKeyPairs: KeyringPair[] = new Array();
+  const leadKeyPair: KeyringPair[] = new Array();
 
   const keyring = new Keyring({ type: 'sr25519' });
   const N: number = +process.env.WORKING_GROUP_N!;
@@ -27,7 +28,8 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
 
   setTestTimeout(apiWrapper, durationInBlocks);
   membershipTest(apiWrapper, nKeyPairs, keyring, N, paidTerms, sudoUri);
-  workerApplicationHappyCase(apiWrapper, nKeyPairs, keyring, sudoUri);
+  membershipTest(apiWrapper, leadKeyPair, keyring, N, paidTerms, sudoUri);
+  workerApplicationHappyCase(apiWrapper, nKeyPairs, leadKeyPair, keyring, sudoUri);
 
   closeApi(apiWrapper);
 });

+ 100 - 6
tests/network-tests/src/nicaea/utils/apiWrapper.ts

@@ -254,6 +254,37 @@ export class ApiWrapper {
     );
   }
 
+  public estimateAcceptWorkerApplicationsFee(): BN {
+    return this.estimateTxFee(this.api.tx.forumBureaucracy.acceptWorkerApplications(0));
+  }
+
+  public estimateApplyOnOpeningFee(account: KeyringPair): BN {
+    return this.estimateTxFee(
+      this.api.tx.forumBureaucracy.applyOnWorkerOpening(
+        0,
+        0,
+        account.address,
+        0,
+        0,
+        'Some testing text used for estimation purposes which is longer than text expected during the test'
+      )
+    );
+  }
+
+  public estimateBeginWorkerApplicantReviewFee(): BN {
+    return this.estimateTxFee(this.api.tx.forumBureaucracy.beginWorkerApplicantReview(0));
+  }
+
+  public estimateFillWorkerOpeningFee(): BN {
+    return this.estimateTxFee(
+      this.api.tx.forumBureaucracy.fillWorkerOpening(0, [0], {
+        amount_per_payout: 0,
+        next_payment_at_block: 0,
+        payout_interval: 0,
+      })
+    );
+  }
+
   private applyForCouncilElection(account: KeyringPair, amount: BN): Promise<void> {
     return this.sender.signAndSend(this.api.tx.councilElection.apply(amount), account, false);
   }
@@ -653,10 +684,11 @@ export class ApiWrapper {
     );
   }
 
-  public async addWorkerOpening(account: KeyringPair, activateAt: string, text: string): Promise<void> {
+  public async addWorkerOpening(account: KeyringPair, maxActiveApplicants: number, text: string): Promise<void> {
+    //TODO add text as soon as opening text limitations will be introduced in migrations
     const commitment = {
-      application_rationing_policy: { max_active_applicants: '32' },
-      max_review_period_length: 2,
+      application_rationing_policy: { max_active_applicants: maxActiveApplicants },
+      max_review_period_length: 32,
       application_staking_policy: {
         amount: 0,
         amount_mode: 'AtLeast',
@@ -671,8 +703,8 @@ export class ApiWrapper {
       },
       role_slashing_terms: {
         Slashable: {
-          max_count: 0,
-          max_percent_pts_per_time: 0,
+          max_count: 1,
+          max_percent_pts_per_time: 100,
         },
       },
       fill_opening_successful_applicant_application_stake_unstaking_period: 0,
@@ -684,12 +716,66 @@ export class ApiWrapper {
       exit_curator_role_stake_unstaking_period: 0,
     };
     await this.sender.signAndSend(
-      this.api.tx.forumBureaucracy.addWorkerOpening(activateAt, commitment, text),
+      this.api.tx.forumBureaucracy.addWorkerOpening('CurrentBlock', commitment, ''),
       account,
       false
     );
   }
 
+  public async acceptWorkerApplications(account: KeyringPair, workerOpeningId: BN): Promise<void> {
+    return this.sender.signAndSend(
+      this.api.tx.forumBureaucracy.acceptWorkerApplications(workerOpeningId),
+      account,
+      false
+    );
+  }
+
+  public async beginWorkerApplicationReview(account: KeyringPair): Promise<void> {
+    return this.sender.signAndSend(this.api.tx.forumBureaucracy.beginWorkerApplicantReview(), account, false);
+  }
+
+  public async applyOnWorkerOpening(account: KeyringPair, workerOpeningId: BN): Promise<void> {
+    const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
+    return this.sender.signAndSend(
+      this.api.tx.forumBureaucracy.applyOnWorkerOpening(memberId, workerOpeningId, account.address, 0, 0, ''),
+      account,
+      false
+    );
+  }
+
+  public async batchApplyOnWorkerOpening(accounts: KeyringPair[], workerOpeningId: BN): Promise<void[]> {
+    return Promise.all(
+      accounts.map(async keyPair => {
+        await this.applyOnWorkerOpening(keyPair, workerOpeningId);
+      })
+    );
+  }
+
+  public async fillWorkerOpening(account: KeyringPair, workerOpeningId: BN, applicationId: BN): Promise<void> {
+    return this.sender.signAndSend(
+      this.api.tx.forumBureaucracy.fillWorkerOpening(workerOpeningId, [applicationId], {
+        amount_per_payout: 0,
+        next_payment_at_block: 0,
+        payout_interval: 0,
+      }),
+      account,
+      false
+    );
+  }
+
+  public async batchFillWorkerOpening(
+    lead: KeyringPair,
+    accounts: KeyringPair[],
+    firstApplicationId: BN,
+    workerOpeningId: BN
+  ): Promise<void[]> {
+    return Promise.all(
+      accounts.map(async (keyPair, index) => {
+        await this.fillWorkerOpening(lead, workerOpeningId, firstApplicationId.addn(index));
+      })
+    );
+  }
+
   public async getStorageRoleParameters(): Promise<RoleParameters> {
     return (await this.api.query.actors.parameters<Option<RoleParameters>>('StorageProvider')).unwrap();
   }
@@ -725,4 +811,12 @@ export class ApiWrapper {
   public async getMinVotingStake(): Promise<BN> {
     return await this.api.query.councilElection.minVotingStake<BalanceOf>();
   }
+
+  public async getNextWorkerOpeningId(): Promise<BN> {
+    return await this.api.query.forumBureaucracy.nextWorkerOpeningId<u32>();
+  }
+
+  public async getNextApplicationId(): Promise<BN> {
+    return await this.api.query.forumBureaucracy.nextWorkerApplicationId<u32>();
+  }
 }