Skip to content

Commit

Permalink
feat(tests): add relay and assethub xcm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Dec 17, 2024
1 parent 0d16bed commit 6a65032
Show file tree
Hide file tree
Showing 12 changed files with 812 additions and 165 deletions.
27 changes: 27 additions & 0 deletions js-packages/playgrounds/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
TSubstrateAccount,
TNetworks,
IEthCrossAccountId,
IPhasicEvent,
} from './types.js';
import type {RuntimeDispatchInfo} from '@polkadot/types/interfaces';

Expand Down Expand Up @@ -368,6 +369,32 @@ class UniqueEventHelper {

return parsedEvents;
}

public static extractPhasicEvents(events: { event: any, phase: any }[]): IPhasicEvent[] {
const parsedEvents: IPhasicEvent[] = [];

events.forEach((record) => {
const {event, phase} = record;

const eventData: IEvent = {
section: event.section.toString(),
method: event.method.toString(),
index: this.extractIndex(event.index),

// assigned without any transformation for compatibility with the `ITransactionResult` events
data: event.data,

phase: phase.toJSON(),
};

parsedEvents.push({
phase,
event: eventData,
});
});

return parsedEvents;
}
}
const InvalidTypeSymbol = Symbol('Invalid type');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
2 changes: 2 additions & 0 deletions js-packages/scripts/createHrmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ await usingPlaygrounds(async (helper, privateKey) => {
default:
throw new Error(`unknown hrmp config profile: ${profile}`);
}

await helper.wait.newSessions(1);
}, config.relayUrl);
// We miss disconnect/unref somewhere.
process.exit(0);
22 changes: 17 additions & 5 deletions js-packages/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {ApiPromise, Keyring, WsProvider} from '@polkadot/api';
import * as defs from '@unique-nft/opal-testnet-types/definitions.js';
import type {IKeyringPair} from '@polkadot/types/types';
import type {EventRecord} from '@polkadot/types/interfaces';
import type {ICrossAccountId, ILogger, IPovInfo, ISchedulerOptions, ITransactionResult, TSigner} from '@unique-nft/playgrounds/types.js';
import type {ICrossAccountId, ILogger, IPhasicEvent, IPovInfo, ISchedulerOptions, ITransactionResult, TSigner} from '@unique-nft/playgrounds/types.js';
import type {FrameSystemEventRecord, XcmV2TraitsError, StagingXcmV4TraitsOutcome} from '@polkadot/types/lookup';
import type {SignerOptions, VoidFn} from '@polkadot/api/types';
import {spawnSync} from 'child_process';
Expand Down Expand Up @@ -102,13 +102,13 @@ function EventHelper(section: string, method: string, wrapEvent: (data: any[]) =
.map(e => this.wrapEvent(e.event.data));
}

