Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
d58fac82
Unverified
Commit
d58fac82
authored
Aug 23, 2018
by
Nicolás Venturo
Committed by
GitHub
Aug 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mint and burn tests for zero amounts. (#1230)
parent
2adb4916
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
58 deletions
+86
-58
BurnableToken.behavior.js
test/token/ERC20/BurnableToken.behavior.js
+60
-42
MintableToken.behavior.js
test/token/ERC20/MintableToken.behavior.js
+26
-16
No files found.
test/token/ERC20/BurnableToken.behavior.js
View file @
d58fac82
...
@@ -11,28 +11,36 @@ require('chai')
...
@@ -11,28 +11,36 @@ 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
);
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
()
{
context
(
'for a non-zero amount'
,
function
()
{
const
event
=
expectEvent
.
inLogs
(
this
.
logs
,
'Burn'
);
shouldBurn
(
100
);
event
.
args
.
burner
.
should
.
eq
(
owner
);
event
.
args
.
value
.
should
.
be
.
bignumber
.
equal
(
amount
);
});
});
it
(
'emits a transfer event'
,
async
function
()
{
function
shouldBurn
(
amount
)
{
const
event
=
expectEvent
.
inLogs
(
this
.
logs
,
'Transfer'
);
beforeEach
(
async
function
()
{
event
.
args
.
from
.
should
.
eq
(
owner
);
({
logs
:
this
.
logs
}
=
await
this
.
token
.
burn
(
amount
,
{
from
:
owner
}));
event
.
args
.
to
.
should
.
eq
(
ZERO_ADDRESS
);
});
event
.
args
.
value
.
should
.
be
.
bignumber
.
equal
(
amount
);
});
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
);
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
()
{
describe
(
'when the given amount is greater than the balance of the sender'
,
function
()
{
...
@@ -46,34 +54,44 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
...
@@ -46,34 +54,44 @@ 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
);
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
);
});
});
it
(
'decrements allowance'
,
async
function
()
{
context
(
'for a non-zero amount'
,
function
()
{
(
await
this
.
token
.
allowance
(
owner
,
burner
)).
should
.
be
.
bignumber
.
equal
(
2
00
);
shouldBurnFrom
(
1
00
);
});
});
it
(
'emits a burn event'
,
async
function
()
{
function
shouldBurnFrom
(
amount
)
{
const
event
=
expectEvent
.
inLogs
(
this
.
logs
,
'Burn'
);
const
originalAllowance
=
amount
*
3
;
event
.
args
.
burner
.
should
.
eq
(
owner
);
event
.
args
.
value
.
should
.
be
.
bignumber
.
equal
(
amount
);
beforeEach
(
async
function
()
{
});
await
this
.
token
.
approve
(
burner
,
originalAllowance
,
{
from
:
owner
});
const
{
logs
}
=
await
this
.
token
.
burnFrom
(
owner
,
amount
,
{
from
:
burner
});
it
(
'emits a transfer event'
,
async
function
()
{
this
.
logs
=
logs
;
const
event
=
expectEvent
.
inLogs
(
this
.
logs
,
'Transfer'
);
});
event
.
args
.
from
.
should
.
eq
(
owner
);
event
.
args
.
to
.
should
.
eq
(
ZERO_ADDRESS
);
it
(
'burns the requested amount'
,
async
function
()
{
event
.
args
.
value
.
should
.
be
.
bignumber
.
equal
(
amount
);
(
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
()
{
describe
(
'when the given amount is greater than the balance of the sender'
,
function
()
{
...
...
test/token/ERC20/MintableToken.behavior.js
View file @
d58fac82
...
@@ -93,26 +93,36 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
...
@@ -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
);
});
});
it
(
'emits a mint and a transfer event'
,
async
function
()
{
function
shouldMint
(
amount
)
{
const
{
logs
}
=
await
this
.
token
.
mint
(
owner
,
amount
,
{
from
});
beforeEach
(
async
function
()
{
({
logs
:
this
.
logs
}
=
await
this
.
token
.
mint
(
anyone
,
amount
,
{
from
}));
});
const
mintEvent
=
expectEvent
.
inLogs
(
logs
,
'Mint'
,
{
it
(
'mints the requested amount'
,
async
function
()
{
to
:
owner
,
(
await
this
.
token
.
balanceOf
(
anyone
)).
should
.
be
.
bignumber
.
equal
(
amount
);
});
});
mintEvent
.
args
.
amount
.
should
.
be
.
bignumber
.
equal
(
amount
);
const
transferEvent
=
expectEvent
.
inLogs
(
logs
,
'Transfer'
,
{
it
(
'emits a mint and a transfer event'
,
async
function
()
{
from
:
ZERO_ADDRESS
,
const
mintEvent
=
expectEvent
.
inLogs
(
this
.
logs
,
'Mint'
,
{
to
:
owner
,
to
:
anyone
,
});
mintEvent
.
args
.
amount
.
should
.
be
.
bignumber
.
equal
(
amount
);
const
transferEvent
=
expectEvent
.
inLogs
(
this
.
logs
,
'Transfer'
,
{
from
:
ZERO_ADDRESS
,
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]) {
...
@@ -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]) {
...
@@ -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]) {
...
@@ -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
}));
});
});
});
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment