Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b-pmcg committed Oct 12, 2021
1 parent a5044b3 commit e027a43
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/dai-plugin-governance/src/GovPollingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {});
Expand Down
63 changes: 24 additions & 39 deletions packages/dai-plugin-governance/test/GovPollingService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
dummyBallotDontMoveToEliminated,
dummyBallotDontMoveToEliminatedExpect,
dummyBallotStopWhenOneRemains,
dummyBallotStopWhenOneRemainsExpect
dummyBallotStopWhenOneRemainsExpect,
dummyMkrGetMkrSupportRCForPluralityData,
dummyMkrGetMkrSupportRCForPluralityDataAdjusted
} from './fixtures';
import { MKR } from '../src/utils/constants';

Expand Down Expand Up @@ -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
}
}
Expand All @@ -355,49 +359,30 @@ 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
}));
const tally = await govPollingService.getTallyPlurality();

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
}
}
};
Expand Down
53 changes: 53 additions & 0 deletions packages/dai-plugin-governance/test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e027a43

Please sign in to comment.