Votes.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const { expectRevert, BN } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const {
  4. shouldBehaveLikeVotes,
  5. } = require('./Votes.behavior');
  6. const Votes = artifacts.require('VotesMock');
  7. contract('Votes', function (accounts) {
  8. const [ account1, account2, account3 ] = accounts;
  9. beforeEach(async function () {
  10. this.name = 'My Vote';
  11. this.votes = await Votes.new(this.name);
  12. });
  13. it('starts with zero votes', async function () {
  14. expect(await this.votes.getTotalSupply()).to.be.bignumber.equal('0');
  15. });
  16. describe('performs voting operations', function () {
  17. beforeEach(async function () {
  18. this.tx1 = await this.votes.mint(account1, 1);
  19. this.tx2 = await this.votes.mint(account2, 1);
  20. this.tx3 = await this.votes.mint(account3, 1);
  21. });
  22. it('reverts if block number >= current block', async function () {
  23. await expectRevert(
  24. this.votes.getPastTotalSupply(this.tx3.receipt.blockNumber + 1),
  25. 'Votes: block not yet mined',
  26. );
  27. });
  28. it('delegates', async function () {
  29. await this.votes.delegate(account3, account2);
  30. expect(await this.votes.delegates(account3)).to.be.equal(account2);
  31. });
  32. it('returns total amount of votes', async function () {
  33. expect(await this.votes.getTotalSupply()).to.be.bignumber.equal('3');
  34. });
  35. });
  36. describe('performs voting workflow', function () {
  37. beforeEach(async function () {
  38. this.chainId = await this.votes.getChainId();
  39. this.account1 = account1;
  40. this.account2 = account2;
  41. this.account1Delegatee = account2;
  42. this.token0 = new BN('10000000000000000000000000');
  43. this.token1 = new BN('10');
  44. this.token2 = new BN('20');
  45. this.token3 = new BN('30');
  46. });
  47. shouldBehaveLikeVotes();
  48. });
  49. });