Browse Source

integration-tests: handle race condition when voting on proposals

Mokhtar Naamani 3 years ago
parent
commit
9db517272c

+ 15 - 3
tests/network-tests/src/fixtures/proposalsModule.ts

@@ -732,10 +732,22 @@ export class VoteForProposalFixture extends BaseFixture {
     const councilAccounts = await this.api.getCouncilAccounts()
     this.api.treasuryTransferBalanceToAccounts(councilAccounts, proposalVoteFee)
 
-    // Approving the proposal
+    // Catch the proposal execution result
     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'))
+
+    // Approve proposal
+    // const approvals =
+    await this.api.batchApproveProposal(this.proposalNumber)
+
+    // Depending on the "approval_threshold_percentage" paramater for the proposal type, it might happen
+    // that the proposal can pass before all votes are cast, and this can result in an approval vote
+    // failing with a 'ProposalFinalized' Dispatch error. Important to note that depending on how many
+    // votes make it into a block, it may not always manifest becasuse the check for proposal finalization
+    // happens in on_finalize. So we no longer assert that all vote dispatches are successful.
+    // "Not taking this into account has resulted in tests failing undeterminisctly in the past.."
+    // approvals.map((result) => this.expectDispatchSuccess(result, 'Proposal Approval Vote Expected To Be Successful'))
+
+    // Wait for the proposal to finalize
     const proposalOutcome = await proposalExecutionResult.promise
     this._proposalExecuted = proposalOutcome[0]
     this._events = proposalOutcome[1]

+ 0 - 1
tests/network-tests/src/flows/membership/creatingMemberships.ts

@@ -12,7 +12,6 @@ import { assert } from 'chai'
 export default async function membershipCreation({ api, env }: FlowProps): Promise<void> {
   const debug = extendDebug('flow:memberships')
   debug('Started')
-  api.enableDebugTxLogs()
 
   const N: number = +env.MEMBERSHIP_CREATION_N!
   assert(N > 0)

+ 4 - 1
tests/network-tests/src/flows/proposals/manageLeaderRole.ts

@@ -33,7 +33,6 @@ export default {
 
 async function manageLeaderRole(api: Api, env: NodeJS.ProcessEnv, group: WorkingGroups, lock: ResourceLocker) {
   const debug = extendDebug(`flow:managerLeaderRole:${group}`)
-  api.enableDebugTxLogs()
   debug('Started')
   await lock(Resource.Proposals)
 
@@ -83,6 +82,7 @@ async function manageLeaderRole(api: Api, env: NodeJS.ProcessEnv, group: Working
   )
 
   await new FixtureRunner(voteForCreateOpeningProposalFixture).run()
+  assert(voteForCreateOpeningProposalFixture.proposalExecuted)
 
   const openingId = api.findOpeningAddedEvent(voteForCreateOpeningProposalFixture.events, group) as OpeningId
   assert(openingId)
@@ -113,6 +113,7 @@ async function manageLeaderRole(api: Api, env: NodeJS.ProcessEnv, group: Working
   )
 
   await new FixtureRunner(voteForBeginReviewProposal).run()
+  assert(voteForBeginReviewProposal.proposalExecuted)
 
   const fillLeaderOpeningProposalFixture = new FillLeaderOpeningProposalFixture(
     api,
@@ -133,6 +134,7 @@ async function manageLeaderRole(api: Api, env: NodeJS.ProcessEnv, group: Working
   )
   // Approve fill leader opening
   await new FixtureRunner(voteForFillLeaderProposalFixture).run()
+  assert(voteForFillLeaderProposalFixture.proposalExecuted)
 
   const hiredLead = await api.getGroupLead(group)
   assert(hiredLead)
@@ -148,6 +150,7 @@ async function manageLeaderRole(api: Api, env: NodeJS.ProcessEnv, group: Working
 
   // Approve new leader reward
   await new FixtureRunner(voteForeLeaderRewardFixture).run()
+  assert(voteForeLeaderRewardFixture.proposalExecuted)
 
   const leadId = (await api.getLeadWorkerId(group)) as WorkerId
   assert(leadId)

+ 0 - 1
tests/network-tests/src/flows/workingGroup/atLeastValueBug.ts

@@ -10,7 +10,6 @@ import { FixtureRunner } from '../../Fixture'
 export default async function zeroAtLeastValueBug({ api, env }: FlowProps): Promise<void> {
   const debug = extendDebug('flow:atLeastValueBug')
   debug('Started')
-  api.enableDebugTxLogs()
 
   const applicationStake: BN = new BN(env.WORKING_GROUP_APPLICATION_STAKE!)
   const roleStake: BN = new BN(env.WORKING_GROUP_ROLE_STAKE!)

+ 4 - 4
tests/network-tests/src/scenarios/full.ts

@@ -18,18 +18,18 @@ scenario(async ({ job }) => {
 
   const councilJob = job('council setup', councilSetup)
 
-  job('proposals', [
+  const proposalsJob = job('proposals', [
     electionParametersProposal,
     spendingProposal,
     textProposal,
     validatorCountProposal,
     wgMintCapacityProposal.storage,
     wgMintCapacityProposal.content,
+    manageLeaderRole.storage,
+    manageLeaderRole.content,
   ]).requires(councilJob)
 
-  const manageLeadsJob = job('lead-roles', [manageLeaderRole.storage, manageLeaderRole.content]).requires(councilJob)
-
-  const leadSetupJob = job('setup leads', [leaderSetup.storage, leaderSetup.content]).after(manageLeadsJob)
+  const leadSetupJob = job('setup leads', [leaderSetup.storage, leaderSetup.content]).after(proposalsJob)
 
   // Test bug only on one instance of working group is sufficient
   job('at least value bug', atLeastValueBug).requires(leadSetupJob)