-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Improve ERC20 tests coverage #712
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
Merged
facuspagnuolo
merged 6 commits into
OpenZeppelin:master
from
facuspagnuolo:enhancement/provide_more_erc20_tests
Feb 8, 2018
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0945c82
Improve BasicToken test coverage
facuspagnuolo 0d6cab9
Improve StandardToken tests coverage
facuspagnuolo 435f0e1
Improve MintableToken test coverage
facuspagnuolo 966ed26
Improve BurnableToken test coverage
facuspagnuolo 94fc8ed
Improve PausableToken tests coverage
facuspagnuolo 55dbe13
Fix typo
facuspagnuolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Improve BasicToken test coverage
- Loading branch information
commit 0945c8206dd6f8bfcb7da89ed6504b54d323a26e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| beforeEach(async function () { | ||
| this.token = await BasicToken.new(owner, 100); | ||
| }); | ||
|
|
||
| describe('total supply', function () { | ||
| it('returns the total amount of tokens', async function () { | ||
| const totalSupply = await this.token.totalSupply(); | ||
|
|
||
| assert.equal(totalSupply, 100); | ||
| assert.equal(totalSupply, 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('balanceOf', function () { | ||
| describe('when the requested account has no tokens', function () { | ||
| it('returns zero', async function () { | ||
| const balance = await this.token.balanceOf(anotherAccount); | ||
|
|
||
| let firstAccountBalance = await token.balanceOf(accounts[0]); | ||
| assert.equal(firstAccountBalance, 0); | ||
| assert.equal(balance, 0); | ||
| }); | ||
| }); | ||
|
|
||
| let secondAccountBalance = await token.balanceOf(accounts[1]); | ||
| assert.equal(secondAccountBalance, 100); | ||
| }); | ||
| 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); | ||
|
|
||
| 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)); | ||
| 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('transfer 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 })); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should be
transfersinstead oftransferThere 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.
nice catch! thx @gertjanleemans