GovernorComp.test.js 3.9 KB

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