Added mint and burn tests for zero amounts. (#1230)

This commit is contained in:
Nicolás Venturo
2018-08-23 06:07:34 -03:00
committed by GitHub
parent 2adb491637
commit d58fac8281
2 changed files with 87 additions and 59 deletions

View File

@ -11,8 +11,15 @@ require('chai')
function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) { function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
describe('burn', function () { describe('burn', function () {
describe('when the given amount is not greater than balance of the sender', function () { describe('when the given amount is not greater than balance of the sender', function () {
const amount = 100; context('for a zero amount', function () {
shouldBurn(0);
});
context('for a non-zero amount', function () {
shouldBurn(100);
});
function shouldBurn (amount) {
beforeEach(async function () { beforeEach(async function () {
({ logs: this.logs } = await this.token.burn(amount, { from: owner })); ({ logs: this.logs } = await this.token.burn(amount, { from: owner }));
}); });
@ -33,6 +40,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
event.args.to.should.eq(ZERO_ADDRESS); event.args.to.should.eq(ZERO_ADDRESS);
event.args.value.should.be.bignumber.equal(amount); event.args.value.should.be.bignumber.equal(amount);
}); });
}
}); });
describe('when the given amount is greater than the balance of the sender', function () { describe('when the given amount is greater than the balance of the sender', function () {
@ -46,10 +54,19 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
describe('burnFrom', function () { describe('burnFrom', function () {
describe('on success', function () { describe('on success', function () {
const amount = 100; context('for a zero amount', function () {
shouldBurnFrom(0);
});
context('for a non-zero amount', function () {
shouldBurnFrom(100);
});
function shouldBurnFrom (amount) {
const originalAllowance = amount * 3;
beforeEach(async function () { beforeEach(async function () {
await this.token.approve(burner, 300, { from: owner }); await this.token.approve(burner, originalAllowance, { from: owner });
const { logs } = await this.token.burnFrom(owner, amount, { from: burner }); const { logs } = await this.token.burnFrom(owner, amount, { from: burner });
this.logs = logs; this.logs = logs;
}); });
@ -59,7 +76,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
}); });
it('decrements allowance', async function () { it('decrements allowance', async function () {
(await this.token.allowance(owner, burner)).should.be.bignumber.equal(200); (await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance - amount);
}); });
it('emits a burn event', async function () { it('emits a burn event', async function () {
@ -74,6 +91,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
event.args.to.should.eq(ZERO_ADDRESS); event.args.to.should.eq(ZERO_ADDRESS);
event.args.value.should.be.bignumber.equal(amount); event.args.value.should.be.bignumber.equal(amount);
}); });
}
}); });
describe('when the given amount is greater than the balance of the sender', function () { describe('when the given amount is greater than the balance of the sender', function () {

View File

@ -93,26 +93,36 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
const from = minter; const from = minter;
describe('when the token minting is not finished', function () { describe('when the token minting is not finished', function () {
it('mints the requested amount', async function () { context('for a zero amount', function () {
await this.token.mint(owner, amount, { from }); shouldMint(0);
});
(await this.token.balanceOf(owner)).should.be.bignumber.equal(amount); context('for a non-zero amount', function () {
shouldMint(amount);
});
function shouldMint (amount) {
beforeEach(async function () {
({ logs: this.logs } = await this.token.mint(anyone, amount, { from }));
});
it('mints the requested amount', async function () {
(await this.token.balanceOf(anyone)).should.be.bignumber.equal(amount);
}); });
it('emits a mint and a transfer event', async function () { it('emits a mint and a transfer event', async function () {
const { logs } = await this.token.mint(owner, amount, { from }); const mintEvent = expectEvent.inLogs(this.logs, 'Mint', {
to: anyone,
const mintEvent = expectEvent.inLogs(logs, 'Mint', {
to: owner,
}); });
mintEvent.args.amount.should.be.bignumber.equal(amount); mintEvent.args.amount.should.be.bignumber.equal(amount);
const transferEvent = expectEvent.inLogs(logs, 'Transfer', { const transferEvent = expectEvent.inLogs(this.logs, 'Transfer', {
from: ZERO_ADDRESS, from: ZERO_ADDRESS,
to: owner, to: anyone,
}); });
transferEvent.args.value.should.be.bignumber.equal(amount); transferEvent.args.value.should.be.bignumber.equal(amount);
}); });
}
}); });
describe('when the token minting is finished', function () { describe('when the token minting is finished', function () {
@ -121,7 +131,7 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
}); });
it('reverts', async function () { it('reverts', async function () {
await assertRevert(this.token.mint(owner, amount, { from })); await assertRevert(this.token.mint(anyone, amount, { from }));
}); });
}); });
}); });
@ -131,7 +141,7 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
describe('when the token minting is not finished', function () { describe('when the token minting is not finished', function () {
it('reverts', async function () { it('reverts', async function () {
await assertRevert(this.token.mint(owner, amount, { from })); await assertRevert(this.token.mint(anyone, amount, { from }));
}); });
}); });
@ -141,7 +151,7 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
}); });
it('reverts', async function () { it('reverts', async function () {
await assertRevert(this.token.mint(owner, amount, { from })); await assertRevert(this.token.mint(anyone, amount, { from }));
}); });
}); });
}); });