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
99e0f5b5
Commit
99e0f5b5
authored
Aug 13, 2017
by
Jakub Wojciechowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor time manipulation in TokenTimelock tests
parent
6e66ba32
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
TokenTimelock.js
test/TokenTimelock.js
+6
-7
increaseTime.js
test/helpers/increaseTime.js
+4
-1
No files found.
test/TokenTimelock.js
View file @
99e0f5b5
...
...
@@ -5,10 +5,9 @@ require('chai')
.
use
(
require
(
'chai-bignumber'
)(
BigNumber
))
.
should
()
import
moment
from
'moment'
import
latestTime
from
'./helpers/latestTime'
import
increaseTime
from
'./helpers/increaseTime'
import
{
increaseTimeTo
,
duration
}
from
'./helpers/increaseTime'
const
MintableToken
=
artifacts
.
require
(
'MintableToken'
)
const
TokenTimelock
=
artifacts
.
require
(
'TokenTimelock'
)
...
...
@@ -19,7 +18,7 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
beforeEach
(
async
function
()
{
this
.
token
=
await
MintableToken
.
new
({
from
:
owner
})
this
.
releaseTime
=
latestTime
().
add
(
1
,
'year'
).
unix
(
)
this
.
releaseTime
=
latestTime
().
unix
()
+
duration
.
years
(
1
)
this
.
timelock
=
await
TokenTimelock
.
new
(
this
.
token
.
address
,
beneficiary
,
this
.
releaseTime
)
await
this
.
token
.
mint
(
this
.
timelock
.
address
,
amount
,
{
from
:
owner
})
})
...
...
@@ -29,26 +28,26 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
})
it
(
'cannot be released just before time limit'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
0.99
,
'year'
).
asSeconds
(
))
await
increaseTime
To
(
this
.
releaseTime
-
duration
.
seconds
(
3
))
await
this
.
timelock
.
release
().
should
.
be
.
rejected
})
it
(
'can be released just after limit'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1.01
,
'year'
).
asSeconds
(
))
await
increaseTime
To
(
this
.
releaseTime
+
duration
.
seconds
(
1
))
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
balance
.
should
.
be
.
bignumber
.
equal
(
amount
)
})
it
(
'can be released after time limit'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2
,
'year'
).
asSeconds
(
))
await
increaseTime
To
(
this
.
releaseTime
+
duration
.
years
(
1
))
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
balance
.
should
.
be
.
bignumber
.
equal
(
amount
)
})
it
(
'cannot be released twice'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2
,
'year'
).
asSeconds
(
))
await
increaseTime
To
(
this
.
releaseTime
+
duration
.
years
(
1
))
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
await
this
.
timelock
.
release
().
should
.
be
.
rejected
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
...
...
test/helpers/increaseTime.js
View file @
99e0f5b5
...
...
@@ -43,5 +43,7 @@ export const duration = {
minutes
:
function
(
val
)
{
return
val
*
this
.
seconds
(
60
)
},
hours
:
function
(
val
)
{
return
val
*
this
.
minutes
(
60
)
},
days
:
function
(
val
)
{
return
val
*
this
.
hours
(
24
)
},
weeks
:
function
(
val
)
{
return
val
*
this
.
days
(
7
)
}
weeks
:
function
(
val
)
{
return
val
*
this
.
days
(
7
)
},
months
:
function
(
val
)
{
return
val
*
this
.
days
(
30
)},
years
:
function
(
val
)
{
return
val
*
this
.
days
(
365
)}
};
\ No newline at end of file
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