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
7c883b63
Commit
7c883b63
authored
Aug 10, 2017
by
Jakub Wojciechowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Duration helper and eliminated hardcoded periods
parent
2261039d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
46 deletions
+76
-46
CappedCrowdsale.js
test/CappedCrowdsale.js
+8
-5
Crowdsale.js
test/Crowdsale.js
+12
-8
FinalizableCrowdsale.js
test/FinalizableCrowdsale.js
+12
-8
RefundableCrowdsale.js
test/RefundableCrowdsale.js
+14
-10
SampleCrowdsale.js
test/SampleCrowdsale.js
+14
-10
TokenTimelock.js
test/TokenTimelock.js
+4
-4
increaseTime.js
test/helpers/increaseTime.js
+12
-1
No files found.
test/CappedCrowdsale.js
View file @
7c883b63
import
moment
from
'moment'
import
ether
from
'./helpers/ether'
import
ether
from
'./helpers/ether'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
increaseTime
from
'./helpers/increaseTime'
import
{
duration
,
increaseTimeHandicap
}
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
...
@@ -28,8 +28,11 @@ contract('CappedCrowdsale', function ([_, wallet]) {
...
@@ -28,8 +28,11 @@ contract('CappedCrowdsale', function ([_, wallet]) {
})
})
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
timeToStart
=
duration
.
weeks
(
1
);
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsalePeriod
=
duration
.
weeks
(
1
);
this
.
startTime
=
latestTime
().
unix
()
+
this
.
timeToStart
;
this
.
endTime
=
this
.
startTime
+
this
.
crowdsalePeriod
;
this
.
crowdsale
=
await
CappedCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
cap
)
this
.
crowdsale
=
await
CappedCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
cap
)
...
@@ -48,7 +51,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
...
@@ -48,7 +51,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe
(
'accepting payments'
,
function
()
{
describe
(
'accepting payments'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
})
})
it
(
'should accept payments within cap'
,
async
function
()
{
it
(
'should accept payments within cap'
,
async
function
()
{
...
@@ -70,7 +73,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
...
@@ -70,7 +73,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe
(
'ending'
,
function
()
{
describe
(
'ending'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
})
})
it
(
'should not be ended if under cap'
,
async
function
()
{
it
(
'should not be ended if under cap'
,
async
function
()
{
...
...
test/Crowdsale.js
View file @
7c883b63
import
moment
from
'moment'
import
ether
from
'./helpers/ether'
import
ether
from
'./helpers/ether'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
increaseTime
from
'./helpers/increaseTime'
import
{
duration
,
increaseTimeHandicap
}
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
...
@@ -28,8 +28,12 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
...
@@ -28,8 +28,12 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
})
})
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
timeToStart
=
duration
.
weeks
(
1
);
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsalePeriod
=
duration
.
weeks
(
1
);
this
.
timeToEnd
=
this
.
timeToStart
+
this
.
crowdsalePeriod
+
increaseTimeHandicap
;
this
.
startTime
=
latestTime
().
unix
()
+
this
.
timeToStart
;
this
.
endTime
=
this
.
startTime
+
this
.
crowdsalePeriod
;
this
.
crowdsale
=
await
Crowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
)
this
.
crowdsale
=
await
Crowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
)
...
@@ -44,7 +48,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
...
@@ -44,7 +48,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
it
(
'should be ended only after end'
,
async
function
()
{
it
(
'should be ended only after end'
,
async
function
()
{
let
ended
=
await
this
.
crowdsale
.
hasEnded
()
let
ended
=
await
this
.
crowdsale
.
hasEnded
()
ended
.
should
.
equal
(
false
)
ended
.
should
.
equal
(
false
)
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
ended
=
await
this
.
crowdsale
.
hasEnded
()
ended
=
await
this
.
crowdsale
.
hasEnded
()
ended
.
should
.
equal
(
true
)
ended
.
should
.
equal
(
true
)
})
})
...
@@ -57,13 +61,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
...
@@ -57,13 +61,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
})
})
it
(
'should accept payments after start'
,
async
function
()
{
it
(
'should accept payments after start'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
await
this
.
crowdsale
.
send
(
value
).
should
.
be
.
fulfilled
await
this
.
crowdsale
.
send
(
value
).
should
.
be
.
fulfilled
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
value
,
from
:
purchaser
}).
should
.
be
.
fulfilled
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
value
,
from
:
purchaser
}).
should
.
be
.
fulfilled
})
})
it
(
'should reject payments after end'
,
async
function
()
{
it
(
'should reject payments after end'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
await
this
.
crowdsale
.
send
(
value
).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
send
(
value
).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
value
,
from
:
purchaser
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
value
,
from
:
purchaser
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
})
})
...
@@ -73,7 +77,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
...
@@ -73,7 +77,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe
(
'high-level purchase'
,
function
()
{
describe
(
'high-level purchase'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
})
})
it
(
'should log purchase'
,
async
function
()
{
it
(
'should log purchase'
,
async
function
()
{
...
@@ -112,7 +116,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
...
@@ -112,7 +116,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe
(
'low-level purchase'
,
function
()
{
describe
(
'low-level purchase'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
})
})
it
(
'should log purchase'
,
async
function
()
{
it
(
'should log purchase'
,
async
function
()
{
...
...
test/FinalizableCrowdsale.js
View file @
7c883b63
import
moment
from
'moment'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
increaseTime
from
'./helpers/increaseTime'
import
{
duration
,
increaseTimeHandicap
}
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
...
@@ -24,8 +24,12 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
...
@@ -24,8 +24,12 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
})
})
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
timeToStart
=
duration
.
weeks
(
1
);
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsalePeriod
=
duration
.
weeks
(
1
);
this
.
timeToEnd
=
this
.
timeToStart
+
this
.
crowdsalePeriod
+
increaseTimeHandicap
;
this
.
startTime
=
latestTime
().
unix
()
+
this
.
timeToStart
;
this
.
endTime
=
this
.
startTime
+
this
.
crowdsalePeriod
;
this
.
crowdsale
=
await
FinalizableCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
{
from
:
owner
})
this
.
crowdsale
=
await
FinalizableCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
{
from
:
owner
})
...
@@ -37,30 +41,30 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
...
@@ -37,30 +41,30 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
})
})
it
(
'cannot be finalized by third party after ending'
,
async
function
()
{
it
(
'cannot be finalized by third party after ending'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
await
this
.
crowdsale
.
finalize
({
from
:
thirdparty
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
finalize
({
from
:
thirdparty
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
})
})
it
(
'can be finalized by owner after ending'
,
async
function
()
{
it
(
'can be finalized by owner after ending'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
}).
should
.
be
.
fulfilled
await
this
.
crowdsale
.
finalize
({
from
:
owner
}).
should
.
be
.
fulfilled
})
})
it
(
'cannot be finalized twice'
,
async
function
()
{
it
(
'cannot be finalized twice'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
await
this
.
crowdsale
.
finalize
({
from
:
owner
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
})
})
it
(
'logs finalized'
,
async
function
()
{
it
(
'logs finalized'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
const
{
logs
}
=
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
const
{
logs
}
=
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
const
event
=
logs
.
find
(
e
=>
e
.
event
===
'Finalized'
)
const
event
=
logs
.
find
(
e
=>
e
.
event
===
'Finalized'
)
should
.
exist
(
event
)
should
.
exist
(
event
)
})
})
it
(
'finishes minting of token'
,
async
function
()
{
it
(
'finishes minting of token'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
await
increaseTime
(
this
.
timeToEnd
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
const
finished
=
await
this
.
token
.
mintingFinished
()
const
finished
=
await
this
.
token
.
mintingFinished
()
finished
.
should
.
equal
(
true
)
finished
.
should
.
equal
(
true
)
...
...
test/RefundableCrowdsale.js
View file @
7c883b63
import
moment
from
'moment'
import
ether
from
'./helpers/ether'
import
ether
from
'./helpers/ether'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
increaseTime
from
'./helpers/increaseTime'
import
{
duration
,
increaseTimeHandicap
}
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
...
@@ -26,8 +26,12 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
...
@@ -26,8 +26,12 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
})
})
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
timeToStart
=
duration
.
weeks
(
1
);
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsalePeriod
=
duration
.
weeks
(
1
);
this
.
timeToEnd
=
this
.
timeToStart
+
this
.
crowdsalePeriod
+
increaseTimeHandicap
;
this
.
startTime
=
latestTime
().
unix
()
+
this
.
timeToStart
;
this
.
endTime
=
this
.
startTime
+
this
.
crowdsalePeriod
;
this
.
crowdsale
=
await
RefundableCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
goal
,
{
from
:
owner
})
this
.
crowdsale
=
await
RefundableCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
goal
,
{
from
:
owner
})
})
})
...
@@ -42,21 +46,21 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
...
@@ -42,21 +46,21 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
it
(
'should deny refunds before end'
,
async
function
()
{
it
(
'should deny refunds before end'
,
async
function
()
{
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
increaseTime
(
moment
.
duration
(
2
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
})
})
it
(
'should deny refunds after end if goal was reached'
,
async
function
()
{
it
(
'should deny refunds after end if goal was reached'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
)
await
increaseTime
(
this
.
crowdsalePeriod
+
increaseTimeHandicap
)
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
)
})
})
it
(
'should allow refunds after end if goal was not reached'
,
async
function
()
{
it
(
'should allow refunds after end if goal was not reached'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
await
this
.
crowdsale
.
sendTransaction
({
value
:
lessThanGoal
,
from
:
investor
})
await
this
.
crowdsale
.
sendTransaction
({
value
:
lessThanGoal
,
from
:
investor
})
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
)
await
increaseTime
(
this
.
crowdsalePeriod
+
increaseTimeHandicap
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
...
@@ -69,9 +73,9 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
...
@@ -69,9 +73,9 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
})
})
it
(
'should forward funds to wallet after end if goal was reached'
,
async
function
()
{
it
(
'should forward funds to wallet after end if goal was reached'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
increaseTime
(
this
.
timeToStart
)
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
)
await
increaseTime
(
this
.
crowdsalePeriod
+
increaseTimeHandicap
)
const
pre
=
web3
.
eth
.
getBalance
(
wallet
)
const
pre
=
web3
.
eth
.
getBalance
(
wallet
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
...
...
test/SampleCrowdsale.js
View file @
7c883b63
import
moment
from
'moment'
import
ether
from
'./helpers/ether'
import
ether
from
'./helpers/ether'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
{
advanceBlock
}
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
increaseTime
from
'./helpers/increaseTime'
import
{
duration
,
increaseTimeHandicap
}
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
...
@@ -27,8 +27,12 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -27,8 +27,12 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
})
})
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
timeToStart
=
duration
.
weeks
(
1
);
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsalePeriod
=
duration
.
weeks
(
1
);
this
.
timeToEnd
=
this
.
timeToStart
+
this
.
crowdsalePeriod
+
increaseTimeHandicap
;
this
.
startTime
=
latestTime
().
unix
()
+
this
.
timeToStart
;
this
.
endTime
=
this
.
startTime
+
this
.
crowdsalePeriod
;
this
.
crowdsale
=
await
SampleCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
RATE
,
GOAL
,
CAP
,
wallet
);
this
.
crowdsale
=
await
SampleCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
RATE
,
GOAL
,
CAP
,
wallet
);
...
@@ -57,7 +61,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -57,7 +61,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
const
investmentAmount
=
ether
(
1
);
const
investmentAmount
=
ether
(
1
);
const
expectedTokenAmount
=
RATE
.
mul
(
investmentAmount
);
const
expectedTokenAmount
=
RATE
.
mul
(
investmentAmount
);
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
await
increaseTime
(
this
.
timeToStart
);
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
investmentAmount
,
from
:
investor
}).
should
.
be
.
fulfilled
;
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
investmentAmount
,
from
:
investor
}).
should
.
be
.
fulfilled
;
(
await
this
.
token
.
balanceOf
(
investor
)).
should
.
be
.
bignumber
.
equal
(
expectedTokenAmount
);
(
await
this
.
token
.
balanceOf
(
investor
)).
should
.
be
.
bignumber
.
equal
(
expectedTokenAmount
);
...
@@ -65,23 +69,23 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -65,23 +69,23 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
});
});
it
(
'should reject payments after end'
,
async
function
()
{
it
(
'should reject payments after end'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
);
await
increaseTime
(
this
.
timeToEnd
);
await
this
.
crowdsale
.
send
(
ether
(
1
)).
should
.
be
.
rejectedWith
(
EVMThrow
);
await
this
.
crowdsale
.
send
(
ether
(
1
)).
should
.
be
.
rejectedWith
(
EVMThrow
);
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
ether
(
1
),
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
);
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
ether
(
1
),
from
:
investor
}).
should
.
be
.
rejectedWith
(
EVMThrow
);
});
});
it
(
'should reject payments over cap'
,
async
function
()
{
it
(
'should reject payments over cap'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
await
increaseTime
(
this
.
timeToStart
);
await
this
.
crowdsale
.
send
(
CAP
);
await
this
.
crowdsale
.
send
(
CAP
);
await
this
.
crowdsale
.
send
(
1
).
should
.
be
.
rejectedWith
(
EVMThrow
);
await
this
.
crowdsale
.
send
(
1
).
should
.
be
.
rejectedWith
(
EVMThrow
);
});
});
it
(
'should allow finalization and transfer funds to wallet if the goal is reached'
,
async
function
()
{
it
(
'should allow finalization and transfer funds to wallet if the goal is reached'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
await
increaseTime
(
this
.
timeToStart
);
await
this
.
crowdsale
.
send
(
GOAL
);
await
this
.
crowdsale
.
send
(
GOAL
);
const
beforeFinalization
=
web3
.
eth
.
getBalance
(
wallet
);
const
beforeFinalization
=
web3
.
eth
.
getBalance
(
wallet
);
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
);
await
increaseTime
(
this
.
crowdsalePeriod
+
increaseTimeHandicap
);
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
const
afterFinalization
=
web3
.
eth
.
getBalance
(
wallet
);
const
afterFinalization
=
web3
.
eth
.
getBalance
(
wallet
);
...
@@ -91,9 +95,9 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -91,9 +95,9 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
it
(
'should allow refunds if the goal is not reached'
,
async
function
()
{
it
(
'should allow refunds if the goal is not reached'
,
async
function
()
{
const
balanceBeforeInvestment
=
web3
.
eth
.
getBalance
(
investor
);
const
balanceBeforeInvestment
=
web3
.
eth
.
getBalance
(
investor
);
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
await
increaseTime
(
this
.
timeToStart
);
await
this
.
crowdsale
.
sendTransaction
({
value
:
ether
(
1
),
from
:
investor
,
gasPrice
:
0
});
await
this
.
crowdsale
.
sendTransaction
({
value
:
ether
(
1
),
from
:
investor
,
gasPrice
:
0
});
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
);
await
increaseTime
(
this
.
crowdsalePeriod
+
increaseTimeHandicap
);
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
,
gasPrice
:
0
}).
should
.
be
.
fulfilled
;
await
this
.
crowdsale
.
claimRefund
({
from
:
investor
,
gasPrice
:
0
}).
should
.
be
.
fulfilled
;
...
...
test/TokenTimelock.js
View file @
7c883b63
...
@@ -29,26 +29,26 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
...
@@ -29,26 +29,26 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
})
})
it
(
'cannot be released just before time limit'
,
async
function
()
{
it
(
'cannot be released just before time limit'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
0.99
,
'year'
))
await
increaseTime
(
moment
.
duration
(
0.99
,
'year'
)
.
asSeconds
()
)
await
this
.
timelock
.
release
().
should
.
be
.
rejected
await
this
.
timelock
.
release
().
should
.
be
.
rejected
})
})
it
(
'can be released just after limit'
,
async
function
()
{
it
(
'can be released just after limit'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
1.01
,
'year'
))
await
increaseTime
(
moment
.
duration
(
1.01
,
'year'
)
.
asSeconds
()
)
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
balance
.
should
.
be
.
bignumber
.
equal
(
amount
)
balance
.
should
.
be
.
bignumber
.
equal
(
amount
)
})
})
it
(
'can be released after time limit'
,
async
function
()
{
it
(
'can be released after time limit'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2
,
'year'
))
await
increaseTime
(
moment
.
duration
(
2
,
'year'
)
.
asSeconds
()
)
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
balance
.
should
.
be
.
bignumber
.
equal
(
amount
)
balance
.
should
.
be
.
bignumber
.
equal
(
amount
)
})
})
it
(
'cannot be released twice'
,
async
function
()
{
it
(
'cannot be released twice'
,
async
function
()
{
await
increaseTime
(
moment
.
duration
(
2
,
'year'
))
await
increaseTime
(
moment
.
duration
(
2
,
'year'
)
.
asSeconds
()
)
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
await
this
.
timelock
.
release
().
should
.
be
.
fulfilled
await
this
.
timelock
.
release
().
should
.
be
.
rejected
await
this
.
timelock
.
release
().
should
.
be
.
rejected
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
const
balance
=
await
this
.
token
.
balanceOf
(
beneficiary
)
...
...
test/helpers/increaseTime.js
View file @
7c883b63
...
@@ -6,7 +6,7 @@ export default function increaseTime(duration) {
...
@@ -6,7 +6,7 @@ export default function increaseTime(duration) {
web3
.
currentProvider
.
sendAsync
({
web3
.
currentProvider
.
sendAsync
({
jsonrpc
:
'2.0'
,
jsonrpc
:
'2.0'
,
method
:
'evm_increaseTime'
,
method
:
'evm_increaseTime'
,
params
:
[
duration
.
asSeconds
()
],
params
:
[
duration
],
id
:
id
,
id
:
id
,
},
err1
=>
{
},
err1
=>
{
if
(
err1
)
return
reject
(
err1
)
if
(
err1
)
return
reject
(
err1
)
...
@@ -21,3 +21,13 @@ export default function increaseTime(duration) {
...
@@ -21,3 +21,13 @@ export default function increaseTime(duration) {
})
})
})
})
}
}
export
const
duration
=
{
seconds
:
function
(
val
)
{
return
val
},
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
)
}
};
export
const
increaseTimeHandicap
=
duration
.
seconds
(
10
);
\ 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