Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add event asserts #982

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/src/fetchMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { writeFile } from "fs/promises";
import { join } from "path";
import { exit } from "process";
import { fileURLToPath } from "url";
import {writeFile} from 'fs/promises';
import {join} from 'path';
import {exit} from 'process';
import {fileURLToPath} from 'url';

const url = process.env.RPC_URL;
if (!url) throw new Error('RPC_URL is not set');
if(!url) throw new Error('RPC_URL is not set');

const srcDir = fileURLToPath(new URL('.', import.meta.url));

for (let i = 0; i < 10; i++) {
for(let i = 0; i < 10; i++) {
try {
console.log(`Trying to fetch metadata, retry ${i + 1}/${10}`)
console.log(`Trying to fetch metadata, retry ${i + 1}/${10}`);
const response = await fetch(url, {
method: 'POST',
headers: {
Expand Down
33 changes: 20 additions & 13 deletions tests/src/governance/technicalCommittee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describeGov('Governance: Technical Committee tests', () => {
});
});

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,
Expand All @@ -54,7 +54,13 @@ describeGov('Governance: Technical Committee tests', () => {
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;
});
}

Expand All @@ -64,36 +70,36 @@ describeGov('Governance: Technical Committee tests', () => {

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}) => {
await helper.getSudo().democracy.externalProposeDefault(sudoer, dummyProposalCall(helper));
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}) => {
Expand All @@ -108,7 +114,8 @@ describeGov('Governance: Technical Committee tests', () => {
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}) => {
Expand Down
29 changes: 29 additions & 0 deletions tests/src/util/playgrounds/unique.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ export class Event {
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') {
Expand All @@ -188,6 +202,9 @@ export class Event {
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') {
Expand All @@ -202,6 +219,13 @@ export class Event {
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') {
Expand All @@ -210,6 +234,11 @@ export class Event {
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');
Expand Down