GovernorComp.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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('$ERC20VotesComp');
  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, tokenName);
  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. {
  34. target: this.receiver.address,
  35. value,
  36. data: this.receiver.contract.methods.mockFunction().encodeABI(),
  37. },
  38. ],
  39. '<proposal description>',
  40. );
  41. });
  42. it('deployment check', async function () {
  43. expect(await this.mock.name()).to.be.equal(name);
  44. expect(await this.mock.token()).to.be.equal(this.token.address);
  45. expect(await this.mock.votingDelay()).to.be.bignumber.equal(votingDelay);
  46. expect(await this.mock.votingPeriod()).to.be.bignumber.equal(votingPeriod);
  47. expect(await this.mock.quorum(0)).to.be.bignumber.equal('0');
  48. });
  49. it('voting with comp token', async function () {
  50. await this.helper.propose();
  51. await this.helper.waitForSnapshot();
  52. await this.helper.vote({ support: Enums.VoteType.For }, { from: voter1 });
  53. await this.helper.vote({ support: Enums.VoteType.For }, { from: voter2 });
  54. await this.helper.vote({ support: Enums.VoteType.Against }, { from: voter3 });
  55. await this.helper.vote({ support: Enums.VoteType.Abstain }, { from: voter4 });
  56. await this.helper.waitForDeadline();
  57. await this.helper.execute();
  58. expect(await this.mock.hasVoted(this.proposal.id, owner)).to.be.equal(false);
  59. expect(await this.mock.hasVoted(this.proposal.id, voter1)).to.be.equal(true);
  60. expect(await this.mock.hasVoted(this.proposal.id, voter2)).to.be.equal(true);
  61. expect(await this.mock.hasVoted(this.proposal.id, voter3)).to.be.equal(true);
  62. expect(await this.mock.hasVoted(this.proposal.id, voter4)).to.be.equal(true);
  63. await this.mock.proposalVotes(this.proposal.id).then(results => {
  64. expect(results.forVotes).to.be.bignumber.equal(web3.utils.toWei('17'));
  65. expect(results.againstVotes).to.be.bignumber.equal(web3.utils.toWei('5'));
  66. expect(results.abstainVotes).to.be.bignumber.equal(web3.utils.toWei('2'));
  67. });
  68. });
  69. });