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
1import {EthUniqueHelper, usingEthPlaygrounds} from '../../eth/util';1import {EthUniqueHelper, usingEthPlaygrounds} from '../../eth/util';
2import {readFile} from 'fs/promises';2import {readFile} from 'fs/promises';
3import {
4 ICrossAccountId,
5} from '../../util/playgrounds/types';
6import {IKeyringPair} from '@polkadot/types/types';3import {IKeyringPair} from '@polkadot/types/types';
7import {UniqueNFTCollection} from '../../util/playgrounds/unique';
8import {Contract} from 'web3-eth-contract';4import {Contract} from 'web3-eth-contract';
9import {createObjectCsvWriter} from 'csv-writer';
10import {convertToTokens, createCollectionForBenchmarks, PERMISSIONS, PROPERTIES} from '../utils/common';5import {convertToTokens} from '../utils/common';
11import {makeNames} from '../../util';6import {makeNames} from '../../util';
12import {ContractImports} from '../../eth/util/playgrounds/types';7import {ContractImports} from '../../eth/util/playgrounds/types';
13import {RMRKNestableMintable} from './ABIGEN';8import {RMRKNestableMintable} from './ABIGEN';
14import {rm} from 'fs';
159
16const {dirname} = makeNames(import.meta.url);10const {dirname} = makeNames(import.meta.url);
1711
modifiedtests/src/eth/nesting/nest.test.tsdiffbeforeafterboth
162 const malignant = await helper.eth.createAccountWithBalance(donor);162 const malignant = await helper.eth.createAccountWithBalance(donor);
163163
164 const {collectionId: collectionIdA, contract: contractA} = await createNestingCollection(helper, owner);164 const {collectionId: collectionIdA, contract: contractA} = await createNestingCollection(helper, owner);
165 const {collectionId: collectionIdB, contract: contractB} = await createNestingCollection(helper, owner);165 const {contract: contractB} = await createNestingCollection(helper, owner);
166166
167 await contractA.methods.setCollectionNesting([true, false, [contractA.options.address, contractB.options.address]]).send({from: owner});167 await contractA.methods.setCollectionNesting([true, false, [contractA.options.address, contractB.options.address]]).send({from: owner});
168168
modifiedtests/src/fetchMetadata.tsdiffbeforeafterboth
1import { writeFile } from "fs/promises";1import {writeFile} from 'fs/promises';
2import { join } from "path";2import {join} from 'path';
3import { exit } from "process";3import {exit} from 'process';
4import { fileURLToPath } from "url";4import {fileURLToPath} from 'url';
55
6const url = process.env.RPC_URL;6const url = process.env.RPC_URL;
7if (!url) throw new Error('RPC_URL is not set');7if(!url) throw new Error('RPC_URL is not set');
1010
11for (let i = 0; i < 10; i++) {11for(let i = 0; i < 10; i++) {
12 try {12 try {
13 console.log(`Trying to fetch metadata, retry ${i + 1}/${10}`)13 console.log(`Trying to fetch metadata, retry ${i + 1}/${10}`);
14 const response = await fetch(url, {14 const response = await fetch(url, {
15 method: 'POST',15 method: 'POST',
16 headers: {16 headers: {
modifiedtests/src/governance/technicalCommittee.test.tsdiffbeforeafterboth
36 });36 });
37 });37 });
3838
39 async function proposalFromAllCommittee(proposal: any) {39 function proposalFromAllCommittee(proposal: any) {
40 return await usingPlaygrounds(async (helper) => {40 return usingPlaygrounds(async (helper) => {
41 expect((await helper.callRpc('api.query.technicalCommitteeMembership.members')).toJSON().length).to.be.equal(allTechCommitteeThreshold);41 expect((await helper.callRpc('api.query.technicalCommitteeMembership.members')).toJSON().length).to.be.equal(allTechCommitteeThreshold);
42 const proposeResult = await helper.technicalCommittee.collective.propose(42 const proposeResult = await helper.technicalCommittee.collective.propose(
43 techcomms.andy,43 techcomms.andy,
54 await helper.technicalCommittee.collective.vote(techcomms.constantine, proposalHash, proposalIndex, true);54 await helper.technicalCommittee.collective.vote(techcomms.constantine, proposalHash, proposalIndex, true);
55 await helper.technicalCommittee.collective.vote(techcomms.greg, proposalHash, proposalIndex, true);55 await helper.technicalCommittee.collective.vote(techcomms.greg, proposalHash, proposalIndex, true);
5656
57 return await helper.technicalCommittee.collective.close(techcomms.andy, proposalHash, proposalIndex);57 const closeResult = await helper.technicalCommittee.collective.close(techcomms.andy, proposalHash, proposalIndex);
58 Event.TechnicalCommittee.Closed.expect(closeResult);
59 Event.TechnicalCommittee.Approved.expect(closeResult);
60 const {result} = Event.TechnicalCommittee.Executed.expect(closeResult);
61 expect(result).to.eq('Ok');
62
63 return closeResult;
58 });64 });
59 }65 }
6066
6470
65 await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash);71 await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash);
6672
67 await expect(proposalFromAllCommittee(helper.democracy.fastTrackCall(preimageHash, democracyFastTrackVotingPeriod, 0)))73 const fastTrackProposal = await proposalFromAllCommittee(helper.democracy.fastTrackCall(preimageHash, democracyFastTrackVotingPeriod, 0));
68 .to.be.fulfilled;74 Event.Democracy.Started.expect(fastTrackProposal);
69 });75 });
7076
71 itSub('TechComm can cancel Democracy proposals', async ({helper}) => {77 itSub('TechComm can cancel Democracy proposals', async ({helper}) => {
72 const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);78 const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
73 const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;79 const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
7480
75 await expect(proposalFromAllCommittee(helper.democracy.cancelProposalCall(proposalIndex)))81 const cancelProposal = await proposalFromAllCommittee(helper.democracy.cancelProposalCall(proposalIndex));
76 .to.be.fulfilled;82 Event.Democracy.ProposalCanceled.expect(cancelProposal);
77 });83 });
7884
79 itSub('TechComm can cancel ongoing Democracy referendums', async ({helper}) => {85 itSub('TechComm can cancel ongoing Democracy referendums', async ({helper}) => {
80 await helper.getSudo().democracy.externalProposeDefault(sudoer, dummyProposalCall(helper));86 await helper.getSudo().democracy.externalProposeDefault(sudoer, dummyProposalCall(helper));
81 const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, Event.Democracy.Started);87 const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, Event.Democracy.Started);
82 const referendumIndex = startedEvent.referendumIndex;88 const referendumIndex = startedEvent.referendumIndex;
8389
84 await expect(proposalFromAllCommittee(helper.democracy.emergencyCancelCall(referendumIndex)))90 const emergencyCancelProposal = await proposalFromAllCommittee(helper.democracy.emergencyCancelCall(referendumIndex));
85 .to.be.fulfilled;91 Event.Democracy.Cancelled.expect(emergencyCancelProposal);
86 });92 });
87
8893
89 itSub('TechComm member can veto Democracy proposals', async ({helper}) => {94 itSub('TechComm member can veto Democracy proposals', async ({helper}) => {
90 const preimageHash = await helper.preimage.notePreimageFromCall(sudoer, dummyProposalCall(helper), true);95 const preimageHash = await helper.preimage.notePreimageFromCall(sudoer, dummyProposalCall(helper), true);
91 await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash);96 await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash);
9297
93 await expect(helper.technicalCommittee.collective.execute(98 const vetoExternalCall = await helper.technicalCommittee.collective.execute(
94 techcomms.andy,99 techcomms.andy,
95 helper.democracy.vetoExternalCall(preimageHash),100 helper.democracy.vetoExternalCall(preimageHash),
96 )).to.be.fulfilled;101 );
102 Event.Democracy.Vetoed.expect(vetoExternalCall);
97 });103 });
98104
99 itSub('TechComm can cancel Fellowship referendums', async ({helper}) => {105 itSub('TechComm can cancel Fellowship referendums', async ({helper}) => {
108 defaultEnactmentMoment,114 defaultEnactmentMoment,
109 );115 );
110 const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;116 const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
111 await expect(proposalFromAllCommittee(helper.fellowship.referenda.cancelCall(referendumIndex))).to.be.fulfilled;117 const cancelProposal = await proposalFromAllCommittee(helper.fellowship.referenda.cancelCall(referendumIndex));
118 Event.FellowshipReferenda.Cancelled.expect(cancelProposal);
112 });119 });
113120
114 itSub.skip('TechComm member can add a Fellowship member', async ({helper}) => {121 itSub.skip('TechComm member can add a Fellowship member', async ({helper}) => {
modifiedtests/src/maintenance.seqtest.tsdiffbeforeafterboth
18import {ApiPromise} from '@polkadot/api';18import {ApiPromise} from '@polkadot/api';
19import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';19import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
20import {itEth} from './eth/util';20import {itEth} from './eth/util';
21import {UniqueHelper} from './util/playgrounds/unique';
22import {main as correctState} from './migrations/correctStateAfterMaintenance';21import {main as correctState} from './migrations/correctStateAfterMaintenance';
2322
24async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {23async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
175 referendumIndex: eventJsonData<number>(data, 0),175 referendumIndex: eventJsonData<number>(data, 0),
176 }));176 }));
177
178 static ProposalCanceled = this.Method('ProposalCanceled', data => ({
179 propIndex: eventJsonData<number>(data, 0),
180 }));
181
182 static Cancelled = this.Method('Cancelled', data => ({
183 propIndex: eventJsonData<number>(data, 0),
184 }));
185
186 static Vetoed = this.Method('Vetoed', data => ({
187 who: eventHumanData(data, 0),
188 proposalHash: eventHumanData(data, 1),
189 until: eventJsonData<number>(data, 1),
190 }));
177 };191 };
178192
179 static Council = class extends EventSection('council') {193 static Council = class extends EventSection('council') {
188 yes: eventJsonData<number>(data, 1),202 yes: eventJsonData<number>(data, 1),
189 no: eventJsonData<number>(data, 2),203 no: eventJsonData<number>(data, 2),
190 }));204 }));
205 static Executed = this.Method('Executed', data => ({
206 proposalHash: eventHumanData(data, 0),
207 }));
191 };208 };
192209
193 static TechnicalCommittee = class extends EventSection('technicalCommittee') {210 static TechnicalCommittee = class extends EventSection('technicalCommittee') {
202 yes: eventJsonData<number>(data, 1),219 yes: eventJsonData<number>(data, 1),
203 no: eventJsonData<number>(data, 2),220 no: eventJsonData<number>(data, 2),
204 }));221 }));
222 static Approved = this.Method('Approved', data => ({
223 proposalHash: eventHumanData(data, 0),
224 }));
225 static Executed = this.Method('Executed', data => ({
226 proposalHash: eventHumanData(data, 0),
227 result: eventHumanData(data, 1),
228 }));
205 };229 };
206230
207 static FellowshipReferenda = class extends EventSection('fellowshipReferenda') {231 static FellowshipReferenda = class extends EventSection('fellowshipReferenda') {
211 proposal: eventJsonData(data, 2),235 proposal: eventJsonData(data, 2),
212 }));236 }));
237
238 static Cancelled = this.Method('Cancelled', data => ({
239 index: eventJsonData<number>(data, 0),
240 tally: eventJsonData(data, 1),
241 }));
213 };242 };
214243
215 static UniqueScheduler = schedulerSection('uniqueScheduler');244 static UniqueScheduler = schedulerSection('uniqueScheduler');
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
44 MoonbeamAssetInfo,44 MoonbeamAssetInfo,
45 DemocracyStandardAccountVote,45 DemocracyStandardAccountVote,
46 IEthCrossAccountId,46 IEthCrossAccountId,
47 CollectionFlag,
48 IPhasicEvent,47 IPhasicEvent,
49 DemocracySplitAccount,
50} from './types';48} from './types';
51import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';49import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';
52import type {Vec} from '@polkadot/types-codec';50import type {Vec} from '@polkadot/types-codec';
53import {FrameSupportPreimagesBounded, FrameSupportScheduleDispatchTime, FrameSystemEventRecord, PalletBalancesIdAmount, PalletDemocracyConviction, PalletDemocracyVoteAccountVote} from '@polkadot/types/lookup';51import {FrameSystemEventRecord, PalletDemocracyConviction} from '@polkadot/types/lookup';
54import {arrayUnzip} from '@polkadot/util';
55import {Event} from './unique.dev';
5652
57export class CrossAccountId {53export class CrossAccountId {
58 Substrate!: TSubstrateAccount;54 Substrate!: TSubstrateAccount;