Browse Source

composed scenarios as sequence of functions

Gleb Urvanov 4 years ago
parent
commit
7138f7921d

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

@@ -4,7 +4,8 @@
   "license": "GPL-3.0-only",
   "scripts": {
     "build": "tsc --build tsconfig.json",
-    "test": "mocha -r ts-node/register src/tests/constantinople/proposals/*",
+    "test": "mocha -r ts-node/register src/tests/constantinople/proposals/* --reporter tap",
+    "test-mocha": "mocha -r ts-node/register src/tests/constantinople/proposals/spendingProposalTest.ts",
     "test-migration": "mocha -r ts-node/register src/tests/rome/* && mocha -r ts-node/register src/tests/constantinople/*",
     "lint": "tslint --project tsconfig.json",
     "prettier": "prettier --write ./src"

+ 1 - 1
tests/network-tests/src/tests/constantinople/electingCouncilTest.ts

@@ -28,7 +28,7 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  it('Electing a council test', async () => {
+  it('\n\tElecting a council test', async () => {
     // Setup goes here because M keypairs are generated after before() function
     sudo = keyring.addFromUri(sudoUri);
     let now = await apiWrapper.getBestBlock();

+ 3 - 3
tests/network-tests/src/tests/constantinople/membershipCreationTest.ts

@@ -42,7 +42,7 @@ export function membershipTest(nKeyPairs: KeyringPair[]) {
     await apiWrapper.transferBalance(sudo, aKeyPair.address, membershipTransactionFee);
   });
 
-  it('Buy membeship is accepted with sufficient funds', async () => {
+  it('\n\tBuy membeship is accepted with sufficient funds', async () => {
     await Promise.all(
       nKeyPairs.map(async (keyPair, index) => {
         await apiWrapper.buyMembership(keyPair, paidTerms, `new_member_${index}${keyPair.address.substring(0, 8)}`);
@@ -55,7 +55,7 @@ export function membershipTest(nKeyPairs: KeyringPair[]) {
     );
   }).timeout(defaultTimeout);
 
-  it('Account A can not buy the membership with insufficient funds', async () => {
+  it('\n\tAccount A can not buy the membership with insufficient funds', async () => {
     await apiWrapper
       .getBalance(aKeyPair.address)
       .then(balance =>
@@ -70,7 +70,7 @@ export function membershipTest(nKeyPairs: KeyringPair[]) {
       .then(membership => assert(membership.length === 0, 'Account A is a member'));
   }).timeout(defaultTimeout);
 
-  it('Account A was able to buy the membership with sufficient funds', async () => {
+  it('\n\tAccount A was able to buy the membership with sufficient funds', async () => {
     await apiWrapper.transferBalance(sudo, aKeyPair.address, membershipFee.add(membershipTransactionFee));
     apiWrapper
       .getBalance(aKeyPair.address)

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/electionParametersProposalTest.ts

@@ -9,16 +9,13 @@ import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 import { assert } from 'chai';
 
-describe('Election parameters proposal network tests', () => {
+export function electionParametersProposalTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const defaultTimeout: number = 180000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -29,11 +26,7 @@ describe('Election parameters proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Election parameters proposal test', async () => {
+  it('\n\tElection parameters proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -135,4 +128,14 @@ describe('Election parameters proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Election parameters proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  electionParametersProposalTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/evictStoraveProviderTest.ts

@@ -10,16 +10,13 @@ import BN = require('bn.js');
 import { assert } from 'chai';
 import { Utils } from '../../../utils/utils';
 
-describe('Evict storage provider proposal network tests', () => {
+export function evictStorageProviderTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const defaultTimeout: number = 180000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -30,11 +27,7 @@ describe('Evict storage provider proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Evict storage provider proposal test', async () => {
+  it('\n\tEvict storage provider proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -81,4 +74,14 @@ describe('Evict storage provider proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Evict storage provider proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  evictStorageProviderTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/setLeadProposalTest.ts

@@ -9,16 +9,13 @@ import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 import { assert } from 'chai';
 
-describe('Lead proposal network tests', () => {
+export function setLeadProposalTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const defaultTimeout: number = 180000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -29,11 +26,7 @@ describe('Lead proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Lead proposal test', async () => {
+  it('\n\tLead proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -65,4 +58,14 @@ describe('Lead proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Lead proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  setLeadProposalTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
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', () => {
+export function spendingProposalTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
@@ -18,9 +18,6 @@ describe('Spending proposal network tests', () => {
   const mintCapacity: BN = new BN(+process.env.COUNCIL_MINTING_CAPACITY!);
   const defaultTimeout: number = 120000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -31,11 +28,7 @@ describe('Spending proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Spending proposal test', async () => {
+  it('\n\tSpending proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const description: string = 'spending proposal which is used for API network testing with some mock data';
@@ -83,4 +76,14 @@ describe('Spending proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Spending proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  spendingProposalTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/storageRoleParametersProposalTest.ts

@@ -10,16 +10,13 @@ import BN = require('bn.js');
 import { assert } from 'chai';
 import { RoleParameters } from '@joystream/types/lib/roles';
 
-describe('Storage role parameters proposal network tests', () => {
+export function storageRoleParametersProposalTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const defaultTimeout: number = 180000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -30,11 +27,7 @@ describe('Storage role parameters proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Storage role parameters proposal test', async () => {
+  it('\n\tStorage role parameters proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -146,4 +139,14 @@ describe('Storage role parameters proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Storage role parameters proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  storageRoleParametersProposalTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/textProposalTest.ts

@@ -8,16 +8,13 @@ import { ApiWrapper } from '../../../utils/apiWrapper';
 import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 
-describe('Text proposal network tests', () => {
+export function textProposalTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const defaultTimeout: number = 180000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -28,11 +25,7 @@ describe('Text proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Text proposal test', async () => {
+  it('\n\tText proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -65,4 +58,14 @@ describe('Text proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Text proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  textProposalTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/updateRuntimeTest.ts

@@ -9,16 +9,13 @@ import { ApiWrapper } from '../../../utils/apiWrapper';
 import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 
-describe('Runtime upgrade networt tests', () => {
+export function updateRuntimeTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
   const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
   const defaultTimeout: number = 120000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -29,11 +26,7 @@ describe('Runtime upgrade networt tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Upgrading the runtime test', async () => {
+  it('\n\tUpgrading the runtime test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const runtime: Bytes = await apiWrapper.getRuntime();
@@ -73,4 +66,14 @@ describe('Runtime upgrade networt tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Runtime upgrade networt tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  updateRuntimeTest(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 9
tests/network-tests/src/tests/constantinople/proposals/validatorCountProposal.ts

@@ -9,7 +9,7 @@ import { v4 as uuid } from 'uuid';
 import BN = require('bn.js');
 import { assert } from 'chai';
 
-describe('Validator count proposal network tests', () => {
+export function validatorCountProposal(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
@@ -17,9 +17,6 @@ describe('Validator count proposal network tests', () => {
   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;
 
@@ -30,11 +27,7 @@ describe('Validator count proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  it('Validator count proposal test', async () => {
+  it('\n\tValidator count proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
@@ -75,4 +68,14 @@ describe('Validator count proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Validator count proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  validatorCountProposal(m1KeyPairs, m2KeyPairs);
 });

+ 12 - 10
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', () => {
+export function workingGroupMintCapacityProposalTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
@@ -17,9 +17,6 @@ describe('Working group mint capacity proposal network tests', () => {
   const mintingCapacityIncrement: BN = new BN(+process.env.MINTING_CAPACITY_INCREMENT!);
   const defaultTimeout: number = 120000;
 
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-
   let apiWrapper: ApiWrapper;
   let sudo: KeyringPair;
 
@@ -30,12 +27,7 @@ describe('Working group mint capacity proposal network tests', () => {
     apiWrapper = await ApiWrapper.create(provider);
   });
 
-  membershipTest(m1KeyPairs);
-  membershipTest(m2KeyPairs);
-  councilTest(m1KeyPairs, m2KeyPairs);
-
-  // TODO implement the test
-  it('Mint capacity proposal test', async () => {
+  it('\n\tMint capacity proposal test', async () => {
     // Setup
     sudo = keyring.addFromUri(sudoUri);
     const description: string = 'spending proposal which is used for API network testing';
@@ -80,4 +72,14 @@ describe('Working group mint capacity proposal network tests', () => {
   after(() => {
     apiWrapper.close();
   });
+}
+
+describe('Working group mint capacity proposal network tests', () => {
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  membershipTest(m1KeyPairs);
+  membershipTest(m2KeyPairs);
+  councilTest(m1KeyPairs, m2KeyPairs);
+  workingGroupMintCapacityProposalTest(m1KeyPairs, m2KeyPairs);
 });