Browse Source

leader hiring happy case scenario

Gleb Urvanov 4 years ago
parent
commit
9463eacfb1

+ 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/proposals/addWorkingGroupLeaderTest.ts -T",
+    "debug": "tap --files src/nicaea/tests/proposals/leaderHiringHappyCase.ts -T",
     "lint": "tslint --project tsconfig.json",
     "prettier": "prettier --write ./src"
   },

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

@@ -96,12 +96,12 @@ export async function fillLeaderOpeningProposal(
   rewardInterval: BN,
   payoutAmount: BN,
   openingId: BN,
-  workingGroup: string
+  workingGroup: WorkingGroups
 ): Promise<BN> {
   // Setup
-  console.log('lead address: ' + applicantRoleAccountAddress);
   const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
   const description: string = 'Testing fill opening proposal ' + uuid().substring(0, 8);
+  const workingGroupString: string = apiWrapper.getWorkingGroupString(workingGroup);
 
   // Proposal stake calculation
   const proposalStake: BN = new BN(50000);
@@ -110,10 +110,7 @@ export async function fillLeaderOpeningProposal(
 
   // Proposal creation
   const applicationId: BN = (
-    await apiWrapper.getActiveApplicationsIdsByRoleAccount(
-      applicantRoleAccountAddress,
-      WorkingGroups.storageWorkingGroup
-    )
+    await apiWrapper.getActiveApplicationsIdsByRoleAccount(applicantRoleAccountAddress, workingGroup)
   )[0];
   const now = await apiWrapper.getBestBlock();
   let fillOpeningParameters: FillOpeningParameters = new FillOpeningParameters();
@@ -122,7 +119,7 @@ export async function fillLeaderOpeningProposal(
   fillOpeningParameters.setPayoutInterval(rewardInterval);
   fillOpeningParameters.setOpeningId(openingId);
   fillOpeningParameters.setSuccessfulApplicationId(applicationId);
-  fillOpeningParameters.setWorkingGroup(workingGroup);
+  fillOpeningParameters.setWorkingGroup(workingGroupString);
 
   const proposalPromise = apiWrapper.expectProposalCreated();
   await apiWrapper.proposeFillLeaderOpening(
@@ -136,12 +133,48 @@ export async function fillLeaderOpeningProposal(
   return proposalNumber;
 }
 
+export async function terminateLeaderRoleProposal(
+  apiWrapper: ApiWrapper,
+  m1KeyPairs: KeyringPair[],
+  leaderRoleAccountAddress: string,
+  sudo: KeyringPair,
+  slash: boolean,
+  workingGroup: WorkingGroups
+) {
+  // Setup
+  const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
+  const description: string = 'Testing begin working group lead application review proposal ' + uuid().substring(0, 8);
+  const rationale: string = 'Testing leader termination ' + uuid().substring(0, 8);
+  const workingGroupString: string = apiWrapper.getWorkingGroupString(workingGroup);
+  const workerId: BN = await apiWrapper.getWorkerIdByRoleAccount(leaderRoleAccountAddress, workingGroup);
+
+  // Proposal stake calculation
+  const proposalStake: BN = new BN(100000);
+  const proposalFee: BN = apiWrapper.estimateProposeTerminateLeaderRole();
+  await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, proposalFee.add(proposalStake));
+
+  // Proposal creation
+  const proposalPromise = apiWrapper.expectProposalCreated();
+  await apiWrapper.proposeTerminateLeaderRole(
+    m1KeyPairs[0],
+    proposalTitle,
+    description,
+    proposalStake,
+    workerId,
+    rationale,
+    slash,
+    workingGroupString
+  );
+  const proposalNumber: BN = await proposalPromise;
+  return proposalNumber;
+}
+
 export async function voteForProposal(
   apiWrapper: ApiWrapper,
   m2KeyPairs: KeyringPair[],
   sudo: KeyringPair,
   proposalNumber: BN
-) {
+): Promise<void> {
   const proposalVoteFee: BN = apiWrapper.estimateVoteForProposalFee();
   await apiWrapper.transferBalanceToAccounts(sudo, m2KeyPairs, proposalVoteFee);
 

+ 26 - 4
tests/network-tests/src/nicaea/tests/proposals/addWorkingGroupLeaderTest.ts → tests/network-tests/src/nicaea/tests/proposals/leaderHiringHappyCase.ts

@@ -14,12 +14,14 @@ import {
   voteForProposal,
   beginWorkingGroupLeaderApplicationReview,
   fillLeaderOpeningProposal,
+  terminateLeaderRoleProposal,
 } from './impl/proposalsModule';
 import {
   applyForOpening,
   expectLeadOpeningAdded,
   expectLeaderSet,
   expectBeganApplicationReview,
+  expectLeaderRoleTerminated,
 } from '../workingGroup/impl/workingGroupModule';
 
 tap.mocha.describe('Set lead proposal scenario', async () => {
@@ -58,7 +60,7 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
   let createOpeningProposalId: BN;
   let openingId: BN;
   tap.test(
-    'Create leader opening',
+    'Propose create leader opening',
     async () =>
       (createOpeningProposalId = await createWorkingGroupLeaderOpening(
         apiWrapper,
@@ -73,6 +75,7 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
     voteForProposal(apiWrapper, m2KeyPairs, sudo, createOpeningProposalId);
     openingId = await expectLeadOpeningAdded(apiWrapper);
   });
+
   tap.test(
     'Apply for lead opening',
     async () =>
@@ -89,7 +92,7 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
   );
   let beginReviewProposalId: BN;
   tap.test(
-    'Begin leader application review',
+    'Propose begin leader application review',
     async () =>
       (beginReviewProposalId = await beginWorkingGroupLeaderApplicationReview(
         apiWrapper,
@@ -103,9 +106,10 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
     voteForProposal(apiWrapper, m2KeyPairs, sudo, beginReviewProposalId);
     expectBeganApplicationReview(apiWrapper);
   });
+
   let fillLeaderOpeningProposalId: BN;
   tap.test(
-    'Fill leader opening',
+    'Propose fill leader opening',
     async () =>
       (fillLeaderOpeningProposalId = await fillLeaderOpeningProposal(
         apiWrapper,
@@ -116,7 +120,7 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
         rewardInterval,
         payoutAmount,
         new BN(openingId),
-        'Storage'
+        WorkingGroups.storageWorkingGroup
       ))
   );
   tap.test('Approve fill leader opening', async () => {
@@ -124,5 +128,23 @@ tap.mocha.describe('Set lead proposal scenario', async () => {
     await expectLeaderSet(apiWrapper, leadKeyPair[0].address, WorkingGroups.storageWorkingGroup);
   });
 
+  let terminateLeaderRoleProposalId: BN;
+  tap.test(
+    'Propose terminate leader role',
+    async () =>
+      (terminateLeaderRoleProposalId = await terminateLeaderRoleProposal(
+        apiWrapper,
+        m1KeyPairs,
+        leadKeyPair[0].address,
+        sudo,
+        false,
+        WorkingGroups.storageWorkingGroup
+      ))
+  );
+  tap.test('Approve leader role termination', async () => {
+    voteForProposal(apiWrapper, m2KeyPairs, sudo, terminateLeaderRoleProposalId);
+    await expectLeaderRoleTerminated(apiWrapper, WorkingGroups.storageWorkingGroup);
+  });
+
   closeApi(apiWrapper);
 });

+ 7 - 0
tests/network-tests/src/nicaea/tests/workingGroup/impl/workingGroupModule.ts

@@ -527,3 +527,10 @@ export async function expectLeaderSet(
 export async function expectBeganApplicationReview(apiWrapper: ApiWrapper): Promise<BN> {
   return apiWrapper.expectApplicationReviewBegan();
 }
+
+export async function expectLeaderRoleTerminated(apiWrapper: ApiWrapper, module: WorkingGroups): Promise<void> {
+  await apiWrapper.expectLeaderUnset();
+  const leadWorkerId: BN | undefined = await apiWrapper.getLeadWorkerId(module);
+  assert(leadWorkerId === undefined, `Unexpected lead worker id: ${leadWorkerId}, expected none`);
+  return;
+}

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

@@ -5,14 +5,7 @@ import { KeyringPair } from '@polkadot/keyring/types';
 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,
-  ApplicationIdToWorkerIdMap,
-  Opening,
-  RewardPolicy,
-} from '@nicaea/types/working-group';
+import { Application, WorkerId, Worker, ApplicationIdToWorkerIdMap, Opening } 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';
@@ -49,6 +42,15 @@ export class ApiWrapper {
     this.api.disconnect();
   }
 
+  public getWorkingGroupString(workingGroup: WorkingGroups): string {
+    switch (workingGroup) {
+      case WorkingGroups.storageWorkingGroup:
+        return 'Storage';
+      default:
+        return 'Undefined';
+    }
+  }
+
   public async buyMembership(
     account: KeyringPair,
     paidTermsId: number,
@@ -396,6 +398,23 @@ export class ApiWrapper {
     );
   }
 
+  public estimateProposeTerminateLeaderRole(): BN {
+    return this.estimateTxFee(
+      this.api.tx.proposalsCodex.createTerminateWorkingGroupLeaderRoleProposal(
+        0,
+        'Some testing text used for estimation purposes which is longer than text expected during the test',
+        'Some testing text used for estimation purposes which is longer than text expected during the test',
+        0,
+        {
+          worker_id: 0,
+          rationale: 'Exceptionaly long and extraordinary descriptive rationale',
+          slash: true,
+          working_group: 'Storage',
+        }
+      )
+    );
+  }
+
   private applyForCouncilElection(account: KeyringPair, amount: BN): Promise<void> {
     return this.sender.signAndSend(this.api.tx.councilElection.apply(amount), account, false);
   }
@@ -803,6 +822,18 @@ export class ApiWrapper {
     });
   }
 
+  public expectLeaderUnset(): Promise<void> {
+    return new Promise(async resolve => {
+      await this.api.query.system.events<Vec<EventRecord>>(events => {
+        events.forEach(record => {
+          if (record.event.method && record.event.method.toString() === 'LeaderUnset') {
+            resolve();
+          }
+        });
+      });
+    });
+  }
+
   public expectApplicationReviewBegan(): Promise<BN> {
     return new Promise(async resolve => {
       await this.api.query.system.events<Vec<EventRecord>>(events => {
@@ -927,6 +958,35 @@ export class ApiWrapper {
     );
   }
 
+  public async proposeTerminateLeaderRole(
+    account: KeyringPair,
+    title: string,
+    description: string,
+    proposalStake: BN,
+    leadWorkerId: BN,
+    rationale: string,
+    slash: boolean,
+    workingGroup: string
+  ): Promise<void> {
+    const memberId: BN = (await this.getMemberIds(account.address))[0];
+    return this.sender.signAndSend(
+      this.api.tx.proposalsCodex.createTerminateWorkingGroupLeaderRoleProposal(
+        memberId,
+        title,
+        description,
+        proposalStake,
+        {
+          worker_id: leadWorkerId,
+          rationale: rationale,
+          slash: slash,
+          working_group: workingGroup,
+        }
+      ),
+      account,
+      false
+    );
+  }
+
   private createAddOpeningTransaction(
     opening: WorkingGroupOpening,
     module: WorkingGroups
@@ -1273,4 +1333,8 @@ export class ApiWrapper {
     let rewardRelationshipId: BN = (await this.getWorkerById(workerId, module)).reward_relationship.unwrap();
     return (await this.getRewardRelationship(rewardRelationshipId)).getField('account').toString();
   }
+
+  public async getLeadWorkerId(module: WorkingGroups): Promise<BN | undefined> {
+    return (await this.api.query[module].currentLead<Option<WorkerId>>()).unwrapOr(undefined);
+  }
 }