Browse Source

query node - council mappings lint fixes III

ondratra 3 years ago
parent
commit
8f9e2a0011

+ 1 - 0
query-node/mappings/.eslintrc.js

@@ -5,5 +5,6 @@ module.exports = {
   rules: {
     '@typescript-eslint/naming-convention': 'off',
     '@typescript-eslint/no-explicit-any': 'off',
+    '@typescript-eslint/no-non-null-assertion': 'off',
   },
 }

+ 22 - 27
query-node/mappings/src/council.ts

@@ -52,7 +52,6 @@ import {
 
   // Misc
   Membership,
-  VariantNone,
 } from 'query-node/dist/model'
 import { Council, Referendum } from '../generated/types'
 import { CouncilCandidacyNoteMetadata } from '@joystream/metadata-protobuf'
@@ -95,7 +94,6 @@ async function getCandidate(
     relations: ['candidate'].concat(relations.map((r) => `candidate.${r}`)),
   })
 
-
   if (!event) {
     throw new Error(`Candidate not found. memberId '${memberId}' electionRound '${electionRound?.id}'`)
   }
@@ -122,10 +120,7 @@ async function getCouncilMember(store: DatabaseManager, memberId: string): Promi
 /*
   Returns the current election round record.
 */
-async function getCurrentElectionRound(
-  store: DatabaseManager,
-  relations: string[] = []
-): Promise<ElectionRound> {
+async function getCurrentElectionRound(store: DatabaseManager, relations: string[] = []): Promise<ElectionRound> {
   const electionRound = await store.get(ElectionRound, { order: { cycleId: 'DESC' }, relations: relations })
 
   if (!electionRound) {
@@ -872,9 +867,12 @@ export async function referendum_RevealingStageStarted({ event, store }: EventCo
 export async function referendum_ReferendumFinished({ event, store }: EventContext & StoreContext): Promise<void> {
   // common event processing
 
-  const [optionResultsRaw] = new Referendum.ReferendumFinishedEvent(event).params
+  // const [optionResultsRaw] = new Referendum.ReferendumFinishedEvent(event).params
 
-  const electionRound = await getCurrentElectionRound(store, ['referendumStageRevealing', 'referendumStageRevealing.intermediateWinners'])
+  const electionRound = await getCurrentElectionRound(store, [
+    'referendumStageRevealing',
+    'referendumStageRevealing.intermediateWinners',
+  ])
 
   const referendumFinishedEvent = new ReferendumFinishedEvent({
     ...genericEventFields(event),
@@ -986,30 +984,27 @@ async function integrateCandidateToIntermediateWinners(
   }
 
   // compose new list of intermediate winners
-  const [result, toBeAdded] = await referendumStageRevealing.intermediateWinners!.reduce(
-    async (acc, item, index) => {
-      let [newWinners, toBeAdded] = await acc
+  const [result, toBeAdded] = await referendumStageRevealing.intermediateWinners!.reduce(async (acc, item) => {
+    let [newWinners, toBeAdded] = await acc
 
-      // place winner to the list if it has more votes than previous one
-      if (toBeAdded && item.votePower < candidate.votePower) {
-        const newRecord = await addRecord()
+    // place winner to the list if it has more votes than previous one
+    if (toBeAdded && item.votePower < candidate.votePower) {
+      const newRecord = await addRecord()
 
-        newWinners = [...newWinners, newRecord]
-        toBeAdded = false
-      }
+      newWinners = [...newWinners, newRecord]
+      toBeAdded = false
+    }
 
-      // remove no-longer-winner record if needed
-      if (newWinners.length >= winningTargetCount) {
-        await store.remove(item)
+    // remove no-longer-winner record if needed
+    if (newWinners.length >= winningTargetCount) {
+      await store.remove(item)
 
-        return [newWinners, false]
-      }
+      return [newWinners, false]
+    }
 
-      // place winner to the list (possibly to new place among intermediate winners)
-      return [[...newWinners, item], toBeAdded]
-    },
-    Promise.resolve([[], true] as [ReferendumStageRevealingOptionResult[], boolean])
-  )
+    // place winner to the list (possibly to new place among intermediate winners)
+    return [[...newWinners, item], toBeAdded]
+  }, Promise.resolve([[], true] as [ReferendumStageRevealingOptionResult[], boolean]))
 
   // place winner to end of list if needed
   if (toBeAdded && result.length < winningTargetCount) {

+ 1 - 7
query-node/mappings/src/genesis.ts

@@ -1,12 +1,6 @@
 import { StoreContext, DatabaseManager } from '@joystream/hydra-common'
 import BN from 'bn.js'
-import {
-  MembershipSystemSnapshot,
-  WorkingGroup,
-  ElectedCouncil,
-  ElectionRound,
-  VariantNone,
-} from 'query-node/dist/model'
+import { MembershipSystemSnapshot, WorkingGroup, ElectedCouncil, ElectionRound } from 'query-node/dist/model'
 import { membershipSystem, workingGroups } from './genesis-data'
 import { CURRENT_NETWORK } from './common'
 

+ 3 - 1
tests/integration-tests/src/fixtures/council/ElectCouncilFixture.ts

@@ -84,7 +84,9 @@ export class ElectCouncilFixture extends BaseQueryNodeFixture {
       () => query.getReferendumIntermediateWinners(),
       (qnReferendumIntermediateWinners) => {
         assert.sameMembers(
-          qnReferendumIntermediateWinners!.referendumStageRevealing!.intermediateWinners!.map(item => item.option.id.toString()),
+          qnReferendumIntermediateWinners!.referendumStageRevealing!.intermediateWinners!.map((item) =>
+            item.option.id.toString()
+          ),
           candidatesToWinIds
         )
       }

+ 2 - 2
tests/integration-tests/src/fixtures/council/NotEnoughCandidatesFixture.ts

@@ -1,5 +1,5 @@
 import { BaseQueryNodeFixture, FixtureRunner } from '../../Fixture'
-import { assertCouncilMembersRuntimeQnMatch, prepareFailtToElectResources } from './common'
+import { assertCouncilMembersRuntimeQnMatch, prepareFailToElectResources } from './common'
 import { assert } from 'chai'
 
 export class NotEnoughCandidatesFixture extends BaseQueryNodeFixture {
@@ -14,7 +14,7 @@ export class NotEnoughCandidatesFixture extends BaseQueryNodeFixture {
       candidatesMemberAccounts,
       councilCandidateStake,
       councilMemberIds,
-    } = await prepareFailtToElectResources(this.api, this.query)
+    } = await prepareFailToElectResources(this.api, this.query)
 
     const lessCandidatesNumber = 1
     const candidatingMemberIds = candidatesMemberIds.slice(0, candidatesMemberIds.length - lessCandidatesNumber)

+ 2 - 2
tests/integration-tests/src/fixtures/council/NotEnoughCandidatesWithVotesFixture.ts

@@ -1,5 +1,5 @@
 import { BaseQueryNodeFixture, FixtureRunner } from '../../Fixture'
-import { assertCouncilMembersRuntimeQnMatch, prepareFailtToElectResources } from './common'
+import { assertCouncilMembersRuntimeQnMatch, prepareFailToElectResources } from './common'
 import { blake2AsHex } from '@polkadot/util-crypto'
 import { assert } from 'chai'
 import { MINIMUM_STAKING_ACCOUNT_BALANCE } from '../../consts'
@@ -12,7 +12,7 @@ export class NotEnoughCandidatesWithVotesFixture extends BaseQueryNodeFixture {
       candidatesMemberAccounts,
       councilCandidateStake,
       councilMemberIds,
-    } = await prepareFailtToElectResources(this.api, this.query)
+    } = await prepareFailToElectResources(this.api, this.query)
 
     const lessVotersNumber = 1
     const numberOfCandidates = candidatesMemberIds.length

+ 4 - 1
tests/integration-tests/src/fixtures/proposals/CreateProposalsFixture.ts

@@ -287,7 +287,10 @@ export class CreateProposalsFixture extends StandardizedFixture {
         Utils.assert(qProposal.details.__typename === 'UpdateWorkingGroupBudgetProposalDetails')
         const details = proposalDetails.asType('UpdateWorkingGroupBudget')
         const [balance, group, balanceKind] = details
-        assert.equal(qProposal.details.amount.toString(), (balanceKind.isOfType('Negative') ? '-' : '') + balance.toString())
+        assert.equal(
+          qProposal.details.amount.toString(),
+          (balanceKind.isOfType('Negative') ? '-' : '') + balance.toString()
+        )
         assert.equal(qProposal.details.group?.id, getWorkingGroupModuleName(group))
         break
       }