From e027a43a534751105ad20deb070529ab0eda673f Mon Sep 17 00:00:00 2001 From: Phil Bain Date: Tue, 12 Oct 2021 15:30:08 -0600 Subject: [PATCH] fix tests --- .../src/GovPollingService.js | 2 +- .../test/GovPollingService.test.js | 63 +++++++------------ .../dai-plugin-governance/test/fixtures.js | 53 ++++++++++++++++ 3 files changed, 78 insertions(+), 40 deletions(-) diff --git a/packages/dai-plugin-governance/src/GovPollingService.js b/packages/dai-plugin-governance/src/GovPollingService.js index 9b043c528..83b73fab5 100644 --- a/packages/dai-plugin-governance/src/GovPollingService.js +++ b/packages/dai-plugin-governance/src/GovPollingService.js @@ -352,7 +352,7 @@ export default class GovPollingService extends PrivateService { const options = summedSupport.reduce((a, v) => { a[v.optionId] = { mkrSupport: new BigNumber(v.mkrSupport || 0), - winner: v.optionId === parseInt(winner) + winner: v.optionId === winner }; return a; }, {}); diff --git a/packages/dai-plugin-governance/test/GovPollingService.test.js b/packages/dai-plugin-governance/test/GovPollingService.test.js index 7cb6b3a47..1318bca76 100644 --- a/packages/dai-plugin-governance/test/GovPollingService.test.js +++ b/packages/dai-plugin-governance/test/GovPollingService.test.js @@ -26,7 +26,9 @@ import { dummyBallotDontMoveToEliminated, dummyBallotDontMoveToEliminatedExpect, dummyBallotStopWhenOneRemains, - dummyBallotStopWhenOneRemainsExpect + dummyBallotStopWhenOneRemainsExpect, + dummyMkrGetMkrSupportRCForPluralityData, + dummyMkrGetMkrSupportRCForPluralityDataAdjusted } from './fixtures'; import { MKR } from '../src/utils/constants'; @@ -329,23 +331,25 @@ test('should correctly decode ranked choice options from event logs', () => { }); test('plurality tally', async () => { - govQueryApiService.getMkrSupport = jest.fn(() => dummyMkrSupportData); + govQueryApiService.getMkrSupportRankedChoice = jest.fn( + () => dummyMkrGetMkrSupportRCForPluralityData + ); govPollingService._getPoll = jest.fn(() => ({ endDate: 123 })); const tally = await govPollingService.getTallyPlurality(); const expectedResult = { - winner: '2', - totalMkrParticipation: '160', - numVoters: 2, + winner: '1', + totalMkrParticipation: '809', + numVoters: 5, options: { - '1': { - mkrSupport: '40', + '0': { + mkrSupport: '109', winner: false }, - '2': { - mkrSupport: '120', + '1': { + mkrSupport: '700', winner: true } } @@ -355,28 +359,9 @@ test('plurality tally', async () => { }); test('plurality tally with adjusted votes', async () => { - const mkrSupportData = [ - { - optionId: 1, - mkrSupport: 40, - percentage: 48, - blockTimestamp: Date.now() - }, - { - optionId: 2, - mkrSupport: 41, - percentage: 49, - blockTimestamp: Date.now() - }, - { - optionId: 3, - mkrSupport: 1, - percentage: 1, - blockTimestamp: Date.now() - } - ]; - - govQueryApiService.getMkrSupport = jest.fn(() => mkrSupportData); + govQueryApiService.getMkrSupportRankedChoice = jest.fn( + () => dummyMkrGetMkrSupportRCForPluralityDataAdjusted + ); govPollingService._getPoll = jest.fn(() => ({ endDate: 123 })); @@ -384,20 +369,20 @@ test('plurality tally with adjusted votes', async () => { const expectedResult = { winner: '2', - totalMkrParticipation: '82', - numVoters: 3, + totalMkrParticipation: '2041', + numVoters: 7, options: { + '0': { + mkrSupport: '109', + winner: false + }, '1': { - mkrSupport: '40', + mkrSupport: '700', winner: false }, '2': { - mkrSupport: '41', + mkrSupport: '1232', winner: true - }, - '3': { - mkrSupport: '1', - winner: false } } }; diff --git a/packages/dai-plugin-governance/test/fixtures.js b/packages/dai-plugin-governance/test/fixtures.js index 8d86b2d29..380a0dabe 100644 --- a/packages/dai-plugin-governance/test/fixtures.js +++ b/packages/dai-plugin-governance/test/fixtures.js @@ -16,6 +16,59 @@ export const dummyMkrSupportData = [ } ]; +export const dummyMkrGetMkrSupportRCForPluralityData = [ + { + optionIdRaw: '1', + mkrSupport: '40' + }, + { + optionIdRaw: '1', + mkrSupport: '60' + }, + { + optionIdRaw: '0', + mkrSupport: '77' + }, + { + optionIdRaw: '0', + mkrSupport: '32' + }, + { + optionIdRaw: '1', + mkrSupport: '600' + } +]; +export const dummyMkrGetMkrSupportRCForPluralityDataAdjusted = [ + { + optionIdRaw: '1', + mkrSupport: '40' + }, + { + optionIdRaw: '1', + mkrSupport: '60' + }, + { + optionIdRaw: '0', + mkrSupport: '77' + }, + { + optionIdRaw: '0', + mkrSupport: '32' + }, + { + optionIdRaw: '1', + mkrSupport: '600' + }, + { + optionIdRaw: '2', + mkrSupport: '32' + }, + { + optionIdRaw: '2', + mkrSupport: '1200' + } +]; + export const dummyAllPollsData = [ { creator: '0xeda95d1bdb60f901986f43459151b6d1c734b8a2',