Votes.test.js 1.8 KB

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