MintableToken.behavior.js 4.8 KB

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