Эх сурвалжийг харах

rename waitForProposalToFinalize

Mokhtar Naamani 4 жил өмнө
parent
commit
5463017e5a

+ 6 - 20
tests/network-tests/src/Api.ts

@@ -850,9 +850,12 @@ export class Api {
     }
   }
 
-  // Resolves to true when proposal finalized and executed successfully
-  // Resolved to false when proposal finalized and execution fails
-  public async waitForProposalToFinalize(id: ProposalId): Promise<InvertedPromise<[boolean, EventRecord[]]>> {
+  // Subscribe to system events, resolves to an InvertedPromise or rejects if subscription fails.
+  // The inverted promise wraps a promise which resolves when the Proposal with id specified
+  // is executed.
+  // - On successful execution the wrapped promise resolves to `[true, events]`
+  // - On failed execution the wrapper promise resolves to `[false, events]`
+  public async subscribeToProposalExecutionResult(id: ProposalId): Promise<InvertedPromise<[boolean, EventRecord[]]>> {
     const invertedPromise = new InvertedPromise<[boolean, EventRecord[]]>()
     const unsubscribe = await this.api.query.system.events<Vec<EventRecord>>((events) => {
       events.forEach((record) => {
@@ -889,23 +892,6 @@ export class Api {
     }
   }
 
-  // Looks for the first occurance of an expected event, and resolves.
-  // Use this when the event we are expecting is not particular to a specific extrinsic,
-  // Normally events emitted from on_initialize() or on_finalize() in a call
-  public async waitForSystemEvent(eventName: string): Promise<InvertedPromise<Event>> {
-    const invertedPromise = new InvertedPromise<Event>()
-    const unsubscribe = await this.api.query.system.events<Vec<EventRecord>>((events) => {
-      events.forEach((record) => {
-        if (record.event.method && record.event.method.toString() === eventName) {
-          unsubscribe()
-          invertedPromise.resolve(record.event)
-        }
-      })
-    })
-
-    return invertedPromise
-  }
-
   public findApplicationReviewBeganEvent(
     events: EventRecord[],
     workingGroup: WorkingGroups

+ 2 - 2
tests/network-tests/src/fixtures/proposalsModule.ts

@@ -735,10 +735,10 @@ export class VoteForProposalFixture extends BaseFixture {
     this.api.treasuryTransferBalanceToAccounts(councilAccounts, proposalVoteFee)
 
     // Approving the proposal
-    const onProposalFinalized = await this.api.waitForProposalToFinalize(this.proposalNumber)
+    const proposalExecutionResult = await this.api.subscribeToProposalExecutionResult(this.proposalNumber)
     const approvals = await this.api.batchApproveProposal(this.proposalNumber)
     approvals.map((result) => this.expectDispatchSuccess(result, 'Proposal Approval Vote Expected To Be Successful'))
-    const proposalOutcome = await onProposalFinalized.promise
+    const proposalOutcome = await proposalExecutionResult.promise
     this._proposalExecuted = proposalOutcome[0]
     this._events = proposalOutcome[1]
   }

+ 3 - 3
tests/network-tests/src/flows/proposals/electionParametersProposal.ts

@@ -10,15 +10,15 @@ export default async function electionParametersProposal({ api, lock }: FlowProp
   const debug = Debugger('integration-tests:flow:electionParametersProposal')
   debug('Started')
   await lock(Resource.Proposals)
-  debug('lock acquired contining flow')
+
   // Pre-Conditions: some members and an elected council
   const council = await api.getCouncil()
   assert.notEqual(council.length, 0)
-  debug('selected proposer')
+
   const proposer = council[0].member.toString()
 
   const electionParametersProposalFixture = new ElectionParametersProposalFixture(api, proposer)
-  debug('created fixture, running it')
+
   await new FixtureRunner(electionParametersProposalFixture).run()
 
   debug('Done')