Pārlūkot izejas kodu

woker application happy case without assertions

Gleb Urvanov 4 gadi atpakaļ
vecāks
revīzija
c1c45f579e

+ 6 - 1
tests/network-tests/.env

@@ -25,4 +25,9 @@ VALIDATOR_COUNT_INCREMENT = 2
 # Constantinople runtime path
 RUNTIME_WASM_PATH = ../../target/release/wbuild/joystream-node-runtime/joystream_node_runtime.compact.wasm
 # Working group size N
-WORKING_GROUP_N = 2
+WORKING_GROUP_N = 3
+# Working group application stake
+WORKING_GROUP_APPLICATION_STAKE = 1
+# Working group role stake
+WORKING_GROUP_ROLE_STAKE = 1
+

+ 51 - 26
tests/network-tests/src/nicaea/tests/bureaucracy/impl/workerApplicationHappyCase.ts

@@ -3,53 +3,78 @@ import { ApiWrapper } from '../../../utils/apiWrapper';
 import { KeyringPair } from '@polkadot/keyring/types';
 import { Keyring } from '@polkadot/api';
 import BN from 'bn.js';
+import { Utils } from '../../../utils/utils';
 
 export function workerApplicationHappyCase(
   apiWrapper: ApiWrapper,
   membersKeyPairs: KeyringPair[],
   leadArray: KeyringPair[],
   keyring: Keyring,
-  sudoUri: string
+  sudoUri: string,
+  applicationStake: BN,
+  roleStake: BN
 ) {
   let sudo: KeyringPair;
-  //   let lead = leadArray[0];
+  let lead: KeyringPair;
 
   tap.test('Set lead test', async () => {
     sudo = keyring.addFromUri(sudoUri);
-    const lead = leadArray[0];
+    lead = leadArray[0];
     await apiWrapper.sudoSetLead(sudo, lead);
   });
 
   tap.test('Add worker opening', async () => {
+    //Fee estimation and transfer
     const addWorkerOpeningFee: BN = apiWrapper.estimateAddWorkerOpeningFee();
-    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 beginReviewFee: BN = apiWrapper.estimateBeginWorkerApplicantReviewFee();
+    const fillWorkerOpeningFee: BN = apiWrapper.estimateFillWorkerOpeningFee();
+    await apiWrapper.transferBalance(
+      sudo,
+      lead.address,
+      addWorkerOpeningFee.add(beginReviewFee).add(fillWorkerOpeningFee)
+    );
 
-    const beginAcceptingApplicationsFee = apiWrapper.estimateAcceptWorkerApplicationsFee();
-    await apiWrapper.transferBalance(sudo, lead.address, beginAcceptingApplicationsFee);
-    await apiWrapper.acceptWorkerApplications(lead, workerOpeningId);
-    console.log('test in process 2');
-    //   });
+    //Worker opening creation
+    const workerOpeningId: BN = await apiWrapper.getNextWorkerOpeningId();
+    await apiWrapper.addWorkerOpening(
+      lead,
+      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),
+      ''
+    );
 
-    //   tap.test('Apply for worker opening', async () => {
+    //Applying for created worker opening
     const nextApplicationId: BN = await apiWrapper.getNextApplicationId();
-    const applyOnOpeningFee: BN = apiWrapper.estimateApplyOnOpeningFee(lead);
+    const applyOnOpeningFee: BN = apiWrapper.estimateApplyOnOpeningFee(lead).add(applicationStake).add(roleStake);
     await apiWrapper.transferBalanceToAccounts(sudo, membersKeyPairs, applyOnOpeningFee);
-    await apiWrapper.batchApplyOnWorkerOpening(membersKeyPairs, workerOpeningId);
-    console.log('test in process 3');
-    //   });
+    await apiWrapper.batchApplyOnWorkerOpening(membersKeyPairs, workerOpeningId, roleStake, applicationStake, '');
 
-    //   tap.test('Begin worker application review', async () => {
-    const beginReviewFee: BN = apiWrapper.estimateBeginWorkerApplicantReviewFee();
-    await apiWrapper.beginWorkerApplicationReview(lead);
-    console.log('test in process 4');
-    //   });
+    //Begin application review
+    await apiWrapper.beginWorkerApplicationReview(lead, workerOpeningId);
 
-    //   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);
+    //Fill worker opening
+    await apiWrapper.fillWorkerOpening(
+      lead,
+      workerOpeningId,
+      Utils.getNextNIds(nextApplicationId, membersKeyPairs.length),
+      new BN(1),
+      new BN(99999999),
+      new BN(99999999)
+    );
   });
 }

+ 5 - 2
tests/network-tests/src/nicaea/tests/bureaucracy/workerApplicationHappyCaseTest.ts

@@ -8,6 +8,7 @@ import { KeyringPair } from '@polkadot/keyring/types';
 import { setTestTimeout } from '../../utils/setTestTimeout';
 import { membershipTest } from '../impl/membershipCreation';
 import { workerApplicationHappyCase } from './impl/workerApplicationHappyCase';
