MintableToken.behaviour.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const { assertRevert } = require('../../helpers/assertRevert');
  2. const BigNumber = web3.BigNumber;
  3. require('chai')
  4. .use(require('chai-as-promised'))
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) {
  8. describe('as a basic mintable token', function () {
  9. describe('after token creation', function () {
  10. it('sender should be token owner', async function () {
  11. const tokenOwner = await this.token.owner({ from: owner });
  12. tokenOwner.should.equal(owner);
  13. });
  14. });
  15. describe('minting finished', function () {
  16. describe('when the token minting is not finished', function () {
  17. it('returns false', async function () {
  18. const mintingFinished = await this.token.mintingFinished();
  19. assert.equal(mintingFinished, false);
  20. });
  21. });
  22. describe('when the token is minting finished', function () {
  23. beforeEach(async function () {
  24. await this.token.finishMinting({ from: owner });
  25. });
  26. it('returns true', async function () {
  27. const mintingFinished = await this.token.mintingFinished();
  28. assert.equal(mintingFinished, true);
  29. });
  30. });
  31. });
  32. describe('finish minting', function () {
  33. describe('when the sender is the token owner', function () {
  34. const from = owner;
  35. describe('when the token minting was not finished', function () {
  36. it('finishes token minting', async function () {
  37. await this.token.finishMinting({ from });
  38. const mintingFinished = await this.token.mintingFinished();
  39. assert.equal(mintingFinished, true);
  40. });
  41. it('emits a mint finished event', async function () {
  42. const { logs } = await this.token.finishMinting({ from });
  43. assert.equal(logs.length, 1);
  44. assert.equal(logs[0].event, 'MintFinished');
  45. });
  46. });
  47. describe('when the token minting was already finished', function () {
  48. beforeEach(async function () {
  49. await this.token.finishMinting({ from });
  50. });
  51. it('reverts', async function () {
  52. await assertRevert(this.token.finishMinting({ from }));
  53. });
  54. });
  55. });
  56. describe('when the sender is not the token owner', function () {
  57. const from = anotherAccount;
  58. describe('when the token minting was not finished', function () {
  59. it('reverts', async function () {
  60. await assertRevert(this.token.finishMinting({ from }));
  61. });
  62. });
  63. describe('when the token minting was already finished', function () {
  64. beforeEach(async function () {
  65. await this.token.finishMinting({ from: owner });
  66. });
  67. it('reverts', async function () {
  68. await assertRevert(this.token.finishMinting({ from }));
  69. });
  70. });
  71. });
  72. });
  73. describe('mint', function () {
  74. const amount = 100;
  75. describe('when the sender has the minting permission', function () {
  76. const from = minter;
  77. describe('when the token minting is not finished', function () {
  78. it('mints the requested amount', async function () {
  79. await this.token.mint(owner, amount, { from });
  80. const balance = await this.token.balanceOf(owner);
  81. assert.equal(balance, amount);
  82. });
  83. it('emits a mint and a transfer event', async function () {
  84. const { logs } = await this.token.mint(owner, amount, { from });
  85. assert.equal(logs.length, 2);
  86. assert.equal(logs[0].event, 'Mint');
  87. assert.equal(logs[0].args.to, owner);
  88. assert.equal(logs[0].args.amount, amount);
  89. assert.equal(logs[1].event, 'Transfer');
  90. });
  91. });
  92. describe('when the token minting is finished', function () {
  93. beforeEach(async function () {
  94. await this.token.finishMinting({ from: owner });
  95. });
  96. it('reverts', async function () {
  97. await assertRevert(this.token.mint(owner, amount, { from }));
  98. });
  99. });
  100. });
  101. describe('when the sender has not the minting permission', function () {
  102. const from = anotherAccount;
  103. describe('when the token minting is not finished', function () {
  104. it('reverts', async function () {
  105. await assertRevert(this.token.mint(owner, amount, { from }));
  106. });
  107. });
  108. describe('when the token minting is already finished', function () {
  109. beforeEach(async function () {
  110. await this.token.finishMinting({ from: owner });
  111. });
  112. it('reverts', async function () {
  113. await assertRevert(this.token.mint(owner, amount, { from }));
  114. });
  115. });
  116. });
  117. });
  118. });
  119. }
  120. module.exports = {
  121. shouldBehaveLikeMintableToken,
  122. };