GovernorComp.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const { BN } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const Enums = require('../../helpers/enums');
  4. const { GovernorHelper } = require('../../helpers/governance');
  5. const Token = artifacts.require('ERC20VotesCompMock');
  6. const Governor = artifacts.require('GovernorCompMock');
  7. const CallReceiver = artifacts.require('CallReceiverMock');
  8. contract('GovernorComp', function (accounts) {
  9. const [ owner, voter1, voter2, voter3, voter4 ] = accounts;
  10. const name = 'OZ-Governor';
  11. // const version = '1';
  12. const tokenName = 'MockToken';
  13. const tokenSymbol = 'MTKN';
  14. const tokenSupply = web3.utils.toWei('100');
  15. const votingDelay = new BN(4);
  16. const votingPeriod = new BN(16);
  17. const value = web3.utils.toWei('1');
  18. beforeEach(async function () {
  19. this.owner = owner;
  20. this.token = await Token.new(tokenName, tokenSymbol);
  21. this.mock = await Governor.new(name, this.token.address);
  22. this.receiver = await CallReceiver.new();
  23. this.helper = new GovernorHelper(this.mock);
  24. await web3.eth.sendTransaction({ from: owner, to: this.mock.address, value });
  25. await this.token.mint(owner, tokenSupply);
  26. await this.helper.delegate({ token: this.token, to: voter1, value: web3.utils.toWei('10') }, { from: owner });
  27. await this.helper.delegate({ token: this.token, to: voter2, value: web3.utils.toWei('7') }, { from: owner });
  28. await this.helper.delegate({ token: this.token, to: voter3, value: web3.utils.toWei('5') }, { from: owner });
  29. await this.helper.delegate({ token: this.token, to: voter4, value: web3.utils.toWei('2') }, { from: owner });
  30. // default proposal
  31. this.proposal = this.helper.setProposal([
  32. {
  33. target: this.receiver.address,
  34. value,
  35. data: this.receiver.contract.methods.mockFunction().encodeABI(),
  36. },
  37. ], '<proposal description>');
  38. });
  39. it('deployment check', async function () {
  40. expect(await this.mock.name()).to.be.equal(name);
  41. expect(await this.mock.token()).to.be.equal(this.token.address);
  42. expect(await this.mock.votingDelay()).to.be.bignumber.equal(votingDelay);
  43. expect(await this.mock.votingPeriod()).to.be.bignumber.equal(votingPeriod);
  44. expect(await this.mock.quorum(0)).to.be.bignumber.equal('0');
  45. });
  46. it('voting with comp token', async function () {
  47. await this.helper.propose();
  48. await this.helper.waitForSnapshot();
  49. await this.helper.vote({ support: Enums.VoteType.For }, { from: voter1 });
  50. await this.helper.vote({ support: Enums.VoteType.For }, { from: voter2 });
  51. await this.helper.vote({ support: Enums.VoteType.Against }, { from: voter3 });
  52. await this.helper.vote({ support: Enums.VoteType.Abstain }, { from: voter4 });
  53. await this.helper.waitForDeadline();
  54. await this.helper.execute();
  55. expect(await this.mock.hasVoted(this.proposal.id, owner)).to.be.equal(false);
  56. expect(await this.mock.hasVoted(this.proposal.id, voter1)).to.be.equal(true);
  57. expect(await this.mock.hasVoted(this.proposal.id, voter2)).to.be.equal(true);
  58. expect(await this.mock.hasVoted(this.proposal.id, voter3)).to.be.equal(true);
  59. expect(await this.mock.hasVoted(this.proposal.id, voter4)).to.be.equal(true);
  60. await this.mock.proposalVotes(this.proposal.id).then(results => {
  61. expect(results.forVotes).to.be.bignumber.equal(web3.utils.toWei('17'));
  62. expect(results.againstVotes).to.be.bignumber.equal(web3.utils.toWei('5'));
  63. expect(results.abstainVotes).to.be.bignumber.equal(web3.utils.toWei('2'));
  64. });
  65. });
  66. });