Sfoglia il codice sorgente

added testing scenario for at least 0 bugs

Gleb Urvanov 4 anni fa
parent
commit
a4ec88c8ea

+ 2 - 0
tests/network-tests/.env

@@ -40,3 +40,5 @@ SHORT_REWARD_INTERWAL = 3
 PAYOUT_AMOUNT = 3
 # Mint capacity for storage working group
 STORAGE_WORKING_GROUP_MINTING_CAPACITY = 100000
+# Default unstaking period for storage working group
+STORAGE_WORKING_GROUP_UNSTAKING_PERIOD = 1

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

+ 132 - 0
tests/network-tests/src/nicaea/tests/workingGroup/atLeastValueBugTest.ts

@@ -0,0 +1,132 @@
+import tap from 'tap';
+import { initConfig } from '../../utils/config';
+import { registerJoystreamTypes } from '@nicaea/types';
+import { closeApi } from '../impl/closeApi';
+import { ApiWrapper, WorkingGroups } from '../../utils/apiWrapper';
+import { WsProvider, Keyring } from '@polkadot/api';
+import { KeyringPair } from '@polkadot/keyring/types';
+import { setTestTimeout } from '../../utils/setTestTimeout';
+import { membershipTest } from '../impl/membershipCreation';
+import {
+  addWorkerOpening,
+  applyForOpening,
+  addLeaderOpening,
+  beginLeaderApplicationReview,
+  fillLeaderOpening,
+  leaveRole,
+} from './impl/workingGroupModule';
+import BN from 'bn.js';
+
+tap.mocha.describe('Worker application happy case scenario', async () => {
+  initConfig();
+  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!;
+  const paidTerms: number = +process.env.MEMBERSHIP_PAID_TERMS!;
+  const nodeUrl: string = process.env.NODE_URL!;
+  const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
+  const applicationStake: BN = new BN(process.env.WORKING_GROUP_APPLICATION_STAKE!);
+  const roleStake: BN = new BN(process.env.WORKING_GROUP_ROLE_STAKE!);
+  const firstRewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
+  const rewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
+  const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
+  const unstakingPeriod: BN = new BN(process.env.STORAGE_WORKING_GROUP_UNSTAKING_PERIOD!);
+  const durationInBlocks: number = 48;
+  const openingActivationDelay: BN = new BN(0);
+
+  const provider = new WsProvider(nodeUrl);
+  const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
+  const sudo: KeyringPair = keyring.addFromUri(sudoUri);
+
+  setTestTimeout(apiWrapper, durationInBlocks);
+  membershipTest(apiWrapper, nKeyPairs, keyring, N, paidTerms, sudoUri);
+  membershipTest(apiWrapper, leadKeyPair, keyring, 1, paidTerms, sudoUri);
+
+  let leadOpenignId: BN;
+  tap.test(
+    'Add lead opening',
+    async () =>
+      (leadOpenignId = await addLeaderOpening(
+        apiWrapper,
+        nKeyPairs,
+        sudo,
+        applicationStake,
+        roleStake,
+        openingActivationDelay,
+        WorkingGroups.storageWorkingGroup
+      ))
+  );
+  tap.test(
+    'Apply for lead opening',
+    async () =>
+      await applyForOpening(
+        apiWrapper,
+        leadKeyPair,
+        sudo,
+        applicationStake,
+        roleStake,
+        leadOpenignId,
+        WorkingGroups.storageWorkingGroup,
+        false
+      )
+  );
+  tap.test('Begin lead application review', async () =>
+    beginLeaderApplicationReview(apiWrapper, sudo, leadOpenignId, WorkingGroups.storageWorkingGroup)
+  );
+  tap.test('Fill lead opening', async () =>
+    fillLeaderOpening(
+      apiWrapper,
+      leadKeyPair,
+      sudo,
+      leadOpenignId,
+      firstRewardInterval,
+      rewardInterval,
+      payoutAmount,
+      WorkingGroups.storageWorkingGroup
+    )
+  );
+
+  let workerOpenignId: BN;
+  tap.test(
+    'Add worker opening with 0 stake, expect failure',
+    async () =>
+      (workerOpenignId = await addWorkerOpening(
+        apiWrapper,
+        nKeyPairs,
+        leadKeyPair[0],
+        sudo,
+        new BN(0),
+        new BN(0),
+        openingActivationDelay,
+        unstakingPeriod,
+        WorkingGroups.storageWorkingGroup,
+        false
+      ))
+  );
+  tap.test(
+    'Add worker opening with 0 unstaking period, expect failure',
+    async () =>
+      (workerOpenignId = await addWorkerOpening(
+        apiWrapper,
+        nKeyPairs,
+        leadKeyPair[0],
+        sudo,
+        applicationStake,
+        roleStake,
+        openingActivationDelay,
+        new BN(0),
+        WorkingGroups.storageWorkingGroup,
+        false
+      ))
+  );
+
+  tap.test('Leaving lead role', async () =>
+    leaveRole(apiWrapper, leadKeyPair, sudo, WorkingGroups.storageWorkingGroup)
+  );
+
+  closeApi(apiWrapper);
+});

