@@ -3,7 +3,7 @@ import { BigNumber } from '@ethersproject/bignumber';
33import { parseUnits } from '@ethersproject/units' ;
44import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' ;
55import { ZERO_ADDRESS } from '../lib/constants' ;
6- import { BallotTagManager , DeepSquare , ExposedBallot , ExposedBallot__factory , ExposedVotingProxy } from '../typings' ;
6+ import { DeepSquare , ExposedBallot , ExposedBallot__factory , VotingDelegation } from '../typings' ;
77import { ERC20Agent } from './testing/ERC20Agent' ;
88import setup from './testing/setup' ;
99import setupVoting from './testing/setupVoting' ;
@@ -14,51 +14,49 @@ describe('Ballot', () => {
1414 let DPS : DeepSquare ;
1515 let ballot : ExposedBallot ;
1616 let agentDPS : ERC20Agent ;
17- let ballotTagManager : BallotTagManager ;
18- let votingProxy : ExposedVotingProxy ;
17+ let votingDelegation : VotingDelegation ;
1918
2019 beforeEach ( async ( ) => {
2120 ( { owner, accounts, DPS , agentDPS } = await setup ( ) ) ;
22- ( { ballotTagManager , votingProxy } = await setupVoting ( owner , DPS ) ) ;
21+ ( { votingDelegation } = await setupVoting ( owner , DPS ) ) ;
2322
24- ballot = await new ExposedBallot__factory ( owner ) . deploy ( DPS . address , votingProxy . address ) ;
23+ ballot = await new ExposedBallot__factory ( owner ) . deploy ( DPS . address , votingDelegation . address ) ;
2524 } ) ;
2625
2726 describe ( 'constructor' , ( ) => {
2827 it ( 'should revert if the DPS contract is the zero address' , async ( ) => {
29- await expect ( new ExposedBallot__factory ( owner ) . deploy ( ZERO_ADDRESS , votingProxy . address ) ) . to . be . revertedWith (
28+ await expect ( new ExposedBallot__factory ( owner ) . deploy ( ZERO_ADDRESS , votingDelegation . address ) ) . to . be . revertedWith (
3029 'Vote: DPS address is zero.' ,
3130 ) ;
3231 } ) ;
3332 } ) ;
3433
3534 describe ( 'init' , ( ) => {
3635 it ( 'should initialize ballot state variables' , async ( ) => {
37- await ballot . init ( 'foo' , BigNumber . from ( 0 ) , [ 'bar ' , 'baz ' ] ) ;
36+ await ballot . init ( 'foo' , 'bar' , [ 'baz ' , 'qux ' ] ) ;
3837 expect ( await ballot . subject ( ) ) . to . equals ( 'foo' ) ;
39- expect ( await ballot . tagIndex ( ) ) . to . equals ( BigNumber . from ( 0 ) ) ;
40- expect ( await ballot . getChoices ( ) ) . to . deep . equals ( [ 'bar ' , 'baz ' ] ) ;
38+ expect ( await ballot . topic ( ) ) . to . equals ( 'bar' ) ;
39+ expect ( await ballot . getChoices ( ) ) . to . deep . equals ( [ 'baz ' , 'qux ' ] ) ;
4140 expect ( await ballot . getResults ( ) ) . to . deep . equals ( [ BigNumber . from ( 0 ) , BigNumber . from ( 0 ) ] ) ;
4241 } ) ;
4342 } ) ;
4443
4544 describe ( 'vote' , ( ) => {
4645 beforeEach ( async ( ) => {
47- await ballotTagManager . addTag ( 'foo' ) ;
48- await ballot . init ( 'foo' , BigNumber . from ( 0 ) , [ 'bar' , 'baz' ] ) ;
46+ await ballot . init ( 'foo' , 'qux' , [ 'bar' , 'baz' ] ) ;
4947 } ) ;
5048 it ( 'should throw if ballot is closed' , async ( ) => {
51- await ballot . closeBallot ( ) ;
49+ await ballot . close ( ) ;
5250 await expect ( ballot . connect ( accounts [ 0 ] ) . vote ( BigNumber . from ( 0 ) ) ) . to . revertedWith ( 'Voting: Ballot is closed.' ) ;
5351 } ) ;
5452 it ( 'should throw if proposal does not exist' , async ( ) => {
5553 await expect ( ballot . connect ( accounts [ 0 ] ) . vote ( BigNumber . from ( 2 ) ) ) . to . revertedWith (
5654 'Voting: Choice index is too high.' ,
5755 ) ;
5856 } ) ;
59- it ( 'should throw if voter has granted proxy on the tag ' , async ( ) => {
57+ it ( 'should throw if voter has granted proxy on the topic ' , async ( ) => {
6058 await agentDPS . transfer ( accounts [ 1 ] , 25000 , 18 ) ;
61- await votingProxy . connect ( accounts [ 0 ] ) . grantProxy ( accounts [ 1 ] . address , BigNumber . from ( 0 ) ) ;
59+ await votingDelegation . connect ( accounts [ 0 ] ) . delegate ( accounts [ 1 ] . address , 'qux' ) ;
6260 await expect ( ballot . connect ( accounts [ 0 ] ) . vote ( BigNumber . from ( 0 ) ) ) . to . revertedWith ( 'Voting: Vote is delegated.' ) ;
6361 } ) ;
6462 it ( 'should throw if voter has less than 25k DPS' , async ( ) => {
@@ -77,21 +75,20 @@ describe('Ballot', () => {
7775
7876 describe ( 'closeBallot' , async ( ) => {
7977 beforeEach ( async ( ) => {
80- await ballotTagManager . addTag ( 'foo' ) ;
81- await ballot . init ( 'foo' , BigNumber . from ( 0 ) , [ 'bar' , 'baz' ] ) ;
78+ await ballot . init ( 'foo' , 'qux' , [ 'bar' , 'baz' ] ) ;
8279 } ) ;
8380 it ( 'should throw if ballot is not closed' , async ( ) => {
84- await ballot . closeBallot ( ) ;
85- await expect ( ballot . closeBallot ( ) ) . to . revertedWith ( 'Voting: Ballot already closed.' ) ;
81+ await ballot . close ( ) ;
82+ await expect ( ballot . close ( ) ) . to . revertedWith ( 'Voting: Ballot already closed.' ) ;
8683 } ) ;
8784 it ( 'should show results' , async ( ) => {
8885 await agentDPS . transfer ( accounts [ 0 ] , 25000 , 18 ) ;
8986 await agentDPS . transfer ( accounts [ 1 ] , 25000 , 18 ) ;
9087 await agentDPS . transfer ( accounts [ 2 ] , 25000 , 18 ) ;
91- await votingProxy . connect ( accounts [ 2 ] ) . grantProxy ( accounts [ 1 ] . address , BigNumber . from ( 0 ) ) ;
88+ await votingDelegation . connect ( accounts [ 2 ] ) . delegate ( accounts [ 1 ] . address , 'qux' ) ;
9289 await ballot . connect ( accounts [ 0 ] ) . vote ( BigNumber . from ( 0 ) ) ;
9390 await ballot . connect ( accounts [ 1 ] ) . vote ( BigNumber . from ( 1 ) ) ;
94- await ballot . closeBallot ( ) ;
91+ await ballot . close ( ) ;
9592 expect ( await ballot . getResults ( ) ) . to . deep . equals ( [ parseUnits ( '25000' , 18 ) , parseUnits ( '50000' , 18 ) ] ) ;
9693 } ) ;
9794 } ) ;
0 commit comments