git.delta.rocks / unique-network / refs/commits / 3050b513cda0

difftreelog

test add event asserts (#982)

Max Andreev2023-09-06parent: #ec8104e.patch.diff
in: master
* add events asserts

* fix eslint

* eslint fix - unused vars

7 files changed

modifiedtests/src/benchmarks/nesting/index.tsdiffbeforeafterboth
--- a/tests/src/benchmarks/nesting/index.ts
+++ b/tests/src/benchmarks/nesting/index.ts
@@ -1,17 +1,11 @@
 import {EthUniqueHelper, usingEthPlaygrounds} from '../../eth/util';
 import {readFile} from 'fs/promises';
-import {
-  ICrossAccountId,
-} from '../../util/playgrounds/types';
 import {IKeyringPair} from '@polkadot/types/types';
-import {UniqueNFTCollection} from '../../util/playgrounds/unique';
 import {Contract} from 'web3-eth-contract';
-import {createObjectCsvWriter} from 'csv-writer';
-import {convertToTokens, createCollectionForBenchmarks, PERMISSIONS, PROPERTIES} from '../utils/common';
+import {convertToTokens} from '../utils/common';
 import {makeNames} from '../../util';
 import {ContractImports} from '../../eth/util/playgrounds/types';
 import {RMRKNestableMintable} from './ABIGEN';
-import {rm} from 'fs';
 
 const {dirname} = makeNames(import.meta.url);
 
modifiedtests/src/eth/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nesting/nest.test.ts
+++ b/tests/src/eth/nesting/nest.test.ts
@@ -162,7 +162,7 @@
       const malignant = await helper.eth.createAccountWithBalance(donor);
 
       const {collectionId: collectionIdA, contract: contractA} = await createNestingCollection(helper, owner);
-      const {collectionId: collectionIdB, contract: contractB} = await createNestingCollection(helper, owner);
+      const {contract: contractB} = await createNestingCollection(helper, owner);
 
       await contractA.methods.setCollectionNesting([true, false, [contractA.options.address, contractB.options.address]]).send({from: owner});
 
modifiedtests/src/fetchMetadata.tsdiffbeforeafterboth
before · tests/src/fetchMetadata.ts
1import { writeFile } from "fs/promises";2import { join } from "path";3import { exit } from "process";4import { fileURLToPath } from "url";56const url = process.env.RPC_URL;7if (!url) throw new Error('RPC_URL is not set');89const srcDir = fileURLToPath(new URL('.', import.meta.url));1011for (let i = 0; i < 10; i++) {12  try {13    console.log(`Trying to fetch metadata, retry ${i + 1}/${10}`)14    const response = await fetch(url, {15      method: 'POST',16      headers: {17        'Content-Type': 'application/json',18      },19      redirect: 'follow',20      body: JSON.stringify({21        jsonrpc: '2.0',22        id: '1',23        method: 'state_getMetadata',24        params: [],25      }),26    });27    const json = await response.json();28    const output = join(srcDir, 'interfaces/metadata.json');29    console.log(`Received response, saving to ${output}`);30    await writeFile(output, JSON.stringify(json));31    exit(0);32  } catch (e) {33    console.error('Failed to request metadata:');34    console.error(e);35    console.error('Waiting 1 minute');36    await new Promise(res => setTimeout(res, 60 * 1000));37  }38}39console.error('Out of retries');40exit(1);
after · tests/src/fetchMetadata.ts
1import {writeFile} from 'fs/promises';2import {join} from 'path';3import {exit} from 'process';4import {fileURLToPath} from 'url';56const url = process.env.RPC_URL;7if(!url) throw new Error('RPC_URL is not set');89const srcDir = fileURLToPath(new URL('.', import.meta.url));1011for(let i = 0; i < 10; i++) {12  try {13    console.log(`Trying to fetch metadata, retry ${i + 1}/${10}`);14    const response = await fetch(url, {15      method: 'POST',16      headers: {17        'Content-Type': 'application/json',18      },19      redirect: 'follow',20      body: JSON.stringify({21        jsonrpc: '2.0',22        id: '1',23        method: 'state_getMetadata',24        params: [],25      }),26    });27    const json = await response.json();28    const output = join(srcDir, 'interfaces/metadata.json');29    console.log(`Received response, saving to ${output}`);30    await writeFile(output, JSON.stringify(json));31    exit(0);32  } catch (e) {33    console.error('Failed to request metadata:');34    console.error(e);35    console.error('Waiting 1 minute');36    await new Promise(res => setTimeout(res, 60 * 1000));37  }38}39console.error('Out of retries');40exit(1);
modifiedtests/src/governance/technicalCommittee.test.tsdiffbeforeafterboth
--- a/tests/src/governance/technicalCommittee.test.ts
+++ b/tests/src/governance/technicalCommittee.test.ts
@@ -36,8 +36,8 @@
     });
   });
 
