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
2b5192b9
Commit
2b5192b9
authored
Aug 06, 2017
by
Jakub Wojciechowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change crowdsales to use timestamps instead of block numbers #350 update derived crowdsales
parent
77dfcb6e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
69 additions
and
46 deletions
+69
-46
CappedCrowdsale.js
test/CappedCrowdsale.js
+21
-13
FinalizableCrowdsale.js
test/FinalizableCrowdsale.js
+16
-8
RefundableCrowdsale.js
test/RefundableCrowdsale.js
+23
-16
CappedCrowdsaleImpl.sol
test/helpers/CappedCrowdsaleImpl.sol
+3
-3
FinalizableCrowdsaleImpl.sol
test/helpers/FinalizableCrowdsaleImpl.sol
+3
-3
RefundableCrowdsaleImpl.sol
test/helpers/RefundableCrowdsaleImpl.sol
+3
-3
No files found.
test/CappedCrowdsale.js
View file @
2b5192b9
import
moment
from
'moment'
import
ether
from
'./helpers/ether'
import
ether
from
'./helpers/ether'
import
advanceToBlock
from
'./helpers/advanceToBlock'
import
advanceToBlock
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
const
BigNumber
=
web3
.
BigNumber
const
BigNumber
=
web3
.
BigNumber
...
@@ -19,28 +22,33 @@ contract('CappedCrowdsale', function ([_, wallet]) {
...
@@ -19,28 +22,33 @@ contract('CappedCrowdsale', function ([_, wallet]) {
const
cap
=
ether
(
300
)
const
cap
=
ether
(
300
)
const
lessThanCap
=
ether
(
60
)
const
lessThanCap
=
ether
(
60
)
describe
(
'creating a valid crowdsale'
,
function
()
{
before
(
async
function
()
{
//Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
it
(
'should fail with zero cap'
,
async
function
()
{
await
advanceToBlock
(
web3
.
eth
.
getBlock
(
'latest'
).
number
+
1
)
await
CappedCrowdsale
.
new
(
this
.
startBlock
,
this
.
endBlock
,
rate
,
wallet
,
0
).
should
.
be
.
rejectedWith
(
EVMThrow
);
})
})
});
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
start
Block
=
web3
.
eth
.
blockNumber
+
10
this
.
start
Time
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
end
Block
=
web3
.
eth
.
blockNumber
+
20
this
.
end
Time
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsale
=
await
CappedCrowdsale
.
new
(
this
.
startBlock
,
this
.
endBlock
,
rate
,
wallet
,
cap
)
this
.
crowdsale
=
await
CappedCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
cap
)
this
.
token
=
MintableToken
.
at
(
await
this
.
crowdsale
.
token
())
this
.
token
=
MintableToken
.
at
(
await
this
.
crowdsale
.
token
())
})
})
describe
(
'creating a valid crowdsale'
,
function
()
{
it
(
'should fail with zero cap'
,
async
function
()
{
await
CappedCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
0
).
should
.
be
.
rejectedWith
(
EVMThrow
);
})
});
describe
(
'accepting payments'
,
function
()
{
describe
(
'accepting payments'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
advanceToBlock
(
this
.
startBlock
-
1
)
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
})
})
it
(
'should accept payments within cap'
,
async
function
()
{
it
(
'should accept payments within cap'
,
async
function
()
{
...
@@ -62,7 +70,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
...
@@ -62,7 +70,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe
(
'ending'
,
function
()
{
describe
(
'ending'
,
function
()
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
await
advanceToBlock
(
this
.
startBlock
-
1
)
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
})
})
it
(
'should not be ended if under cap'
,
async
function
()
{
it
(
'should not be ended if under cap'
,
async
function
()
{
...
...
test/FinalizableCrowdsale.js
View file @
2b5192b9
import
moment
from
'moment'
import
advanceToBlock
from
'./helpers/advanceToBlock'
import
advanceToBlock
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
const
BigNumber
=
web3
.
BigNumber
const
BigNumber
=
web3
.
BigNumber
...
@@ -15,11 +18,16 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
...
@@ -15,11 +18,16 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
const
rate
=
new
BigNumber
(
1000
)
const
rate
=
new
BigNumber
(
1000
)
before
(
async
function
()
{
//Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
await
advanceToBlock
(
web3
.
eth
.
getBlock
(
'latest'
).
number
+
1
)
})
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
start
Block
=
web3
.
eth
.
blockNumber
+
10
this
.
start
Time
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
end
Block
=
web3
.
eth
.
blockNumber
+
20
this
.
end
Time
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsale
=
await
FinalizableCrowdsale
.
new
(
this
.
start
Block
,
this
.
endBlock
,
rate
,
wallet
,
{
from
:
owner
})
this
.
crowdsale
=
await
FinalizableCrowdsale
.
new
(
this
.
start
Time
,
this
.
endTime
,
rate
,
wallet
,
{
from
:
owner
})
this
.
token
=
MintableToken
.
at
(
await
this
.
crowdsale
.
token
())
this
.
token
=
MintableToken
.
at
(
await
this
.
crowdsale
.
token
())
})
})
...
@@ -29,30 +37,30 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
...
@@ -29,30 +37,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
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
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
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
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
advanceToBlock
(
this
.
endBlock
+
1
)
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
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
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
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
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
)
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 @
2b5192b9
import
moment
from
'moment'
import
ether
from
'./helpers/ether'
import
ether
from
'./helpers/ether'
import
advanceToBlock
from
'./helpers/advanceToBlock'
import
advanceToBlock
from
'./helpers/advanceToBlock'
import
increaseTime
from
'./helpers/increaseTime'
import
latestTime
from
'./helpers/latestTime'
import
EVMThrow
from
'./helpers/EVMThrow'
import
EVMThrow
from
'./helpers/EVMThrow'
const
BigNumber
=
web3
.
BigNumber
const
BigNumber
=
web3
.
BigNumber
...
@@ -17,39 +20,43 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
...
@@ -17,39 +20,43 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
const
goal
=
ether
(
800
)
const
goal
=
ether
(
800
)
const
lessThanGoal
=
ether
(
750
)
const
lessThanGoal
=
ether
(
750
)
before
(
async
function
()
{
//Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
await
advanceToBlock
(
web3
.
eth
.
getBlock
(
'latest'
).
number
+
1
)
})
beforeEach
(
async
function
()
{
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsale
=
await
RefundableCrowdsale
.
new
(
this
.
startTime
,
this
.
endTime
,
rate
,
wallet
,
goal
,
{
from
:
owner
})
})
describe
(
'creating a valid crowdsale'
,
function
()
{
describe
(
'creating a valid crowdsale'
,
function
()
{
it
(
'should fail with zero goal'
,
async
function
()
{
it
(
'should fail with zero goal'
,
async
function
()
{
await
RefundableCrowdsale
.
new
(
this
.
start
Block
,
this
.
endBlock
,
rate
,
wallet
,
0
,
{
from
:
owner
}).
should
.
be
.
rejectedWith
(
EVMThrow
);
await
RefundableCrowdsale
.
new
(
this
.
start
Time
,
this
.
endTime
,
rate
,
wallet
,
0
,
{
from
:
owner
}).
should
.
be
.
rejectedWith
(
EVMThrow
);
})
})
});
});
beforeEach
(
async
function
()
{
this
.
startBlock
=
web3
.
eth
.
blockNumber
+
10
this
.
endBlock
=
web3
.
eth
.
blockNumber
+
20
this
.
crowdsale
=
await
RefundableCrowdsale
.
new
(
this
.
startBlock
,
this
.
endBlock
,
rate
,
wallet
,
goal
,
{
from
:
owner
})
})
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
advanceToBlock
(
this
.
endBlock
-
1
)
await
increaseTime
(
moment
.
duration
(
2
,
'week'
)
)
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
advanceToBlock
(
this
.
startBlock
-
1
)
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
)
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
advanceToBlock
(
this
.
startBlock
-
1
)
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
this
.
crowdsale
.
sendTransaction
({
value
:
lessThanGoal
,
from
:
investor
})
await
this
.
crowdsale
.
sendTransaction
({
value
:
lessThanGoal
,
from
:
investor
})
await
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
)
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
await
this
.
crowdsale
.
finalize
({
from
:
owner
})
...
@@ -62,9 +69,9 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
...
@@ -62,9 +69,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
advanceToBlock
(
this
.
startBlock
-
1
)
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
)
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
this
.
crowdsale
.
sendTransaction
({
value
:
goal
,
from
:
investor
})
await
advanceToBlock
(
this
.
endBlock
)
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
)
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/helpers/CappedCrowdsaleImpl.sol
View file @
2b5192b9
...
@@ -7,13 +7,13 @@ import '../../contracts/crowdsale/CappedCrowdsale.sol';
...
@@ -7,13 +7,13 @@ import '../../contracts/crowdsale/CappedCrowdsale.sol';
contract CappedCrowdsaleImpl is CappedCrowdsale {
contract CappedCrowdsaleImpl is CappedCrowdsale {
function CappedCrowdsaleImpl (
function CappedCrowdsaleImpl (
uint256 _start
Block
,
uint256 _start
Time
,
uint256 _end
Block
,
uint256 _end
Time
,
uint256 _rate,
uint256 _rate,
address _wallet,
address _wallet,
uint256 _cap
uint256 _cap
)
)
Crowdsale(_start
Block, _endBlock
, _rate, _wallet)
Crowdsale(_start
Time, _endTime
, _rate, _wallet)
CappedCrowdsale(_cap)
CappedCrowdsale(_cap)
{
{
}
}
...
...
test/helpers/FinalizableCrowdsaleImpl.sol
View file @
2b5192b9
...
@@ -7,12 +7,12 @@ import '../../contracts/crowdsale/FinalizableCrowdsale.sol';
...
@@ -7,12 +7,12 @@ import '../../contracts/crowdsale/FinalizableCrowdsale.sol';
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
function FinalizableCrowdsaleImpl (
function FinalizableCrowdsaleImpl (
uint256 _start
Block
,
uint256 _start
Time
,
uint256 _end
Block
,
uint256 _end
Time
,
uint256 _rate,
uint256 _rate,
address _wallet
address _wallet
)
)
Crowdsale(_start
Block, _endBlock
, _rate, _wallet)
Crowdsale(_start
Time, _endTime
, _rate, _wallet)
FinalizableCrowdsale()
FinalizableCrowdsale()
{
{
}
}
...
...
test/helpers/RefundableCrowdsaleImpl.sol
View file @
2b5192b9
...
@@ -7,13 +7,13 @@ import '../../contracts/crowdsale/RefundableCrowdsale.sol';
...
@@ -7,13 +7,13 @@ import '../../contracts/crowdsale/RefundableCrowdsale.sol';
contract RefundableCrowdsaleImpl is RefundableCrowdsale {
contract RefundableCrowdsaleImpl is RefundableCrowdsale {
function RefundableCrowdsaleImpl (
function RefundableCrowdsaleImpl (
uint256 _start
Block
,
uint256 _start
Time
,
uint256 _end
Block
,
uint256 _end
Time
,
uint256 _rate,
uint256 _rate,
address _wallet,
address _wallet,
uint256 _goal
uint256 _goal
)
)
Crowdsale(_start
Block, _endBlock
, _rate, _wallet)
Crowdsale(_start
Time, _endTime
, _rate, _wallet)
RefundableCrowdsale(_goal)
RefundableCrowdsale(_goal)
{
{
}
}
...
...
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