Browse Source

validator count proposal test implemented

Gleb Urvanov 4 years ago
parent
commit
5527844328

+ 4 - 1
.gitignore

@@ -24,4 +24,7 @@ yarn*
 .vscode
 
 # Compiled WASM code
-*.wasm
+*.wasm
+
+# Chain specificaiton
+chainspec.json

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

@@ -19,4 +19,6 @@ MINTING_CAPACITY_INCREMENT = 20
 # Minting capacity for council mint for spending proposal.
 COUNCIL_MINTING_CAPACITY = 100000
 # Stake amount for Rome runtime upgrade proposal
-RUNTIME_UPGRADE_PROPOSAL_STAKE = 100000
+RUNTIME_UPGRADE_PROPOSAL_STAKE = 100000
+# Validator count increment for Validator count test.
+VALIDATOR_COUNT_INCREMENT = 2

+ 1 - 1
tests/network-tests/src/tests/constantinople/proposals/spendingProposalTest.ts

@@ -9,7 +9,7 @@ import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 import { assert } from 'chai';
 
-describe('Spending proposal network tests', () => {
+describe.skip('Spending proposal network tests', () => {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;

+ 1 - 1
tests/network-tests/src/tests/constantinople/proposals/textProposalTest.ts

@@ -8,7 +8,7 @@ import { ApiWrapper } from '../../../utils/apiWrapper';
 import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 
-describe('Text proposal network tests', () => {
+describe.skip('Text proposal network tests', () => {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;

+ 1 - 1
tests/network-tests/src/tests/constantinople/proposals/updateRuntimeTest.ts

@@ -9,7 +9,7 @@ import { ApiWrapper } from '../../../utils/apiWrapper';
 import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 
-describe('Runtime upgrade networt tests', () => {
+describe.skip('Runtime upgrade networt tests', () => {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;

+ 78 - 0
tests/network-tests/src/tests/constantinople/proposals/validatorCountProposal.ts

@@ -0,0 +1,78 @@
+import { initConfig } from '../../../utils/config';
+import { Keyring, WsProvider } from '@polkadot/api';
+import { KeyringPair } from '@polkadot/keyring/types';
+import { membershipTest } from '../membershipCreationTest';
+import { councilTest } from '../electingCouncilTest';
+import { registerJoystreamTypes } from '@joystream/types';
+import { ApiWrapper } from '../../../utils/apiWrapper';
+import { v4 as uuid } from 'uuid';
+import BN = require('bn.js');
+import { assert } from 'chai';
+
+describe('Validator count proposal network tests', () => {
+  initConfig();
+  const keyring = new Keyring({ type: 'sr25519' });
+  const nodeUrl: string = process.env.NODE_URL!;
+  const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
+  const validatorCountIncrement: BN = new BN(+process.env.VALIDATOR_COUNT_INCREMENT!);
+  const defaultTimeout: number = 180000;
+
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  let apiWrapper: ApiWrapper;
+  let sudo: KeyringPair;
+
+  before(async function () {
+    this.timeout(defaultTimeout);
+    registerJoystreamTypes();
+    const provider = new WsProvider(nodeUrl);
+    apiWrapper = await ApiWrapper.create(provider);
+  });
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+
+  it('Validator count proposal test', async () => {
+    // Setup
+    sudo = keyring.addFromUri(sudoUri);
+    const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
+    const description: string = 'Testing validator count proposal ' + uuid().substring(0, 8);
+    const runtimeVoteFee: BN = apiWrapper.estimateVoteForProposalFee();
+    await apiWrapper.transferBalanceToAccounts(sudo, m2KeyPairs, runtimeVoteFee);
+
+    // Proposal stake calculation
+    const proposalStake: BN = await apiWrapper.getRequiredProposalStake(25, 10000);
+    const proposalFee: BN = apiWrapper.estimateProposeValidatorCountFee(description, description, proposalStake);
+    await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, proposalFee.add(proposalStake));
+    const validatorCount: BN = await apiWrapper.getValidatorCount();
+
+    // Proposal creation
+    const proposalPromise = apiWrapper.expectProposalCreated();
+    await apiWrapper.proposeValidatorCount(
+      m1KeyPairs[0],
+      proposalTitle,
+      description,
+      proposalStake,
+      validatorCount.add(validatorCountIncrement)
+    );
+    const proposalNumber = await proposalPromise;
+
+    // Approving text proposal
+    const validatorProposalPromise = apiWrapper.expectProposalFinalized();
+    await apiWrapper.batchApproveProposal(m2KeyPairs, proposalNumber);
+    await validatorProposalPromise;
+    const newValidatorCount: BN = await apiWrapper.getValidatorCount();
+    assert(
+      newValidatorCount.sub(validatorCount).eq(validatorCountIncrement),
+      `Validator count has unexpeccted value ${newValidatorCount}, expected ${validatorCount.add(
+        validatorCountIncrement
+      )}`
+    );
+  }).timeout(defaultTimeout);
+
+  after(() => {
+    apiWrapper.close();
+  });
+});

+ 1 - 1
tests/network-tests/src/tests/constantinople/proposals/workingGroupMintCapacityProposalTest.ts

@@ -9,7 +9,7 @@ import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 import { assert } from 'chai';
 
-describe('Working group mint capacity proposal network tests', () => {
+describe.skip('Working group mint capacity proposal network tests', () => {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;

+ 25 - 0
tests/network-tests/src/utils/apiWrapper.ts

@@ -133,6 +133,12 @@ export class ApiWrapper {
     );
   }
 
+  public estimateProposeValidatorCountFee(title: string, description: string, stake: BN): BN {
+    return this.estimateTxFee(
+      this.api.tx.proposalsCodex.createSetValidatorCountProposal(stake, title, description, stake, stake)
+    );
+  }
+
   public estimateVoteForProposalFee(): BN {
     return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'));
   }
@@ -302,6 +308,21 @@ export class ApiWrapper {
     );
   }
 
+  public async proposeValidatorCount(
+    account: KeyringPair,
+    title: string,
+    description: string,
+    stake: BN,
+    validatorCount: BN
+  ): Promise<void> {
+    const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
+    return this.sender.signAndSend(
+      this.api.tx.proposalsCodex.createSetValidatorCountProposal(memberId, title, description, stake, validatorCount),
+      account,
+      false
+    );
+  }
+
   public approveProposal(account: KeyringPair, memberId: BN, proposal: BN): Promise<void> {
     return this.sender.signAndSend(this.api.tx.proposalsEngine.vote(memberId, proposal, 'Approve'), account, false);
   }
@@ -384,4 +405,8 @@ export class ApiWrapper {
     const mint = (mintCodec[0] as unknown) as Mint;
     return mint.getField<Balance>('capacity');
   }
+
+  public getValidatorCount(): Promise<BN> {
+    return this.api.query.staking.validatorCount<u32>();
+  }
 }