From a8b2abdf33d94dbaa29423edc51b475c4e68f383 Mon Sep 17 00:00:00 2001 From: Tyler Sorensen Date: Thu, 28 May 2020 16:30:10 -0700 Subject: [PATCH] add tests for two new ranked choice functions --- .../test/GovPollingService.test.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/dai-plugin-governance/test/GovPollingService.test.js b/packages/dai-plugin-governance/test/GovPollingService.test.js index 523aa9745..436ddf2d7 100644 --- a/packages/dai-plugin-governance/test/GovPollingService.test.js +++ b/packages/dai-plugin-governance/test/GovPollingService.test.js @@ -107,6 +107,19 @@ test('getMkrAmtVoted', async () => { expect(total).toEqual(MKR(160)); }); +test('getMkrAmtVotedRankedChoice', async () => { + govQueryApiService.getMkrSupportRankedChoice = jest.fn( + () => dummyBallotWithMajority + ); + govPollingService._getPoll = jest.fn(() => ({ + endDate: 123 + })); + const amount = await govPollingService.getMkrAmtVotedRankedChoice(); + expect(amount.toNumber()).toBe( + parseFloat(dummyBallotWithMajorityExpect.totalMkrParticipation) + ); +}); + test('getOptionVotingFor', async () => { const mockFn = jest.fn(async () => dummyOption); govQueryApiService.getOptionVotingFor = mockFn; @@ -147,6 +160,26 @@ test('getPercentageMkrVoted', async () => { expect(percentage).toBe(40); }); +test('getPercentageMkrVotedRankedChoice', async () => { + govQueryApiService.getMkrSupportRankedChoice = jest.fn( + () => dummyBallotWithMajority + ); + govPollingService._getPoll = jest.fn(() => ({ + endDate: 123 + })); + const percentage = await govPollingService.getPercentageMkrVotedRankedChoice(); + const mkrSupply = await maker + .service('token') + .getToken(MKR) + .totalSupply(); + expect(percentage).toBe( + MKR(dummyBallotWithMajorityExpect.totalMkrParticipation) + .div(mkrSupply.toNumber()) + .times(100) + .toNumber() + ); +}); + test('ranked choice tally with majority', async () => { govQueryApiService.getMkrSupportRankedChoice = jest.fn( () => dummyBallotWithMajority @@ -175,7 +208,7 @@ test('ranked choice tally with no majority', async () => { ); }); -test.only('ranked choice tally with multiple rounds', async () => { +test('ranked choice tally with multiple rounds', async () => { govQueryApiService.getMkrSupportRankedChoice = jest.fn( () => dummyBallotMultipleRounds );