Sfoglia il codice sorgente

implemented add lead opening test

Gleb Urvanov 4 anni fa
parent
commit
4cf29f2d27

+ 1 - 1
scripts/create-test-chainspec.sh

@@ -7,6 +7,6 @@ perl -i -pe's/"setElectionParametersProposalGracePeriod":.*/"setElectionParamete
 perl -i -pe's/"textProposalGracePeriod":.*/"textProposalGracePeriod": 0,/' .tmp/chainspec.json
 perl -i -pe's/"setContentWorkingGroupMintCapacityProposalGracePeriod":.*/"setContentWorkingGroupMintCapacityProposalGracePeriod": 0,/' .tmp/chainspec.json
 perl -i -pe's/"setLeadProposalGracePeriod":.*/"setLeadProposalGracePeriod": 0,/' .tmp/chainspec.json
-perl -i -pe's/"spendingProposalGracePeriod":.*/"spendingProposalGracePeriod": 0/' .tmp/chainspec.json
+perl -i -pe's/"spendingProposalGracePeriod":.*/"spendingProposalGracePeriod": 0,/' .tmp/chainspec.json
 perl -i -pe's/"evictStorageProviderProposalGracePeriod":.*/"evictStorageProviderProposalGracePeriod": 0,/' .tmp/chainspec.json
 perl -i -pe's/"setStorageRoleParametersProposalGracePeriod":.*/"setStorageRoleParametersProposalGracePeriod": 0/' .tmp/chainspec.json

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

+ 51 - 0
tests/network-tests/src/nicaea/tests/proposals/addWorkingGroupLeaderTest.ts

@@ -0,0 +1,51 @@
+import { KeyringPair } from '@polkadot/keyring/types';
+import { membershipTest } from '../impl/membershipCreation';
+import { councilTest } from '../impl/electingCouncil';
+import { initConfig } from '../../utils/config';
+import { Keyring, WsProvider } from '@polkadot/api';
+import BN from 'bn.js';
+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';
+
+tap.mocha.describe('Set lead proposal scenario', async () => {
+  initConfig();
+  registerJoystreamTypes();
+
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  const keyring = new Keyring({ type: 'sr25519' });
+  const N: number = +process.env.MEMBERSHIP_CREATION_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 K: number = +process.env.COUNCIL_ELECTION_K!;
+  const greaterStake: BN = new BN(+process.env.COUNCIL_STAKE_GREATER_AMOUNT!);
+  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 provider = new WsProvider(nodeUrl);
+  const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
+  const sudo: KeyringPair = keyring.addFromUri(sudoUri);
+
+  setTestTimeout(apiWrapper, durationInBlocks);
+  membershipTest(apiWrapper, m1KeyPairs, keyring, N, paidTerms, sudoUri);
+  membershipTest(apiWrapper, m2KeyPairs, keyring, N, paidTerms, sudoUri);
+  councilTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, K, sudoUri, greaterStake, lesserStake);
+
+  let proposalId: BN;
+  tap.test(
+    'Create leader opening',
+    async () =>
+      (proposalId = await createWorkingGroupLeaderOpening(apiWrapper, m1KeyPairs, sudo, applicationStake, roleStake))
+  );
+  tap.test('Approve proposal', async () => voteForProposal(apiWrapper, m2KeyPairs, sudo, proposalId));
+
+  closeApi(apiWrapper);
+});

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

@@ -0,0 +1,77 @@
+import { KeyringPair } from '@polkadot/keyring/types';
+import { ApiWrapper } from '../../../utils/apiWrapper';
+import { v4 as uuid } from 'uuid';
+import BN from 'bn.js';
+import { assert } from 'chai';
+
+export async function createWorkingGroupLeaderOpening(
+  apiWrapper: ApiWrapper,
+  m1KeyPairs: KeyringPair[],
+  sudo: KeyringPair,
+  applicationStake: BN,
+  roleStake: BN
+): Promise<BN> {
+  // Setup
+  const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
+  const description: string = 'Testing working group lead opening proposal ' + uuid().substring(0, 8);
+
+  // Proposal stake calculation
+  const proposalStake: BN = new BN(50000);
+  const proposalFee: BN = apiWrapper.estimateProposeCreateWorkingGroupLeaderOpening();
+  await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, proposalFee.add(proposalStake));
+
+  // Proposal creation
+  const proposalPromise = apiWrapper.expectProposalCreated();
+  await apiWrapper.proposeCreateWorkingGroupLeaderOpening(
+    m1KeyPairs[0],
+    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)
+  );
+  const proposalNumber: BN = await proposalPromise;
+  return proposalNumber;
+}
+
+export async function voteForProposal(
+  apiWrapper: ApiWrapper,
+  m2KeyPairs: KeyringPair[],
+  sudo: KeyringPair,
+  proposalNumber: BN
+) {
+  const proposalVoteFee: BN = apiWrapper.estimateVoteForProposalFee();
+  await apiWrapper.transferBalanceToAccounts(sudo, m2KeyPairs, proposalVoteFee);
+
+  // Approving the proposal
+  const proposalExecutionPromise = apiWrapper.expectProposalFinalized();
+  await apiWrapper.batchApproveProposal(m2KeyPairs, proposalNumber);
+  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}`
+  //   );
+}

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

@@ -260,6 +260,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 estimateAcceptApplicationsFee(): BN {
     return this.estimateTxFee(this.api.tx.storageWorkingGroup.acceptApplications(0));
   }
@@ -900,6 +945,79 @@ export class ApiWrapper {
     );
   }
 
+  public async proposeCreateWorkingGroupLeaderOpening(
+    account: KeyringPair,
+    title: string,
+    description: string,
+    proposalStake: BN,
+    activateAtBlock: BN,
+    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 memberId: BN = (await this.getMemberIds(account.address))[0];
+    const commitment = {
+      application_rationing_policy: { max_active_applicants: maxActiveApplicants },
+      max_review_period_length: maxReviewPeriodLength,
+      application_staking_policy: {
+        amount: applicationStakingPolicyAmount,
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: applicationCrowdedOutUnstakingPeriodLength,
+        review_period_expired_unstaking_period_length: applicationExpiredUnstakingPeriodLength,
+      },
+      role_staking_policy: {
+        amount: roleStakingPolicyAmount,
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: roleCrowdedOutUnstakingPeriodLength,
+        review_period_expired_unstaking_period_length: roleExpiredUnstakingPeriodLength,
+      },
+      role_slashing_terms: {
+        Slashable: {
+          max_count: slashableMaxCount,
+          max_percent_pts_per_time: slashableMaxPercentPtsPerTime,
+        },
+      },
+      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.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
+        memberId,
+        title,
+        description,
+        proposalStake,
+        {
+          activate_at: 'CurrentBlock',
+          commitment: commitment,
+          human_readable_text: text,
+          working_group: 'Storage',
+        }
+      ),
+      account,
+      false
+    );
+  }
+
   public async acceptApplications(account: KeyringPair, openingId: BN): Promise<void> {
     return this.sender.signAndSend(this.api.tx.storageWorkingGroup.acceptApplications(openingId), account, false);
   }

+ 1 - 0
yarn.lock

@@ -1746,6 +1746,7 @@
     "@types/vfile" "^4.0.0"
     ajv "^6.11.0"
     lodash "^4.17.15"
+    moment "^2.24.0"
 
 "@ledgerhq/devices@^4.78.0":
   version "4.78.0"