ERC20Pausable.test.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const { accounts, contract } = require('@openzeppelin/test-environment');
  2. const { BN, expectRevert } = require('@openzeppelin/test-helpers');
  3. const { expect } = require('chai');
  4. const ERC20PausableMock = contract.fromArtifact('ERC20PausableMock');
  5. describe('ERC20Pausable', function () {
  6. const [ holder, recipient, anotherAccount ] = accounts;
  7. const initialSupply = new BN(100);
  8. beforeEach(async function () {
  9. this.token = await ERC20PausableMock.new(holder, initialSupply);
  10. });
  11. describe('pausable token', function () {
  12. describe('transfer', function () {
  13. it('allows to transfer when unpaused', async function () {
  14. await this.token.transfer(recipient, initialSupply, { from: holder });
  15. expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('0');
  16. expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(initialSupply);
  17. });
  18. it('allows to transfer when paused and then unpaused', async function () {
  19. await this.token.pause();
  20. await this.token.unpause();
  21. await this.token.transfer(recipient, initialSupply, { from: holder });
  22. expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('0');
  23. expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(initialSupply);
  24. });
  25. it('reverts when trying to transfer when paused', async function () {
  26. await this.token.pause();
  27. await expectRevert(this.token.transfer(recipient, initialSupply, { from: holder }),
  28. 'ERC20Pausable: token transfer while paused'
  29. );
  30. });
  31. });
  32. describe('transfer from', function () {
  33. const allowance = new BN(40);
  34. beforeEach(async function () {
  35. await this.token.approve(anotherAccount, allowance, { from: holder });
  36. });
  37. it('allows to transfer from when unpaused', async function () {
  38. await this.token.transferFrom(holder, recipient, allowance, { from: anotherAccount });
  39. expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(allowance);
  40. expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(allowance));
  41. });
  42. it('allows to transfer when paused and then unpaused', async function () {
  43. await this.token.pause();
  44. await this.token.unpause();
  45. await this.token.transferFrom(holder, recipient, allowance, { from: anotherAccount });
  46. expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(allowance);
  47. expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(allowance));
  48. });
  49. it('reverts when trying to transfer from when paused', async function () {
  50. await this.token.pause();
  51. await expectRevert(this.token.transferFrom(
  52. holder, recipient, allowance, { from: anotherAccount }), 'ERC20Pausable: token transfer while paused'
  53. );
  54. });
  55. });
  56. });
  57. });