Files
openzeppelin-contracts/test/token/ERC20/behaviors/ERC20Burnable.behavior.js
Nicolás Venturo 3e82db2f6f Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)
* Now compiling using truffle 5.

* Migrated some test files, missing BN scientific notation usage.

* Now using BN time values.

* Migrate ERC20 tests.

* Migrate all ERC20 tests.

* Migrate utils, payment and ownership tests.

* All tests save ERC721 migrated.

* Migrated ERC721 tests.

* Fix lint errors.

* Delete old test helpers.

* Fix remaining crowdsale tests.

* Fix signature bouncer tests.

* Update how constants is used.

* Compile script pre-removes the build dir.

* Fix SafeMath tests.

* Revert "Compile script pre-removes the build dir."

This reverts commit 247e745113.

* Fix linter errors.

* Upgrade openzeppelin-test-helpers dependency.

* Update openzeppelin-test-helpers dependency.

* Define math constants globally.

* Remove unnecessary ether unit.

* Roll back reduced ether amounts in tests.

* Remove unnecessary toNumber conversions.

* Delete compile script.

* Fixed failing test.
2019-01-14 19:11:55 -03:00

103 lines
3.3 KiB
JavaScript

const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
describe('burn', function () {
describe('when the given amount is not greater than balance of the sender', function () {
context('for a zero amount', function () {
shouldBurn(new BN(0));
});
context('for a non-zero amount', function () {
shouldBurn(new BN(100));
});
function shouldBurn (amount) {
beforeEach(async function () {
({ logs: this.logs } = await this.token.burn(amount, { from: owner }));
});
it('burns the requested amount', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
});
it('emits a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
value: amount,
});
});
}
});
describe('when the given amount is greater than the balance of the sender', function () {
const amount = initialBalance.addn(1);
it('reverts', async function () {
await shouldFail.reverting(this.token.burn(amount, { from: owner }));
});
});
});
describe('burnFrom', function () {
describe('on success', function () {
context('for a zero amount', function () {
shouldBurnFrom(new BN(0));
});
context('for a non-zero amount', function () {
shouldBurnFrom(new BN(100));
});
function shouldBurnFrom (amount) {
const originalAllowance = amount.muln(3);
beforeEach(async function () {
await this.token.approve(burner, originalAllowance, { from: owner });
const { logs } = await this.token.burnFrom(owner, amount, { from: burner });
this.logs = logs;
});
it('burns the requested amount', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
});
it('decrements allowance', async function () {
(await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance.sub(amount));
});
it('emits a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
value: amount,
});
});
}
});
describe('when the given amount is greater than the balance of the sender', function () {
const amount = initialBalance.addn(1);
it('reverts', async function () {
await this.token.approve(burner, amount, { from: owner });
await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
});
});
describe('when the given amount is greater than the allowance', function () {
const allowance = new BN(100);
it('reverts', async function () {
await this.token.approve(burner, allowance, { from: owner });
await shouldFail.reverting(this.token.burnFrom(owner, allowance.addn(1), { from: burner }));
});
});
});
}
module.exports = {
shouldBehaveLikeERC20Burnable,
};