+import BN from 'bn.js';
 
 tap.mocha.describe('Worker application happy case scenario', async () => {
   initConfig();
@@ -21,7 +22,9 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   const paidTerms: number = +process.env.MEMBERSHIP_PAID_TERMS!;
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
-  const durationInBlocks: number = 25;
+  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 = 100;
 
   const provider = new WsProvider(nodeUrl);
   const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
@@ -29,7 +32,7 @@ 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);
-  workerApplicationHappyCase(apiWrapper, nKeyPairs, leadKeyPair, keyring, sudoUri);
+  workerApplicationHappyCase(apiWrapper, nKeyPairs, leadKeyPair, keyring, sudoUri, applicationStake, roleStake);
 
   closeApi(apiWrapper);
 });

+ 139 - 54
tests/network-tests/src/nicaea/utils/apiWrapper.ts

@@ -222,7 +222,7 @@ export class ApiWrapper {
         'CurrentBlock',
         {
           application_rationing_policy: { max_active_applicants: '32' },
-          max_review_period_length: 2,
+          max_review_period_length: 32,
           application_staking_policy: {
             amount: 0,
             amount_mode: 'AtLeast',
@@ -684,44 +684,112 @@ export class ApiWrapper {
     );
   }
 
-  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
+  public async addWorkerOpening(
+    account: 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
+  ): Promise<void> {
     const commitment = {
       application_rationing_policy: { max_active_applicants: maxActiveApplicants },
-      max_review_period_length: 32,
+      max_review_period_length: maxReviewPeriodLength,
       application_staking_policy: {
-        amount: 0,
+        amount: applicationStakingPolicyAmount,
         amount_mode: 'AtLeast',
-        crowded_out_unstaking_period_length: 0,
-        review_period_expired_unstaking_period_length: 0,
+        crowded_out_unstaking_period_length: applicationCrowdedOutUnstakingPeriodLength,
+        review_period_expired_unstaking_period_length: applicationExpiredUnstakingPeriodLength,
       },
       role_staking_policy: {
-        amount: 0,
+        amount: roleStakingPolicyAmount,
         amount_mode: 'AtLeast',
-        crowded_out_unstaking_period_length: 0,
-        review_period_expired_unstaking_period_length: 0,
+        crowded_out_unstaking_period_length: roleCrowdedOutUnstakingPeriodLength,
+        review_period_expired_unstaking_period_length: roleExpiredUnstakingPeriodLength,
       },
       role_slashing_terms: {
         Slashable: {
-          max_count: 1,
-          max_percent_pts_per_time: 100,
+          max_count: slashableMaxCount,
+          max_percent_pts_per_time: slashableMaxPercentPtsPerTime,
         },
       },
-      fill_opening_successful_applicant_application_stake_unstaking_period: 0,
-      fill_opening_failed_applicant_application_stake_unstaking_period: 0,
-      fill_opening_failed_applicant_role_stake_unstaking_period: 0,
-      terminate_curator_application_stake_unstaking_period: 0,
-      terminate_curator_role_stake_unstaking_period: 0,
-      exit_curator_role_application_stake_unstaking_period: 0,
-      exit_curator_role_stake_unstaking_period: 0,
+      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.forumBureaucracy.addWorkerOpening('CurrentBlock', commitment, ''),
+      this.api.tx.forumBureaucracy.addWorkerOpening('CurrentBlock', commitment, text),
       account,
       false
     );
   }
 
+  public async batchAddWorkerOpening(
+    lead: KeyringPair,
+    accounts: 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
+  ): Promise<void[]> {
+    return Promise.all(
+      accounts.map(async () => {
+        await this.addWorkerOpening(
+          lead,
+          maxActiveApplicants,
+          maxReviewPeriodLength,
+          applicationStakingPolicyAmount,
+          applicationCrowdedOutUnstakingPeriodLength,
+          applicationExpiredUnstakingPeriodLength,
+          roleStakingPolicyAmount,
+          roleCrowdedOutUnstakingPeriodLength,
+          roleExpiredUnstakingPeriodLength,
+          slashableMaxCount,
+          slashableMaxPercentPtsPerTime,
+          successfulApplicantApplicationStakeUnstakingPeriod,
+          failedApplicantApplicationStakeUnstakingPeriod,
+          failedApplicantRoleStakeUnstakingPeriod,
+          terminateCuratorApplicationStakeUnstakingPeriod,
+          terminateCuratorRoleStakeUnstakingPeriod,
+          exitCuratorRoleApplicationStakeUnstakingPeriod,
+          exitCuratorRoleStakeUnstakingPeriod,
+          text
+        );
+      })
+    );
+  }
+
   public async acceptWorkerApplications(account: KeyringPair, workerOpeningId: BN): Promise<void> {
     return this.sender.signAndSend(
       this.api.tx.forumBureaucracy.acceptWorkerApplications(workerOpeningId),
@@ -730,93 +798,110 @@ export class ApiWrapper {
     );
   }
 
-  public async beginWorkerApplicationReview(account: KeyringPair): Promise<void> {
-    return this.sender.signAndSend(this.api.tx.forumBureaucracy.beginWorkerApplicantReview(), account, false);
+  public async beginWorkerApplicationReview(account: KeyringPair, workerOpeningId: BN): Promise<void> {
+    return this.sender.signAndSend(
+      this.api.tx.forumBureaucracy.beginWorkerApplicantReview(workerOpeningId),
+      account,
+      false
+    );
   }
 
-  public async applyOnWorkerOpening(account: KeyringPair, workerOpeningId: BN): Promise<void> {
+  public async applyOnWorkerOpening(
+    account: KeyringPair,
+    workerOpeningId: BN,
+    roleStake: BN,
+    applicantStake: BN,
+    text: string
+  ): 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, ''),
+      this.api.tx.forumBureaucracy.applyOnWorkerOpening(
+        memberId,
+        workerOpeningId,
+        account.address,
+        roleStake,
+        applicantStake,
+        text
+      ),
       account,
       false
     );
   }
 
-  public async batchApplyOnWorkerOpening(accounts: KeyringPair[], workerOpeningId: BN): Promise<void[]> {
+  public async batchApplyOnWorkerOpening(
+    accounts: KeyringPair[],
+    workerOpeningId: BN,
+    roleStake: BN,
+    applicantStake: BN,
+    text: string
+  ): Promise<void[]> {
     return Promise.all(
       accounts.map(async keyPair => {
-        await this.applyOnWorkerOpening(keyPair, workerOpeningId);
+        await this.applyOnWorkerOpening(keyPair, workerOpeningId, roleStake, applicantStake, text);
       })
     );
   }
 
-  public async fillWorkerOpening(account: KeyringPair, workerOpeningId: BN, applicationId: BN): Promise<void> {
+  public async fillWorkerOpening(
+    account: KeyringPair,
+    workerOpeningId: BN,
+    applicationId: BN[],
+    amountPerPayout: BN,
+    nextPaymentBlock: BN,
+    payoutInterval: 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,
+      this.api.tx.forumBureaucracy.fillWorkerOpening(workerOpeningId, applicationId, {
+        amount_per_payout: amountPerPayout,
+        next_payment_at_block: nextPaymentBlock,
+        payout_interval: payoutInterval,
       }),
       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();
   }
 
   public async getAnnouncingPeriod(): Promise<BN> {
-    return await this.api.query.councilElection.announcingPeriod<BlockNumber>();
+    return this.api.query.councilElection.announcingPeriod<BlockNumber>();
   }
 
   public async getVotingPeriod(): Promise<BN> {
-    return await this.api.query.councilElection.votingPeriod<BlockNumber>();
+    return this.api.query.councilElection.votingPeriod<BlockNumber>();
   }
 
   public async getRevealingPeriod(): Promise<BN> {
-    return await this.api.query.councilElection.revealingPeriod<BlockNumber>();
+    return this.api.query.councilElection.revealingPeriod<BlockNumber>();
   }
 
   public async getCouncilSize(): Promise<BN> {
-    return await this.api.query.councilElection.councilSize<u32>();
+    return this.api.query.councilElection.councilSize<u32>();
   }
 
   public async getCandidacyLimit(): Promise<BN> {
-    return await this.api.query.councilElection.candidacyLimit<u32>();
+    return this.api.query.councilElection.candidacyLimit<u32>();
   }
 
   public async getNewTermDuration(): Promise<BN> {
-    return await this.api.query.councilElection.newTermDuration<BlockNumber>();
+    return this.api.query.councilElection.newTermDuration<BlockNumber>();
   }
 
   public async getMinCouncilStake(): Promise<BN> {
-    return await this.api.query.councilElection.minCouncilStake<BalanceOf>();
+    return this.api.query.councilElection.minCouncilStake<BalanceOf>();
   }
 
   public async getMinVotingStake(): Promise<BN> {
-    return await this.api.query.councilElection.minVotingStake<BalanceOf>();
+    return this.api.query.councilElection.minVotingStake<BalanceOf>();
   }
 
   public async getNextWorkerOpeningId(): Promise<BN> {
-    return await this.api.query.forumBureaucracy.nextWorkerOpeningId<u32>();
+    return this.api.query.forumBureaucracy.nextWorkerOpeningId<u32>();
   }
 
   public async getNextApplicationId(): Promise<BN> {
-    return await this.api.query.forumBureaucracy.nextWorkerApplicationId<u32>();
+    return this.api.query.forumBureaucracy.nextWorkerApplicationId<u32>();
   }
 }

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

@@ -32,7 +32,6 @@ export class Utils {
     voteU8a.set(saltU8a, accountU8a.length);
 
     const hash = blake2AsHex(voteU8a, 256);
-    // console.log('Vote hash:', hash, 'for', { accountId, salt });
     return hash;
   }
 
@@ -47,4 +46,12 @@ export class Utils {
   public static readRuntimeFromFile(path: string): string {
     return '0x' + fs.readFileSync(path).toString('hex');
   }
+
+  public static getNextNIds(firstId: BN, n: number): BN[] {
+    let result: BN[] = new Array();
+    for (let i = 0; i < n; i++) {
+      result.push(firstId.addn(i));
+    }
+    return result;
+  }
 }