Browse Source

Runtime upgrade proposal test finished, runtime upgrade asserted using events

Gleb Urvanov 4 years ago
parent
commit
dd45ab770a

+ 2 - 2
tests/network-tests/src/tests/electingCouncilTest.ts

@@ -103,8 +103,8 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
     );
 
     // Assertions
-    // m2addresses.forEach(address => assert(members.includes(address), `Account ${address} is not in the council`));
-    // m1addresses.forEach(address => assert(bakers.includes(address), `Account ${address} is not in the voters`));
+    m2addresses.forEach(address => assert(members.includes(address), `Account ${address} is not in the council`));
+    m1addresses.forEach(address => assert(bakers.includes(address), `Account ${address} is not in the voters`));
     seats.forEach(seat =>
       assert(
         Utils.getTotalStake(seat).eq(greaterStake.add(lesserStake)),

+ 16 - 6
tests/network-tests/src/tests/updateRuntimeTest.ts

@@ -8,7 +8,7 @@ import { registerJoystreamTypes } from '@joystream/types';
 import { ApiWrapper } from '../utils/apiWrapper';
 import BN = require('bn.js');
 
-describe('Council integration tests', () => {
+describe('Runtime upgrade integration tests', () => {
   initConfig();
   const keyring = new Keyring({ type: 'sr25519' });
   const nodeUrl: string = process.env.NODE_URL!;
@@ -33,7 +33,8 @@ describe('Council integration tests', () => {
   membershipTest(m2KeyPairs);
   councilTest(m1KeyPairs, m2KeyPairs);
 
-  it('Upgradeing the runtime test', async () => {
+  it('Upgrading the runtime test', async () => {
+    // Setup
     sudo = keyring.addFromUri(sudoUri);
     const runtime: Bytes = await apiWrapper.getRuntime();
     const description: string = 'runtime upgrade proposal which is used for API integration testing';
@@ -43,11 +44,14 @@ describe('Council integration tests', () => {
       description,
       runtime
     );
-    console.log('sending some funds for the test');
     const runtimeVoteFee: BN = apiWrapper.estimateVoteForProposalFee();
+
+    // Topping the balances
     await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, runtimeProposalFee.add(proposalStake));
     await apiWrapper.transferBalanceToAccounts(sudo, m2KeyPairs, runtimeVoteFee);
-    console.log('going to propose runtime');
+
+    // Proposal creation
+    const proposalPromise = apiWrapper.expectProposalCreated();
     await apiWrapper.proposeRuntime(
       m1KeyPairs[0],
       proposalStake,
@@ -55,10 +59,16 @@ describe('Council integration tests', () => {
       'runtime to test proposal functionality',
       runtime
     );
-    console.log('runtime proposed, approving...');
-    await apiWrapper.batchApproveProposal(m2KeyPairs, new BN(1));
+    const proposalNumber = await proposalPromise;
+
+    // Approving runtime update proposal
+    const runtimePromise = apiWrapper.expectRuntimeUpgraded();
+    await apiWrapper.batchApproveProposal(m2KeyPairs, proposalNumber);
+    await runtimePromise;
   }).timeout(defaultTimeout);
 
+  membershipTest(new Array<KeyringPair>());
+
   after(() => {
     apiWrapper.close();
   });

+ 26 - 5
tests/network-tests/src/utils/apiWrapper.ts

@@ -1,10 +1,10 @@
 import { ApiPromise, WsProvider } from '@polkadot/api';
-import { Option, Vec, Bytes, UInt } from '@polkadot/types';
+import { Option, Vec, Bytes } from '@polkadot/types';
 import { Codec } from '@polkadot/types/types';
 import { KeyringPair } from '@polkadot/keyring/types';
 import { UserInfo, PaidMembershipTerms } from '@joystream/types/lib/members';
 import { Seat, VoteKind } from '@joystream/types';
-import { Balance } from '@polkadot/types/interfaces';
+import { Balance, EventRecord } from '@polkadot/types/interfaces';
 import BN = require('bn.js');
 import { SubmittableExtrinsic } from '@polkadot/api/types';
 import { Sender } from './sender';
@@ -64,8 +64,6 @@ export class ApiWrapper {
   public async transferBalanceToAccounts(from: KeyringPair, to: KeyringPair[], amount: BN): Promise<void[]> {
     return Promise.all(
       to.map(async keyPair => {
-        amount = amount.addn(1);
-        console.log('sending to ' + keyPair.address + ' amount ' + amount);
         await this.transferBalance(from, keyPair.address, amount);
       })
     );
@@ -191,7 +189,6 @@ export class ApiWrapper {
 
   public getCouncil(): Promise<Seat[]> {
     return this.api.query.council.activeCouncil<Vec<Codec>>().then(seats => {
-      console.log('elected council ' + seats.toString());
       return JSON.parse(seats.toString());
     });
   }
@@ -233,4 +230,28 @@ export class ApiWrapper {
   public getBlockDuration(): BN {
     return this.api.createType('Moment', this.api.consts.babe.expectedBlockTime).toBn();
   }
+
+  public expectProposalCreated(): Promise<BN> {
+    return new Promise(async resolve => {
+      await this.api.query.system.events<Vec<EventRecord>>(events => {
+        events.forEach(record => {
+          if (record.event.method.toString() === 'ProposalCreated') {
+            resolve(new BN(record.event.data[1].toString()));
+          }
+        });
+      });
+    });
+  }
+
+  public expectRuntimeUpgraded(): 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();
+          }
+        });
+      });
+    });
+  }
 }

+ 1 - 1
tests/network-tests/src/utils/sender.ts

@@ -37,7 +37,7 @@ export class Sender {
   ): Promise<void> {
     return new Promise(async (resolve, reject) => {
       const nonce: BN = await this.getNonce(account.address);
-      console.log('sending transaction from ' + account.address + ' with nonce ' + nonce);
+      // console.log('sending transaction from ' + account.address + ' with nonce ' + nonce);
       const signedTx = tx.sign(account, { nonce });
       await signedTx
         .send(async result => {