Improve ERC20s tests coverage (#712)

* Improve StandardToken tests coverage
* Improve BasicToken test coverage
* Improve MintableToken test coverage
* Improve BurnableToken test coverage
* Improve PausableToken tests coverage
This commit is contained in:
Facundo Spagnuolo
2018-02-08 14:34:31 -03:00
committed by GitHub
parent 7a0bfdfbb4
commit 6ad275befb
5 changed files with 918 additions and 207 deletions

View File

@ -1,33 +1,82 @@
import assertRevert from '../helpers/assertRevert';
const BasicToken = artifacts.require('BasicTokenMock');
var BasicTokenMock = artifacts.require('BasicTokenMock');
contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
contract('BasicToken', function (accounts) {
it('should return the correct totalSupply after construction', async function () {
let token = await BasicTokenMock.new(accounts[0], 100);
let totalSupply = await token.totalSupply();
assert.equal(totalSupply, 100);
beforeEach(async function () {
this.token = await BasicToken.new(owner, 100);
});
it('should return correct balances after transfer', async function () {
let token = await BasicTokenMock.new(accounts[0], 100);
await token.transfer(accounts[1], 100);
describe('total supply', function () {
it('returns the total amount of tokens', async function () {
const totalSupply = await this.token.totalSupply();
let firstAccountBalance = await token.balanceOf(accounts[0]);
assert.equal(firstAccountBalance, 0);
let secondAccountBalance = await token.balanceOf(accounts[1]);
assert.equal(secondAccountBalance, 100);
assert.equal(totalSupply, 100);
});
});
it('should throw an error when trying to transfer more than balance', async function () {
let token = await BasicTokenMock.new(accounts[0], 100);
await assertRevert(token.transfer(accounts[1], 101));
describe('balanceOf', function () {
describe('when the requested account has no tokens', function () {
it('returns zero', async function () {
const balance = await this.token.balanceOf(anotherAccount);
assert.equal(balance, 0);
});
});
describe('when the requested account has some tokens', function () {
it('returns the total amount of tokens', async function () {
const balance = await this.token.balanceOf(owner);
assert.equal(balance, 100);
});
});
});
it('should throw an error when trying to transfer to 0x0', async function () {
let token = await BasicTokenMock.new(accounts[0], 100);
await assertRevert(token.transfer(0x0, 100));
describe('transfer', function () {
describe('when the recipient is not the zero address', function () {
const to = recipient;
describe('when the sender does not have enough balance', function () {
const amount = 101;
it('reverts', async function () {
await assertRevert(this.token.transfer(to, amount, { from: owner }));
});
});
describe('when the sender has enough balance', function () {
const amount = 100;
it('transfers the requested amount', async function () {
await this.token.transfer(to, amount, { from: owner });
const senderBalance = await this.token.balanceOf(owner);
assert.equal(senderBalance, 0);
const recipientBalance = await this.token.balanceOf(to);
assert.equal(recipientBalance, amount);
});
it('emits a transfer event', async function () {
const { logs } = await this.token.transfer(to, amount, { from: owner });
assert.equal(logs.length, 1);
assert.equal(logs[0].event, 'Transfer');
assert.equal(logs[0].args.from, owner);
assert.equal(logs[0].args.to, to);
assert(logs[0].args.value.eq(amount));
});
});
});
describe('when the recipient is the zero address', function () {
const to = ZERO_ADDRESS;
it('reverts', async function () {
await assertRevert(this.token.transfer(to, 100, { from: owner }));
});
});
});
});