-  async function proposalFromAllCommittee(proposal: any) {
-    return await usingPlaygrounds(async (helper) => {
+  function proposalFromAllCommittee(proposal: any) {
+    return usingPlaygrounds(async (helper) => {
       expect((await helper.callRpc('api.query.technicalCommitteeMembership.members')).toJSON().length).to.be.equal(allTechCommitteeThreshold);
       const proposeResult = await helper.technicalCommittee.collective.propose(
         techcomms.andy,
@@ -54,7 +54,13 @@
       await helper.technicalCommittee.collective.vote(techcomms.constantine, proposalHash, proposalIndex, true);
       await helper.technicalCommittee.collective.vote(techcomms.greg, proposalHash, proposalIndex, true);
 
-      return await helper.technicalCommittee.collective.close(techcomms.andy, proposalHash, proposalIndex);
+      const closeResult = await helper.technicalCommittee.collective.close(techcomms.andy, proposalHash, proposalIndex);
+      Event.TechnicalCommittee.Closed.expect(closeResult);
+      Event.TechnicalCommittee.Approved.expect(closeResult);
+      const {result} = Event.TechnicalCommittee.Executed.expect(closeResult);
+      expect(result).to.eq('Ok');
+
+      return closeResult;
     });
   }
 
@@ -64,16 +70,16 @@
 
     await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash);
 
-    await expect(proposalFromAllCommittee(helper.democracy.fastTrackCall(preimageHash, democracyFastTrackVotingPeriod, 0)))
-      .to.be.fulfilled;
+    const fastTrackProposal = await proposalFromAllCommittee(helper.democracy.fastTrackCall(preimageHash, democracyFastTrackVotingPeriod, 0));
+    Event.Democracy.Started.expect(fastTrackProposal);
   });
 
   itSub('TechComm can cancel Democracy proposals', async ({helper}) => {
     const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
     const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
 
-    await expect(proposalFromAllCommittee(helper.democracy.cancelProposalCall(proposalIndex)))
-      .to.be.fulfilled;
+    const cancelProposal = await proposalFromAllCommittee(helper.democracy.cancelProposalCall(proposalIndex));
+    Event.Democracy.ProposalCanceled.expect(cancelProposal);
   });
 
   itSub('TechComm can cancel ongoing Democracy referendums', async ({helper}) => {
@@ -81,19 +87,19 @@
     const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, Event.Democracy.Started);
     const referendumIndex = startedEvent.referendumIndex;
 
-    await expect(proposalFromAllCommittee(helper.democracy.emergencyCancelCall(referendumIndex)))
-      .to.be.fulfilled;
+    const emergencyCancelProposal = await proposalFromAllCommittee(helper.democracy.emergencyCancelCall(referendumIndex));
+    Event.Democracy.Cancelled.expect(emergencyCancelProposal);
   });
