-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Added mint and burn tests for zero amounts. #1230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,28 +11,36 @@ require('chai') | |
| function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) { | ||
| describe('burn', function () { | ||
| describe('when the given amount is not greater than balance of the sender', function () { | ||
| const amount = 100; | ||
|
|
||
| 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 - amount); | ||
| context('for a zero amount', function () { | ||
| shouldBurn(0); | ||
| }); | ||
|
|
||
| it('emits a burn event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Burn'); | ||
| event.args.burner.should.eq(owner); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| context('for a non-zero amount', function () { | ||
| shouldBurn(100); | ||
| }); | ||
|
|
||
| it('emits a transfer event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Transfer'); | ||
| event.args.from.should.eq(owner); | ||
| event.args.to.should.eq(ZERO_ADDRESS); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
| 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 - amount); | ||
| }); | ||
|
|
||
| it('emits a burn event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Burn'); | ||
| event.args.burner.should.eq(owner); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
|
|
||
| it('emits a transfer event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Transfer'); | ||
| event.args.from.should.eq(owner); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these equals checks should be in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come #1219 didn't cover that? 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| event.args.to.should.eq(ZERO_ADDRESS); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| describe('when the given amount is greater than the balance of the sender', function () { | ||
|
|
@@ -46,34 +54,44 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) { | |
|
|
||
| describe('burnFrom', function () { | ||
| describe('on success', function () { | ||
| const amount = 100; | ||
|
|
||
| beforeEach(async function () { | ||
| await this.token.approve(burner, 300, { 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 - amount); | ||
| context('for a zero amount', function () { | ||
| shouldBurnFrom(0); | ||
| }); | ||
|
|
||
| it('decrements allowance', async function () { | ||
| (await this.token.allowance(owner, burner)).should.be.bignumber.equal(200); | ||
| context('for a non-zero amount', function () { | ||
| shouldBurnFrom(100); | ||
| }); | ||
|
|
||
| it('emits a burn event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Burn'); | ||
| event.args.burner.should.eq(owner); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
|
|
||
| it('emits a transfer event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Transfer'); | ||
| event.args.from.should.eq(owner); | ||
| event.args.to.should.eq(ZERO_ADDRESS); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
| function shouldBurnFrom (amount) { | ||
| const originalAllowance = amount * 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 - amount); | ||
| }); | ||
|
|
||
| it('decrements allowance', async function () { | ||
| (await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance - amount); | ||
| }); | ||
|
|
||
| it('emits a burn event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Burn'); | ||
| event.args.burner.should.eq(owner); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
|
|
||
| it('emits a transfer event', async function () { | ||
| const event = expectEvent.inLogs(this.logs, 'Transfer'); | ||
| event.args.from.should.eq(owner); | ||
| event.args.to.should.eq(ZERO_ADDRESS); | ||
| event.args.value.should.be.bignumber.equal(amount); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| describe('when the given amount is greater than the balance of the sender', function () { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
this.logsworks? amazingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I copied it over from the Burnable tests