Browse Source

add opening, begin review proposals testing finished

Gleb Urvanov 4 years ago
parent
commit
3f9fe8d24b

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

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

+ 41 - 5
tests/network-tests/src/nicaea/tests/proposals/addWorkingGroupLeaderTest.ts

@@ -8,8 +8,14 @@ import { setTestTimeout } from '../../utils/setTestTimeout';
 import tap from 'tap';
 import { registerJoystreamTypes } from '@nicaea/types';
 import { closeApi } from '../impl/closeApi';
-import { ApiWrapper } from '../../utils/apiWrapper';
-import { createWorkingGroupLeaderOpening, voteForProposal } from './impl/proposalsModule';
+import { ApiWrapper, WorkingGroups } from '../../utils/apiWrapper';
+import {
+  createWorkingGroupLeaderOpening,
+  voteForProposal,
+  beginWorkingGroupLeaderApplicationReview,
+  expectLeadOpeningAdded,
+} from './impl/proposalsModule';
+import { applyForOpening } from '../workingGroup/impl/workingGroupModule';
 
 tap.mocha.describe('Set lead proposal scenario', async () => {
   initConfig();
@@ -17,6 +23,7 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
 
   const m1KeyPairs: KeyringPair[] = new Array();
   const m2KeyPairs: KeyringPair[] = new Array();
+  const leadKeyPair: KeyringPair[] = new Array();
 
   const keyring = new Keyring({ type: 'sr25519' });
   const N: number = +process.env.MEMBERSHIP_CREATION_N!;
@@ -28,7 +35,7 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
   const lesserStake: BN = new BN(+process.env.COUNCIL_STAKE_LESSER_AMOUNT!);
   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 = 29;
+  const durationInBlocks: number = 40;
 
   const provider = new WsProvider(nodeUrl);
   const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
@@ -37,15 +44,44 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
   setTestTimeout(apiWrapper, durationInBlocks);
   membershipTest(apiWrapper, m1KeyPairs, keyring, N, paidTerms, sudoUri);
   membershipTest(apiWrapper, m2KeyPairs, keyring, N, paidTerms, sudoUri);
+  membershipTest(apiWrapper, leadKeyPair, keyring, 1, paidTerms, sudoUri);
   councilTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, K, sudoUri, greaterStake, lesserStake);
 
   let proposalId: BN;
+  let openingId: BN;
   tap.test(
     'Create leader opening',
     async () =>
-      (proposalId = await createWorkingGroupLeaderOpening(apiWrapper, m1KeyPairs, sudo, applicationStake, roleStake))
+      (proposalId = await createWorkingGroupLeaderOpening(
+        apiWrapper,
+        m1KeyPairs,
+        sudo,
+        applicationStake,
+        roleStake,
+        'Storage'
+      ))
+  );
+  tap.test('Approve proposal', async () => {
+    voteForProposal(apiWrapper, m2KeyPairs, sudo, proposalId);
+    openingId = await expectLeadOpeningAdded(apiWrapper);
+  });
+  tap.test(
+    'Apply for lead opening',
+    async () =>
+      await applyForOpening(
+        apiWrapper,
+        leadKeyPair,
+        sudo,
+        applicationStake,
+        roleStake,
+        new BN(openingId),
+        WorkingGroups.storageWorkingGroup,
+        false
+      )
+  );
+  tap.test('Begin leader application review', async () =>
+    beginWorkingGroupLeaderApplicationReview(apiWrapper, m1KeyPairs, sudo, new BN(openingId), 'Storage')
   );
-  tap.test('Approve proposal', async () => voteForProposal(apiWrapper, m2KeyPairs, sudo, proposalId));
 
   closeApi(apiWrapper);
 });

+ 29 - 29
tests/network-tests/src/nicaea/tests/proposals/impl/proposalsModule.ts

@@ -3,13 +3,15 @@ import { ApiWrapper, WorkingGroups } from '../../../utils/apiWrapper';
 import { v4 as uuid } from 'uuid';
 import BN from 'bn.js';
 import { assert } from 'chai';
