Skip to content

Commit

Permalink
fix: xcm hydradx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Jan 11, 2025
1 parent d312b62 commit 16586d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
6 changes: 6 additions & 0 deletions js-packages/playgrounds/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,12 @@ export class ChainHelperBase {
const palletNames = this.fetchAllPalletNames();
return requiredPallets.filter(p => !palletNames.includes(p));
}

async fetchPhasicEventsFromBlock(blockHash: string) {
const apiAt = await this.getApi().at(blockHash);
const eventRecords = (await apiAt.query.system.events()).toArray();
return this.eventHelper.extractPhasicEvents(eventRecords);
}
}


Expand Down
36 changes: 16 additions & 20 deletions js-packages/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ class MoonbeamFastDemocracyGroup {

const councilVotingThreshold = 2;
const technicalCommitteeThreshold = 2;
const fastTrackVotingPeriod = 3;
const fastTrackVotingPeriod = 10;
const fastTrackDelayPeriod = 0;

console.log(`[democracy] executing '${proposalDesciption}' proposal`);
Expand Down Expand Up @@ -1150,7 +1150,7 @@ class MoonbeamFastDemocracyGroup {
await this.helper.collective.techCommittee.vote(baltatharAccount, fastTrackHash, techProposalIdx, true);
await this.helper.collective.techCommittee.vote(alithAccount, fastTrackHash, techProposalIdx, true);

await this.helper.collective.techCommittee.close(
const techCommCloseResult = await this.helper.collective.techCommittee.close(
baltatharAccount,
fastTrackHash,
techProposalIdx,
Expand All @@ -1163,7 +1163,12 @@ class MoonbeamFastDemocracyGroup {
console.log('\t* Fast track proposal through technical committee.......DONE');
// <<< Fast track proposal through technical committee <<<

const democracyStarted = await this.helper.wait.expectEvent(3, Event.Democracy.Started);
// FIXME
// WORKAROUND: sometimes a part of the events collected directly from the extrinsic
// is lost somehow. Let's query all of them from the block.
const techCommCloseEvents = await this.helper.fetchPhasicEventsFromBlock(techCommCloseResult.blockHash);

const democracyStarted = Event.Democracy.Started.expect(techCommCloseEvents);
const referendumIndex = democracyStarted.referendumIndex;

// >>> Referendum voting >>>
Expand All @@ -1174,13 +1179,6 @@ class MoonbeamFastDemocracyGroup {
});
console.log(`\t* Referendum #${referendumIndex} voting.......DONE`);
// <<< Referendum voting <<<

// Wait the proposal to pass
await this.helper.wait.expectEvent(3, Event.Democracy.Passed, event => event.referendumIndex == referendumIndex);

await this.helper.wait.newBlocks(1);

console.log(`[democracy] executing '${proposalDesciption}' proposal.......DONE`);
}
}

Expand All @@ -1199,7 +1197,7 @@ class HydraFastDemocracyGroup {

const councilVotingThreshold = 1;
const technicalCommitteeThreshold = 3;
const fastTrackVotingPeriod = 3;
const fastTrackVotingPeriod = 10;
const fastTrackDelayPeriod = 0;

console.log(`[democracy] executing '${proposalDesciption}' proposal`);
Expand Down Expand Up @@ -1235,7 +1233,7 @@ class HydraFastDemocracyGroup {
await this.helper.collective.techCommittee.vote(bobAccount, fastTrackHash, techProposalIdx, true);
await this.helper.collective.techCommittee.vote(eveAccount, fastTrackHash, techProposalIdx, true);

await this.helper.collective.techCommittee.close(
const techCommCloseResult = await this.helper.collective.techCommittee.close(
bobAccount,
fastTrackHash,
techProposalIdx,
Expand All @@ -1248,7 +1246,12 @@ class HydraFastDemocracyGroup {
console.log('\t* Fast track proposal through technical committee.......DONE');
// <<< Fast track proposal through technical committee <<<

const democracyStarted = await this.helper.wait.expectEvent(3, Event.Democracy.Started);
// FIXME
// WORKAROUND: sometimes a part of the events collected directly from the extrinsic
// is lost somehow. Let's query all of them from the block.
const techCommCloseEvents = await this.helper.fetchPhasicEventsFromBlock(techCommCloseResult.blockHash);

const democracyStarted = Event.Democracy.Started.expect(techCommCloseEvents);
const referendumIndex = democracyStarted.referendumIndex;

// >>> Referendum voting >>>
Expand All @@ -1259,13 +1262,6 @@ class HydraFastDemocracyGroup {
});
console.log(`\t* Referendum #${referendumIndex} voting.......DONE`);
// <<< Referendum voting <<<

// Wait the proposal to pass
await this.helper.wait.expectEvent(3, Event.Democracy.Passed, event => event.referendumIndex == referendumIndex);

await this.helper.wait.newBlocks(1);

console.log(`[democracy] executing '${proposalDesciption}' proposal.......DONE`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions js-packages/test-utils/xcm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DemocracyGroup<T extends ChainHelperBase> extends HelperGroup<T> {
}

async referendumVote(signer: TSigner, referendumIndex: number, accountVote: DemocracyStandardAccountVote) {
await this.helper.executeExtrinsic(signer, 'api.tx.democracy.vote', [referendumIndex, {Standard: accountVote}], true);
return await this.helper.executeExtrinsic(signer, 'api.tx.democracy.vote', [referendumIndex, {Standard: accountVote}], true);
}
}

Expand All @@ -114,7 +114,7 @@ class MoonbeamCollectiveGroup extends HelperGroup<MoonbeamHelper> {
}

async close(signer: TSigner, proposalHash: string, proposalIndex: number, weightBound: any, lengthBound: number) {
await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.close`, [proposalHash, proposalIndex, weightBound, lengthBound], true);
return await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.close`, [proposalHash, proposalIndex, weightBound, lengthBound], true);
}

async proposalCount() {
Expand All @@ -140,7 +140,7 @@ class CollectiveGroup<T extends ChainHelperBase> extends HelperGroup<T> {
}

async close(signer: TSigner, proposalHash: string, proposalIndex: number, weightBound: any, lengthBound: number) {
await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.close`, [proposalHash, proposalIndex, weightBound, lengthBound], true);
return await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.close`, [proposalHash, proposalIndex, weightBound, lengthBound], true);
}

async proposalCount() {
Expand Down
8 changes: 3 additions & 5 deletions js-packages/tests/xcm/xcm.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SHIDEN_DECIMALS = 18n;
export const ASTAR_DECIMALS = 18;
export const UNQ_DECIMALS = 18;

export const maxWaitBlocks = 50;
export const maxWaitBlocks = 80;

export const expectDownwardXcmNoPermission = async (helper: DevUniqueHelper) => {
// The correct messageHash for downward messages can't be reliably obtained
Expand Down Expand Up @@ -270,9 +270,7 @@ export class XcmTestHelper {
// FIXME
// WORKAROUND: sometimes a part of the events collected directly from the extrinsic
// is lost somehow. Let's query all of them from the block.
const apiAt = await fromHelper.getApi().at(txResult.blockHash);
const eventRecords = (await apiAt.query.system.events()).toArray();
const events = fromHelper.eventHelper.extractPhasicEvents(eventRecords);
const events = await fromHelper.fetchPhasicEventsFromBlock(txResult.blockHash);

if(from === 'relay') {
return Event.XcmPallet.Sent.expect(events);
Expand Down Expand Up @@ -455,7 +453,7 @@ export class XcmTestHelper {

const collectedEventData = await this.#collectProcessedMsgsEvents(
helper,
getMessageHash,
() => getMessageHash() === null,
);

const validEventIndex = collectedEventData.findIndex(data => {
Expand Down

0 comments on commit 16586d0

Please sign in to comment.