+ 11 - 9
tests/network-tests/src/nicaea/tests/workingGroup/impl/workingGroupModule.ts

@@ -18,7 +18,9 @@ export async function addWorkerOpening(
   applicationStake: BN,
   roleStake: BN,
   activationDelay: BN,
-  module: WorkingGroups
+  unstakingPeriod: BN,
+  module: WorkingGroups,
+  expectFailure: boolean
 ): Promise<BN> {
   // Worker opening construction
   let opening = new WorkingGroupOpening();
@@ -36,13 +38,13 @@ export async function addWorkerOpening(
   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.setSuccessfulApplicantApplicationStakeUnstakingPeriod(unstakingPeriod);
+  opening.setFailedApplicantApplicationStakeUnstakingPeriod(unstakingPeriod);
+  opening.setFailedApplicantRoleStakeUnstakingPeriod(unstakingPeriod);
+  opening.setTerminateCuratorApplicationStakeUnstakingPeriod(unstakingPeriod);
+  opening.setTerminateCuratorRoleStakeUnstakingPeriod(unstakingPeriod);
+  opening.setExitCuratorRoleApplicationStakeUnstakingPeriod(unstakingPeriod);
+  opening.setExitCuratorRoleStakeUnstakingPeriod(unstakingPeriod);
   opening.setText(uuid().substring(0, 8));
   opening.setOpeningType('Worker');
 
@@ -52,7 +54,7 @@ export async function addWorkerOpening(
 
   // Worker opening creation
   const addOpeningPromise: Promise<BN> = apiWrapper.expectOpeningAdded();
-  await apiWrapper.addOpening(lead, opening, module);
+  await apiWrapper.addOpening(lead, opening, module, expectFailure);
   const openingId: BN = await addOpeningPromise;
 
   return openingId;

+ 4 - 1
tests/network-tests/src/nicaea/tests/workingGroup/manageWorkerAsLeadTest.ts

@@ -39,6 +39,7 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
   const firstRewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const rewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
+  const unstakingPeriod: BN = new BN(process.env.STORAGE_WORKING_GROUP_UNSTAKING_PERIOD!);
   const durationInBlocks: number = 60;
   const openingActivationDelay: BN = new BN(0);
 
@@ -106,7 +107,9 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
         applicationStake,
         roleStake,
         openingActivationDelay,
-        WorkingGroups.storageWorkingGroup
+        unstakingPeriod,
+        WorkingGroups.storageWorkingGroup,
+        false
       ))
   );
   tap.test(

+ 4 - 1
tests/network-tests/src/nicaea/tests/workingGroup/manageWorkerAsWorkerTest.ts

@@ -39,6 +39,7 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
   const firstRewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const rewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
+  const unstakingPeriod: BN = new BN(process.env.STORAGE_WORKING_GROUP_UNSTAKING_PERIOD!);
   const durationInBlocks: number = 38;
   const openingActivationDelay: BN = new BN(0);
 
@@ -106,7 +107,9 @@ tap.mocha.describe('Manage worker as worker scenario', async () => {
         applicationStake,
         roleStake,
         openingActivationDelay,
-        WorkingGroups.storageWorkingGroup
+        unstakingPeriod,
+        WorkingGroups.storageWorkingGroup,
+        false
       ))
   );
   tap.test(

+ 4 - 1
tests/network-tests/src/nicaea/tests/workingGroup/workerApplicationHappyCaseTest.ts

@@ -37,6 +37,7 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   const firstRewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const rewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
+  const unstakingPeriod: BN = new BN(process.env.STORAGE_WORKING_GROUP_UNSTAKING_PERIOD!);
   const durationInBlocks: number = 48;
   const openingActivationDelay: BN = new BN(0);
 
@@ -104,7 +105,9 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
         applicationStake,
         roleStake,
         openingActivationDelay,
-        WorkingGroups.storageWorkingGroup
+        unstakingPeriod,
+        WorkingGroups.storageWorkingGroup,
+        false
       ))
   );
   tap.test('Apply for worker opening', async () =>

+ 4 - 1
tests/network-tests/src/nicaea/tests/workingGroup/workerApplicationRejectionCaseTest.ts

@@ -36,6 +36,7 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   const firstRewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const rewardInterval: BN = new BN(process.env.LONG_REWARD_INTERWAL!);
   const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
+  const unstakingPeriod: BN = new BN(process.env.STORAGE_WORKING_GROUP_UNSTAKING_PERIOD!);
   const durationInBlocks: number = 38;
   const openingActivationDelay: BN = new BN(100);
   const leadOpeningActivationDelay: BN = new BN(0);
@@ -105,7 +106,9 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
         applicationStake,
         roleStake,
         openingActivationDelay,
-        WorkingGroups.storageWorkingGroup
+        unstakingPeriod,
+        WorkingGroups.storageWorkingGroup,
+        false
       ))
   );
   tap.test('Apply for worker opening, expect failure', async () =>

+ 4 - 1
tests/network-tests/src/nicaea/tests/workingGroup/workerPayout.ts

@@ -38,6 +38,7 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
   const firstRewardInterval: BN = new BN(process.env.SHORT_FIRST_REWARD_INTERWAL!);
   const rewardInterval: BN = new BN(process.env.SHORT_REWARD_INTERWAL!);
   const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
+  const unstakingPeriod: BN = new BN(process.env.STORAGE_WORKING_GROUP_UNSTAKING_PERIOD!);
   const mintCapacity: BN = new BN(process.env.STORAGE_WORKING_GROUP_MINTING_CAPACITY!);
   const durationInBlocks: number = 48;
   const openingActivationDelay: BN = new BN(0);
@@ -106,7 +107,9 @@ tap.mocha.describe('Worker application happy case scenario', async () => {
         applicationStake,
         roleStake,
         openingActivationDelay,
-        WorkingGroups.storageWorkingGroup
+        unstakingPeriod,
+        WorkingGroups.storageWorkingGroup,
+        false
       ))
   );
   tap.test('Apply for worker opening', async () =>

+ 7 - 2
tests/network-tests/src/nicaea/utils/apiWrapper.ts

@@ -741,8 +741,13 @@ export class ApiWrapper {
     return accountWorkers !== undefined;
   }
 
-  public async addOpening(leader: KeyringPair, opening: WorkingGroupOpening, module: WorkingGroups): Promise<void> {
-    await this.sender.signAndSend(this.createAddOpeningTransaction(opening, module), leader, false);
+  public async addOpening(
+    leader: KeyringPair,
+    opening: WorkingGroupOpening,
+    module: WorkingGroups,
+    expectFailure: boolean
+  ): Promise<void> {
+    await this.sender.signAndSend(this.createAddOpeningTransaction(opening, module), leader, expectFailure);
   }
 
   public async sudoAddOpening(sudo: KeyringPair, opening: WorkingGroupOpening, module: WorkingGroups): Promise<void> {