Votes.test.js 1.8 KB

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