Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve MintableToken test coverage
  • Loading branch information
facuspagnuolo committed Jan 28, 2018
commit 435f0e1399c31fd2f4847b8808dc143de739ae91
151 changes: 122 additions & 29 deletions test/token/MintableToken.test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,137 @@
import assertRevert from '../helpers/assertRevert';
const MintableToken = artifacts.require('MintableToken');

import expectThrow from '../helpers/expectThrow';
var MintableToken = artifacts.require('MintableToken');

contract('Mintable', function (accounts) {
let token;

contract('Mintable', function ([owner, anotherAccount]) {
beforeEach(async function () {
token = await MintableToken.new();
this.token = await MintableToken.new({ from: owner });
});

it('should start with a totalSupply of 0', async function () {
let totalSupply = await token.totalSupply();
describe('minting finished', function () {
describe('when the token is not finished', function () {
it('returns false', async function () {
const mintingFinished = await this.token.mintingFinished();
assert.equal(mintingFinished, false);
});
});

describe('when the token is finished', function () {
beforeEach(async function () {
await this.token.finishMinting({ from: owner });
});

assert.equal(totalSupply, 0);
it('returns true', async function () {
const mintingFinished = await this.token.mintingFinished.call();
assert.equal(mintingFinished, true);
});
});
});

it('should return mintingFinished false after construction', async function () {
let mintingFinished = await token.mintingFinished();
describe('finish minting', function () {
describe('when the sender is the token owner', function () {
const from = owner;

assert.equal(mintingFinished, false);
});
describe('when the token was not finished', function () {
it('finishes token minting', async function () {
await this.token.finishMinting({ from });

const mintingFinished = await this.token.mintingFinished();
assert.equal(mintingFinished, true);
});

it('emits a mint finished event', async function () {
const { logs } = await this.token.finishMinting({ from });

it('should mint a given amount of tokens to a given address', async function () {
const result = await token.mint(accounts[0], 100);
assert.equal(result.logs[0].event, 'Mint');
assert.equal(result.logs[0].args.to.valueOf(), accounts[0]);
assert.equal(result.logs[0].args.amount.valueOf(), 100);
assert.equal(result.logs[1].event, 'Transfer');
assert.equal(result.logs[1].args.from.valueOf(), 0x0);
assert.equal(logs.length, 1);
assert.equal(logs[0].event, 'MintFinished');
});
});

let balance0 = await token.balanceOf(accounts[0]);
assert(balance0, 100);
describe('when the token was already finished', function () {
beforeEach(async function () {
await this.token.finishMinting({ from });
});

let totalSupply = await token.totalSupply();
assert(totalSupply, 100);
it('reverts', async function () {
await assertRevert(this.token.finishMinting({ from }));
});
});
});

describe('when the sender is not the token owner', function () {
const from = anotherAccount;

describe('when the token was not finished', function () {
it('reverts', async function () {
await assertRevert(this.token.finishMinting({ from }));
});
});

describe('when the token was already finished', function () {
beforeEach(async function () {
await this.token.finishMinting({ from: owner });
});

it('reverts', async function () {
await assertRevert(this.token.finishMinting({ from }));
});
});
});
});

it('should fail to mint after call to finishMinting', async function () {
await token.finishMinting();
assert.equal(await token.mintingFinished(), true);
await expectThrow(token.mint(accounts[0], 100));
describe('mint', function () {
const amount = 100;

describe('when the sender is the token owner', function () {
const from = owner;

describe('when the token was not finished', function () {
it('mints the requested amount', async function () {
await this.token.mint(owner, amount, { from });

const balance = await this.token.balanceOf(owner);
assert.equal(balance, amount);
});

it('emits a mint finished event', async function () {
const { logs } = await this.token.mint(owner, amount, { from });

assert.equal(logs.length, 2);
assert.equal(logs[0].event, 'Mint');
assert.equal(logs[0].args.to, owner);
assert.equal(logs[0].args.amount, amount);
assert.equal(logs[1].event, 'Transfer');
});
});

describe('when the token minting is finished', function () {
beforeEach(async function () {
await this.token.finishMinting({ from });
});

it('reverts', async function () {
await assertRevert(this.token.mint(owner, amount, { from }));
});
});
});

describe('when the sender is not the token owner', function () {
const from = anotherAccount;

describe('when the token was not finished', function () {
it('reverts', async function () {
await assertRevert(this.token.mint(owner, amount, { from }));
});
});

describe('when the token was already finished', function () {
beforeEach(async function () {
await this.token.finishMinting({ from: owner });
});

it('reverts', async function () {
await assertRevert(this.token.mint(owner, amount, { from }));
});
});
});
});
});