Browse Source

review feedback applied

Gleb Urvanov 4 years ago
parent
commit
b5b36a2cd2

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

@@ -10,7 +10,7 @@
     "prettier": "prettier --write ./src"
   },
   "dependencies": {
-    "@joystream/types": "../joystream-apps/packages/joy-types",
+    "@joystream/types": "",
     "@rome/types@npm:@joystream/types": "^0.7.0",
     "@polkadot/api": "^0.96.1",
     "@polkadot/keyring": "^1.7.0-beta.5",

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

@@ -1,13 +1,13 @@
 import { membershipTest } from './membershipCreationTest';
 import { KeyringPair } from '@polkadot/keyring/types';
-import { ApiWrapper } from '../../utils/apiWrapper';
+import { ApiWrapper } from './utils/apiWrapper';
 import { WsProvider, Keyring } from '@polkadot/api';
-import { initConfig } from '../../utils/config';
+import { initConfig } from './utils/config';
 import BN = require('bn.js');
 import { registerJoystreamTypes, Seat } from '@joystream/types';
 import { assert } from 'chai';
 import { v4 as uuid } from 'uuid';
-import { Utils } from '../../utils/utils';
+import { Utils } from './utils/utils';
 
 export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]) {
   initConfig();

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

@@ -4,8 +4,8 @@ import { Keyring } from '@polkadot/keyring';
 import { assert } from 'chai';
 import { KeyringPair } from '@polkadot/keyring/types';
 import BN = require('bn.js');
-import { ApiWrapper } from '../../utils/apiWrapper';
-import { initConfig } from '../../utils/config';
+import { ApiWrapper } from './utils/apiWrapper';
+import { initConfig } from './utils/config';
 import { v4 as uuid } from 'uuid';
 
 export function membershipTest(nKeyPairs: KeyringPair[]) {

+ 0 - 0
tests/network-tests/src/utils/apiWrapper.ts → tests/network-tests/src/tests/constantinople/utils/apiWrapper.ts


+ 0 - 0
tests/network-tests/src/utils/config.ts → tests/network-tests/src/tests/constantinople/utils/config.ts


+ 0 - 0
tests/network-tests/src/utils/sender.ts → tests/network-tests/src/tests/constantinople/utils/sender.ts


+ 0 - 0
tests/network-tests/src/utils/utils.ts → tests/network-tests/src/tests/constantinople/utils/utils.ts


+ 5 - 6
tests/network-tests/src/tests/rome/romeRuntimeUpgradeTest.ts

@@ -1,6 +1,5 @@
 import { initConfig } from './utils/config';
 import { Keyring, WsProvider } from '@polkadot/api';
-import { Bytes } from '@polkadot/types';
 import { KeyringPair } from '@polkadot/keyring/types';
 import { membershipTest } from './membershipCreationTest';
 import { councilTest } from './electingCouncilTest';
@@ -41,13 +40,13 @@ describe('Runtime upgrade integration tests', () => {
     sudo = keyring.addFromUri(sudoUri);
     const runtime: string = Utils.readRuntimeFromFile(runtimePath);
     const description: string = 'runtime upgrade proposal which is used for API integration testing';
-    const runtimeProposalFee: BN = apiWrapper.estimateRomeProposeRuntimeUpgradeFee(
+    const runtimeProposalFee: BN = apiWrapper.estimateProposeRuntimeUpgradeFee(
       proposalStake,
       description,
       description,
       runtime
     );
-    const runtimeVoteFee: BN = apiWrapper.estimateVoteForRomeRuntimeProposalFee();
+    const runtimeVoteFee: BN = apiWrapper.estimateVoteForRuntimeProposalFee();
 
     // Topping the balances
     await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, runtimeProposalFee.add(proposalStake));
@@ -55,7 +54,7 @@ describe('Runtime upgrade integration tests', () => {
 
     // Proposal creation
     const proposalPromise = apiWrapper.expectProposalCreated();
-    await apiWrapper.proposeRuntimeRome(
+    await apiWrapper.proposeRuntime(
       m1KeyPairs[0],
       proposalStake,
       'testing runtime',
@@ -65,8 +64,8 @@ describe('Runtime upgrade integration tests', () => {
     const proposalNumber = await proposalPromise;
 
     // Approving runtime update proposal
-    const runtimePromise = apiWrapper.expectRomeRuntimeUpgraded();
-    await apiWrapper.batchApproveRomeProposal(m2KeyPairs, proposalNumber);
+    const runtimePromise = apiWrapper.expectRuntimeUpgraded();
+    await apiWrapper.batchApproveProposal(m2KeyPairs, proposalNumber);
     await runtimePromise;
   }).timeout(defaultTimeout);
 

+ 7 - 67
tests/network-tests/src/tests/rome/utils/apiWrapper.ts

@@ -99,18 +99,7 @@ export class ApiWrapper {
     return this.estimateTxFee(this.api.tx.councilElection.reveal(hashedVote, nominee, salt));
   }
 
-  public estimateProposeRuntimeUpgradeFee(stake: BN, name: string, description: string, runtime: Bytes | string): BN {
-    return this.estimateTxFee(
-      this.api.tx.proposalsCodex.createRuntimeUpgradeProposal(stake, name, description, stake, runtime)
-    );
-  }
-
-  public estimateRomeProposeRuntimeUpgradeFee(
-    stake: BN,
-    name: string,
-    description: string,
-    runtime: Bytes | string
-  ): BN {
+  public estimateProposeRuntimeUpgradeFee(stake: BN, name: string, description: string, runtime: string): BN {
     return this.estimateTxFee(this.api.tx.proposals.createProposal(stake, name, description, runtime));
   }
 
@@ -142,11 +131,7 @@ export class ApiWrapper {
     );
   }
 
-  public estimateVoteForProposalFee(): BN {
-    return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'));
-  }
-
-  public estimateVoteForRomeRuntimeProposalFee(): BN {
+  public estimateVoteForRuntimeProposalFee(): BN {
     return this.estimateTxFee(this.api.tx.proposals.voteOnProposal(0, 'Approve'));
   }
 
@@ -244,27 +229,12 @@ export class ApiWrapper {
     return this.api.query.substrate.code<Bytes>();
   }
 
-  public async proposeRuntime(
+  public proposeRuntime(
     account: KeyringPair,
     stake: BN,
     name: string,
     description: string,
-    runtime: Bytes | string
-  ): Promise<void> {
-    const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
-    return this.sender.signAndSend(
-      this.api.tx.proposalsCodex.createRuntimeUpgradeProposal(memberId, name, description, stake, runtime),
-      account,
-      false
-    );
-  }
-
-  public proposeRuntimeRome(
-    account: KeyringPair,
-    stake: BN,
-    name: string,
-    description: string,
-    runtime: Bytes | string
+    runtime: string
   ): Promise<void> {
     return this.sender.signAndSend(
       this.api.tx.proposals.createProposal(stake, name, description, runtime),
@@ -325,20 +295,7 @@ export class ApiWrapper {
     );
   }
 
-  public approveProposal(account: KeyringPair, memberId: BN, proposal: BN): Promise<void> {
-    return this.sender.signAndSend(this.api.tx.proposalsEngine.vote(memberId, proposal, 'Approve'), account, false);
-  }
-
-  public batchApproveProposal(council: KeyringPair[], proposal: BN): Promise<void[]> {
-    return Promise.all(
-      council.map(async keyPair => {
-        const memberId: BN = (await this.getMemberIds(keyPair.address))[0].toBn();
-        await this.approveProposal(keyPair, memberId, proposal);
-      })
-    );
-  }
-
-  public approveRomeProposal(account: KeyringPair, proposal: BN): Promise<void> {
+  public approveProposal(account: KeyringPair, proposal: BN): Promise<void> {
     return this.sender.signAndSend(
       this.api.tx.proposals.voteOnProposal(proposal, new VoteKind('Approve')),
       account,
@@ -346,10 +303,10 @@ export class ApiWrapper {
     );
   }
 
-  public batchApproveRomeProposal(council: KeyringPair[], proposal: BN): Promise<void[]> {
+  public batchApproveProposal(council: KeyringPair[], proposal: BN): Promise<void[]> {
     return Promise.all(
       council.map(async keyPair => {
-        await this.approveRomeProposal(keyPair, proposal);
+        await this.approveProposal(keyPair, proposal);
       })
     );
   }
@@ -382,18 +339,6 @@ export class ApiWrapper {
     });
   }
 
-  public expectRomeRuntimeUpgraded(): Promise<void> {
-    return new Promise(async resolve => {
-      await this.api.query.system.events<Vec<EventRecord>>(events => {
-        events.forEach(record => {
-          if (record.event.method.toString() === 'RuntimeUpdated') {
-            resolve();
-          }
-        });
-      });
-    });
-  }
-
   public expectProposalFinalized(): Promise<void> {
     return new Promise(async resolve => {
       await this.api.query.system.events<Vec<EventRecord>>(events => {
@@ -413,11 +358,6 @@ export class ApiWrapper {
     return this.api.query.balances.totalIssuance<Balance>();
   }
 
-  public async getProposal(id: BN) {
-    const proposal = await this.api.query.proposalsEngine.proposals(id);
-    return;
-  }
-
   public async getRequiredProposalStake(numerator: number, denominator: number): Promise<BN> {
     const issuance: number = await (await this.getTotalIssuance()).toNumber();
     const stake = (issuance * numerator) / denominator;

+ 2 - 3
tests/network-tests/src/tests/rome/utils/utils.ts

@@ -1,6 +1,5 @@
 import { IExtrinsic } from '@polkadot/types/types';
-import { Bytes } from '@polkadot/types';
-import { compactToU8a, stringToU8a } from '@polkadot/util';
+import { compactToU8a, stringToU8a, u8aToHex } from '@polkadot/util';
 import { blake2AsHex } from '@polkadot/util-crypto';
 import BN = require('bn.js');
 import fs = require('fs');
@@ -46,6 +45,6 @@ export class Utils {
   }
 
   public static readRuntimeFromFile(path: string): string {
-    return '0x' + fs.readFileSync(path).toString('hex');
+    return u8aToHex(fs.readFileSync(path));
   }
 }