-
 
   itSub('TechComm member can veto Democracy proposals', async ({helper}) => {
     const preimageHash = await helper.preimage.notePreimageFromCall(sudoer, dummyProposalCall(helper), true);
     await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash);
 
-    await expect(helper.technicalCommittee.collective.execute(
+    const vetoExternalCall = await helper.technicalCommittee.collective.execute(
       techcomms.andy,
       helper.democracy.vetoExternalCall(preimageHash),
-    )).to.be.fulfilled;
+    );
+    Event.Democracy.Vetoed.expect(vetoExternalCall);
   });
 
   itSub('TechComm can cancel Fellowship referendums', async ({helper}) => {
@@ -108,7 +114,8 @@
       defaultEnactmentMoment,
     );
     const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
-    await expect(proposalFromAllCommittee(helper.fellowship.referenda.cancelCall(referendumIndex))).to.be.fulfilled;
+    const cancelProposal = await proposalFromAllCommittee(helper.fellowship.referenda.cancelCall(referendumIndex));
+    Event.FellowshipReferenda.Cancelled.expect(cancelProposal);
   });
 
   itSub.skip('TechComm member can add a Fellowship member', async ({helper}) => {
modifiedtests/src/maintenance.seqtest.tsdiffbeforeafterboth
--- a/tests/src/maintenance.seqtest.ts
+++ b/tests/src/maintenance.seqtest.ts
@@ -18,7 +18,6 @@
 import {ApiPromise} from '@polkadot/api';
 import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
 import {itEth} from './eth/util';
-import {UniqueHelper} from './util/playgrounds/unique';
 import {main as correctState} from './migrations/correctStateAfterMaintenance';
 
 async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -174,6 +174,20 @@
     static Passed = this.Method('Passed', data => ({
       referendumIndex: eventJsonData<number>(data, 0),
     }));
+
+    static ProposalCanceled = this.Method('ProposalCanceled', data => ({
+      propIndex: eventJsonData<number>(data, 0),
+    }));
+
+    static Cancelled = this.Method('Cancelled', data => ({
+      propIndex: eventJsonData<number>(data, 0),
+    }));
+
+    static Vetoed = this.Method('Vetoed', data => ({
+      who: eventHumanData(data, 0),
+      proposalHash: eventHumanData(data, 1),
+      until: eventJsonData<number>(data, 1),
+    }));
   };
 
   static Council = class extends EventSection('council') {
@@ -188,6 +202,9 @@
       yes: eventJsonData<number>(data, 1),
       no: eventJsonData<number>(data, 2),
     }));
+    static Executed = this.Method('Executed', data => ({
+      proposalHash: eventHumanData(data, 0),
+    }));
   };
 
   static TechnicalCommittee = class extends EventSection('technicalCommittee') {
@@ -202,6 +219,13 @@
       yes: eventJsonData<number>(data, 1),
       no: eventJsonData<number>(data, 2),
     }));
+    static Approved = this.Method('Approved', data => ({
+      proposalHash: eventHumanData(data, 0),
+    }));
+    static Executed = this.Method('Executed', data => ({
+      proposalHash: eventHumanData(data, 0),
+      result: eventHumanData(data, 1),
+    }));
   };
 
   static FellowshipReferenda = class extends EventSection('fellowshipReferenda') {
@@ -210,6 +234,11 @@
       trackId: eventJsonData<number>(data, 1),
       proposal: eventJsonData(data, 2),
     }));
+
+    static Cancelled = this.Method('Cancelled', data => ({
+      index: eventJsonData<number>(data, 0),
+      tally: eventJsonData(data, 1),
+    }));
   };
 
   static UniqueScheduler = schedulerSection('uniqueScheduler');
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -44,15 +44,11 @@
   MoonbeamAssetInfo,
   DemocracyStandardAccountVote,
   IEthCrossAccountId,
-  CollectionFlag,
   IPhasicEvent,
-  DemocracySplitAccount,
 } from './types';
 import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';
 import type {Vec} from '@polkadot/types-codec';
-import {FrameSupportPreimagesBounded, FrameSupportScheduleDispatchTime, FrameSystemEventRecord, PalletBalancesIdAmount, PalletDemocracyConviction, PalletDemocracyVoteAccountVote} from '@polkadot/types/lookup';
-import {arrayUnzip} from '@polkadot/util';
-import {Event} from './unique.dev';
+import {FrameSystemEventRecord, PalletDemocracyConviction} from '@polkadot/types/lookup';
 
 export class CrossAccountId {
   Substrate!: TSubstrateAccount;