MintableToken.test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import assertRevert from '../../helpers/assertRevert';
  2. const MintableToken = artifacts.require('MintableToken');
  3. contract('Mintable', function ([owner, anotherAccount]) {
  4. beforeEach(async function () {
  5. this.token = await MintableToken.new({ from: owner });
  6. });
  7. describe('minting finished', function () {
  8. describe('when the token is not finished', function () {
  9. it('returns false', async function () {
  10. const mintingFinished = await this.token.mintingFinished();
  11. assert.equal(mintingFinished, false);
  12. });
  13. });
  14. describe('when the token is finished', function () {
  15. beforeEach(async function () {
  16. await this.token.finishMinting({ from: owner });
  17. });
  18. it('returns true', async function () {
  19. const mintingFinished = await this.token.mintingFinished.call();
  20. assert.equal(mintingFinished, true);
  21. });
  22. });
  23. });
  24. describe('finish minting', function () {
  25. describe('when the sender is the token owner', function () {
  26. const from = owner;
  27. describe('when the token was not finished', function () {
  28. it('finishes token minting', async function () {
  29. await this.token.finishMinting({ from });
  30. const mintingFinished = await this.token.mintingFinished();
  31. assert.equal(mintingFinished, true);
  32. });
  33. it('emits a mint finished event', async function () {
  34. const { logs } = await this.token.finishMinting({ from });
  35. assert.equal(logs.length, 1);
  36. assert.equal(logs[0].event, 'MintFinished');
  37. });
  38. });
  39. describe('when the token was already finished', function () {
  40. beforeEach(async function () {
  41. await this.token.finishMinting({ from });
  42. });
  43. it('reverts', async function () {
  44. await assertRevert(this.token.finishMinting({ from }));
  45. });
  46. });
  47. });
  48. describe('when the sender is not the token owner', function () {
  49. const from = anotherAccount;
  50. describe('when the token was not finished', function () {
  51. it('reverts', async function () {
  52. await assertRevert(this.token.finishMinting({ from }));
  53. });
  54. });
  55. describe('when the token was already finished', function () {
  56. beforeEach(async function () {
  57. await this.token.finishMinting({ from: owner });
  58. });
  59. it('reverts', async function () {
  60. await assertRevert(this.token.finishMinting({ from }));
  61. });
  62. });
  63. });
  64. });
  65. describe('mint', function () {
  66. const amount = 100;
  67. describe('when the sender is the token owner', function () {
  68. const from = owner;
  69. describe('when the token was not finished', function () {
  70. it('mints the requested amount', async function () {
  71. await this.token.mint(owner, amount, { from });
  72. const balance = await this.token.balanceOf(owner);
  73. assert.equal(balance, amount);
  74. });
  75. it('emits a mint finished event', async function () {
  76. const { logs } = await this.token.mint(owner, amount, { from });
  77. assert.equal(logs.length, 2);
  78. assert.equal(logs[0].event, 'Mint');
  79. assert.equal(logs[0].args.to, owner);
  80. assert.equal(logs[0].args.amount, amount);
  81. assert.equal(logs[1].event, 'Transfer');
  82. });
  83. });
  84. describe('when the token minting is finished', function () {
  85. beforeEach(async function () {
  86. await this.token.finishMinting({ from });
  87. });
  88. it('reverts', async function () {
  89. await assertRevert(this.token.mint(owner, amount, { from }));
  90. });
  91. });
  92. });
  93. describe('when the sender is not the token owner', function () {
  94. const from = anotherAccount;
  95. describe('when the token was not finished', function () {
  96. it('reverts', async function () {
  97. await assertRevert(this.token.mint(owner, amount, { from }));
  98. });
  99. });
  100. describe('when the token was already finished', function () {
  101. beforeEach(async function () {
  102. await this.token.finishMinting({ from: owner });
  103. });
  104. it('reverts', async function () {
  105. await assertRevert(this.token.mint(owner, amount, { from }));
  106. });
  107. });
  108. });
  109. });
  110. });