find(txres: ITransactionResult) {
const e = txres.result.events.find(e => e.event.section === section && e.event.method === method);
find(events: IPhasicEvent[]) {
const e = events.find(e => e.event.section === section && e.event.method === method);
return e ? this.wrapEvent(e.event.data) : null;
}

expect(txres: ITransactionResult) {
const e = this.find(txres);
expect(events: IPhasicEvent[]) {
const e = this.find(events);
if(e) {
return e;
} else {
Expand Down Expand Up @@ -274,6 +274,18 @@ export class Event {
}));
};

static XcmPallet = class extends EventSection('xcmPallet') {
static Sent = this.Method('Sent', data => ({
messageHash: eventJsonData(data, 3),
}));
};

static PolkadotXcm = class extends EventSection('polkadotXcm') {
static Sent = this.Method('Sent', data => ({
messageHash: eventJsonData(data, 3),
}));
};

static MessageQueue = class extends EventSection('messageQueue') {
static Processed = this.Method('Processed', data => ({
messageHash: eventJsonData(data, 0),
Expand Down
20 changes: 10 additions & 10 deletions js-packages/tests/sub/governance/council.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);
const councilProposedEvent = Event.Council.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand All @@ -61,7 +61,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);
const councilProposedEvent = Event.Council.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand Down Expand Up @@ -92,7 +92,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);
const councilProposedEvent = Event.Council.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand Down Expand Up @@ -145,15 +145,15 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);
const councilProposedEvent = Event.Council.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

await helper.council.collective.vote(counselors.alex, proposalHash, proposalIndex, true);

await helper.wait.newBlocks(councilMotionDuration);
const closeResult = await helper.council.collective.close(counselors.filip, proposalHash, proposalIndex);
const closeEvent = Event.Council.Closed.expect(closeResult);
const closeEvent = Event.Council.Closed.expect(closeResult.result.events);
const members = (await helper.callRpc('api.query.councilMembership.members')).toJSON() as string[];
expect(closeEvent.yes).to.be.equal(members.length);
});
Expand Down Expand Up @@ -396,7 +396,7 @@ describeGov('Governance: Council tests', () => {

itSub('[Negative] Council cannot cancel Democracy proposals', async ({helper}) => {
const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult.result.events).proposalIndex;

await expect(proposalFromAllCouncil(helper.democracy.cancelProposalCall(proposalIndex)))
.to.be.rejectedWith(/BadOrigin/);
Expand All @@ -405,7 +405,7 @@ describeGov('Governance: Council tests', () => {
itSub('[Negative] Council member cannot cancel Democracy proposals', async ({helper}) => {

const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult.result.events).proposalIndex;

await expect(helper.council.collective.execute(
counselors.alex,
Expand Down Expand Up @@ -445,7 +445,7 @@ describeGov('Governance: Council tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;

await expect(proposalFromAllCouncil(helper.fellowship.referenda.cancelCall(referendumIndex)))
.to.be.rejectedWith(/BadOrigin/);
Expand All @@ -462,7 +462,7 @@ describeGov('Governance: Council tests', () => {
proposal,
defaultEnactmentMoment,
);
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;
await expect(helper.council.collective.execute(
counselors.alex,
helper.fellowship.referenda.cancelCall(referendumIndex),
Expand All @@ -478,7 +478,7 @@ describeGov('Governance: Council tests', () => {
councilSize,
);

const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);
const councilProposedEvent = Event.Council.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand Down
2 changes: 1 addition & 1 deletion js-packages/tests/sub/governance/democracy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describeGov('Governance: Democracy tests', () => {
{After: 0},
);

const fellowshipReferendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const fellowshipReferendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;
await voteUnanimouslyInFellowship(helper, fellows, democracyTrackMinRank, fellowshipReferendumIndex);
await helper.fellowship.referenda.placeDecisionDeposit(donor, fellowshipReferendumIndex);

Expand Down
2 changes: 1 addition & 1 deletion js-packages/tests/sub/governance/electsudo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describeGov('Governance: Elect Sudo', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);
const councilProposedEvent = Event.Council.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand Down
14 changes: 7 additions & 7 deletions js-packages/tests/sub/governance/fellowship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;
await voteUnanimouslyInFellowship(helper, members, democracyTrackMinRank, referendumIndex);
await helper.fellowship.referenda.placeDecisionDeposit(donor, referendumIndex);

Expand Down Expand Up @@ -85,7 +85,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const fellowshipReferendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const fellowshipReferendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;
await voteUnanimouslyInFellowship(helper, members, democracyTrackMinRank, fellowshipReferendumIndex);
await helper.fellowship.referenda.placeDecisionDeposit(donor, fellowshipReferendumIndex);

Expand Down Expand Up @@ -116,7 +116,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;
const referendumInfo = await helper.fellowship.referenda.referendumInfo(referendumIndex);
expect(referendumInfo.ongoing.track, `${memberIdx}-th member of rank #${rank}: proposal #${referendumIndex} is on invalid track`)
.to.be.equal(democracyTrackId);
Expand All @@ -134,7 +134,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;

let expectedAyes = 0;
for(let rank = democracyTrackMinRank; rank < fellowshipRankLimit; rank++) {
Expand Down Expand Up @@ -171,7 +171,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;

for(let rank = democracyTrackMinRank; rank < fellowshipRankLimit; rank++) {
const rankMembers = members[rank];
Expand Down Expand Up @@ -253,7 +253,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;

for(let rank = 0; rank < democracyTrackMinRank; rank++) {
for(const member of members[rank]) {
Expand Down Expand Up @@ -304,7 +304,7 @@ describeGov('Governance: Fellowship tests', () => {

itSub('[Negative] FellowshipProposition cannot cancel Democracy proposals', async ({helper}) => {
const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult.result.events).proposalIndex;

await testBadFellowshipProposal(helper, helper.democracy.cancelProposalCall(proposalIndex));
});
Expand Down
12 changes: 6 additions & 6 deletions js-packages/tests/sub/governance/financialCouncil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describeGov('Governance: Financial Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.FinCouncil.Proposed.expect(proposeResult);
const councilProposedEvent = Event.FinCouncil.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand All @@ -56,7 +56,7 @@ describeGov('Governance: Financial Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = Event.FinCouncil.Proposed.expect(proposeResult);
const councilProposedEvent = Event.FinCouncil.Proposed.expect(proposeResult.result.events);
const proposalIndex = councilProposedEvent.proposalIndex;
const proposalHash = councilProposedEvent.proposalHash;

Expand Down Expand Up @@ -118,15 +118,15 @@ describeGov('Governance: Financial Council tests', () => {

itSub('[Negative] FinCouncil can\'t cancel Democracy proposals', async ({helper}) => {
const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult.result.events).proposalIndex;

await expect(proposalFromAllFinCouncil(helper.democracy.cancelProposalCall(proposalIndex)))
.rejectedWith('BadOrigin');
});

itSub('[Negative] FinCouncil member cannot cancel Democracy proposals', async ({helper}) => {
const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult).proposalIndex;
const proposalIndex = Event.Democracy.Proposed.expect(proposeResult.result.events).proposalIndex;

await expect(helper.finCouncil.collective.execute(
finCounselors.andy,
Expand Down Expand Up @@ -201,7 +201,7 @@ describeGov('Governance: Financial Council tests', () => {
proposal,
defaultEnactmentMoment,
);
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;
await expect(proposalFromAllFinCouncil(helper.fellowship.referenda.cancelCall(referendumIndex)))
.rejectedWith('BadOrigin');
});
Expand All @@ -218,7 +218,7 @@ describeGov('Governance: Financial Council tests', () => {
defaultEnactmentMoment,
);

const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult).referendumIndex;
const referendumIndex = Event.FellowshipReferenda.Submitted.expect(submitResult.result.events).referendumIndex;

await expect(helper.finCouncil.collective.execute(
finCounselors.andy,
Expand Down
Loading

0 comments on commit 6a65032

Please sign in to comment.