+import { WorkingGroupOpening } from '../../../dto/workingGroupOpening';
 
 export async function createWorkingGroupLeaderOpening(
   apiWrapper: ApiWrapper,
   m1KeyPairs: KeyringPair[],
   sudo: KeyringPair,
   applicationStake: BN,
-  roleStake: BN
+  roleStake: BN,
+  workingGroup: string
 ): Promise<BN> {
   // Setup
   const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -20,6 +22,27 @@ export async function createWorkingGroupLeaderOpening(
   const proposalFee: BN = apiWrapper.estimateProposeCreateWorkingGroupLeaderOpening();
   await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, proposalFee.add(proposalStake));
 
+  // Opening construction
+  let opening = new WorkingGroupOpening();
+  opening.setMaxActiveApplicants(new BN(m1KeyPairs.length));
+  opening.setMaxReviewPeriodLength(new BN(32));
+  opening.setApplicationStakingPolicyAmount(new BN(applicationStake));
+  opening.setApplicationCrowdedOutUnstakingPeriodLength(new BN(0));
+  opening.setApplicationExpiredUnstakingPeriodLength(new BN(0));
+  opening.setRoleStakingPolicyAmount(new BN(roleStake));
+  opening.setRoleCrowdedOutUnstakingPeriodLength(new BN(0));
+  opening.setRoleExpiredUnstakingPeriodLength(new BN(0));
+  opening.setSlashableMaxCount(new BN(1));
+  opening.setSlashableMaxPercentPtsPerTime(new BN(100));
+  opening.setSuccessfulApplicantApplicationStakeUnstakingPeriod(new BN(1));
+  opening.setFailedApplicantApplicationStakeUnstakingPeriod(new BN(1));
+  opening.setFailedApplicantRoleStakeUnstakingPeriod(new BN(1));
+  opening.setTerminateCuratorApplicationStakeUnstakingPeriod(new BN(1));
+  opening.setTerminateCuratorRoleStakeUnstakingPeriod(new BN(1));
+  opening.setExitCuratorRoleApplicationStakeUnstakingPeriod(new BN(1));
+  opening.setExitCuratorRoleStakeUnstakingPeriod(new BN(1));
+  opening.setText(uuid().substring(0, 8));
+
   // Proposal creation
   const proposalPromise = apiWrapper.expectProposalCreated();
   await apiWrapper.proposeCreateWorkingGroupLeaderOpening(
@@ -27,25 +50,8 @@ export async function createWorkingGroupLeaderOpening(
     proposalTitle,
     description,
     proposalStake,
-    await apiWrapper.getBestBlock(),
-    new BN(32),
-    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)
+    opening,
+    workingGroup
   );
   const proposalNumber: BN = await proposalPromise;
   return proposalNumber;
@@ -63,7 +69,7 @@ export async function beginWorkingGroupLeaderApplicationReview(
   const description: string = 'Testing begin working group lead application review proposal ' + uuid().substring(0, 8);
 
   // Proposal stake calculation
-  const proposalStake: BN = new BN(100000);
+  const proposalStake: BN = new BN(25000);
   const proposalFee: BN = apiWrapper.estimateProposeBeginWorkingGroupLeaderApplicationReview();
   await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, proposalFee.add(proposalStake));
 
@@ -96,12 +102,6 @@ export async function voteForProposal(
   await proposalExecutionPromise;
 }
 
-export async function ensureLeadOpeningCreated(apiWrapper: ApiWrapper, m1KeyPairs: KeyringPair[], sudo: KeyringPair) {
-  // Assertions
-  //   const opening = apiWrapper.getApplicationById();
-  //   const newLead: string = await apiWrapper.getCurrentLeadAddress();
-  //   assert(
-  //     newLead === m1KeyPairs[1].address,
-  //     `New lead has unexpected value ${newLead}, expected ${m1KeyPairs[1].address}`
-  //   );
+export async function expectLeadOpeningAdded(apiWrapper: ApiWrapper): Promise<BN> {
+  return apiWrapper.expectOpeningAdded();
 }

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

@@ -310,6 +310,51 @@ export class ApiWrapper {
     );
   }
 
+  public estimateProposeCreateWorkingGroupLeaderOpening(): BN {
+    return this.estimateTxFee(
+      this.api.tx.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
+        0,
+        'some long title for the purpose of testing',
+        'some long description for the purpose of testing',
+        0,
+        {
+          activate_at: 'CurrentBlock',
+          commitment: {
+            application_rationing_policy: { max_active_applicants: '32' },
+            max_review_period_length: 32,
+            application_staking_policy: {
+              amount: 0,
+              amount_mode: 'AtLeast',
+              crowded_out_unstaking_period_length: 0,
+              review_period_expired_unstaking_period_length: 0,
+            },
+            role_staking_policy: {
+              amount: 0,
+              amount_mode: 'AtLeast',
+              crowded_out_unstaking_period_length: 0,
+              review_period_expired_unstaking_period_length: 0,
+            },
+            role_slashing_terms: {
+              Slashable: {
+                max_count: 0,
+                max_percent_pts_per_time: 0,
+              },
+            },
+            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,
+          },
+          human_readable_text: 'Opening readable text',
+          working_group: 'Storage',
+        }
+      )
+    );
+  }
+
   public estimateProposeBeginWorkingGroupLeaderApplicationReview(): BN {
     return this.estimateTxFee(
       this.api.tx.proposalsCodex.createBeginReviewWorkingGroupLeaderApplicationsProposal(
@@ -794,6 +839,33 @@ export class ApiWrapper {
     );
   }
 
+  public async proposeCreateWorkingGroupLeaderOpening(
+    account: KeyringPair,
+    title: string,
+    description: string,
+    proposalStake: BN,
+    opening: WorkingGroupOpening,
+    workingGroup: string
+  ): Promise<void> {
+    const memberId: BN = (await this.getMemberIds(account.address))[0];
+    await this.sender.signAndSend(
+      this.api.tx.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
+        memberId,
+        title,
+        description,
+        proposalStake,
+        {
+          activate_at: opening.getActivateAt(),
+          commitment: opening.getCommitment(),
+          human_readable_text: opening.getText(),
+          working_group: workingGroup,
+        }
+      ),
+      account,
+      false
+    );
+  }
+
   private createAddOpeningTransaction(
     opening: WorkingGroupOpening,
     module: WorkingGroups