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
c6e05568
Commit
c6e05568
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 example
parent
2b5192b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
13 deletions
+23
-13
SampleCrowdsale.sol
contracts/examples/SampleCrowdsale.sol
+2
-2
SampleCrowdsale.js
test/SampleCrowdsale.js
+21
-11
No files found.
contracts/examples/SampleCrowdsale.sol
View file @
c6e05568
...
@@ -30,11 +30,11 @@ contract SampleCrowdsaleToken is MintableToken {
...
@@ -30,11 +30,11 @@ contract SampleCrowdsaleToken is MintableToken {
*/
*/
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {
function SampleCrowdsale(uint256 _start
Block, uint256 _endBlock
, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet)
function SampleCrowdsale(uint256 _start
Time, uint256 _endTime
, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet)
CappedCrowdsale(_cap)
CappedCrowdsale(_cap)
FinalizableCrowdsale()
FinalizableCrowdsale()
RefundableCrowdsale(_goal)
RefundableCrowdsale(_goal)
Crowdsale(_start
Block, _endBlock
, _rate, _wallet)
Crowdsale(_start
Time, _endTime
, _rate, _wallet)
{
{
//As goal needs to be met for a successful crowdsale
//As goal needs to be met for a successful crowdsale
//the value needs to less or equal than a cap which is limit for accepted funds
//the value needs to less or equal than a cap which is limit for accepted funds
...
...
test/SampleCrowdsale.js
View file @
c6e05568
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
;
...
@@ -18,11 +21,17 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -18,11 +21,17 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
const
GOAL
=
ether
(
10
);
const
GOAL
=
ether
(
10
);
const
CAP
=
ether
(
20
);
const
CAP
=
ether
(
20
);
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
.
startBlock
=
web3
.
eth
.
blockNumber
+
10
;
this
.
startTime
=
latestTime
().
unix
()
+
moment
.
duration
(
1
,
'week'
).
asSeconds
();
this
.
endBlock
=
web3
.
eth
.
blockNumber
+
20
;
this
.
endTime
=
latestTime
().
unix
()
+
moment
.
duration
(
2
,
'week'
).
asSeconds
();
this
.
crowdsale
=
await
SampleCrowdsale
.
new
(
this
.
start
Block
,
this
.
endBlock
,
RATE
,
GOAL
,
CAP
,
wallet
);
this
.
crowdsale
=
await
SampleCrowdsale
.
new
(
this
.
start
Time
,
this
.
endTime
,
RATE
,
GOAL
,
CAP
,
wallet
);
this
.
token
=
SampleCrowdsaleToken
.
at
(
await
this
.
crowdsale
.
token
());
this
.
token
=
SampleCrowdsaleToken
.
at
(
await
this
.
crowdsale
.
token
());
});
});
...
@@ -31,8 +40,8 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -31,8 +40,8 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
this
.
crowdsale
.
should
.
exist
;
this
.
crowdsale
.
should
.
exist
;
this
.
token
.
should
.
exist
;
this
.
token
.
should
.
exist
;
(
await
this
.
crowdsale
.
start
Block
()).
should
.
be
.
bignumber
.
equal
(
this
.
startBlock
);
(
await
this
.
crowdsale
.
start
Time
()).
should
.
be
.
bignumber
.
equal
(
this
.
startTime
);
(
await
this
.
crowdsale
.
end
Block
()).
should
.
be
.
bignumber
.
equal
(
this
.
endBlock
);
(
await
this
.
crowdsale
.
end
Time
()).
should
.
be
.
bignumber
.
equal
(
this
.
endTime
);
(
await
this
.
crowdsale
.
rate
()).
should
.
be
.
bignumber
.
equal
(
RATE
);
(
await
this
.
crowdsale
.
rate
()).
should
.
be
.
bignumber
.
equal
(
RATE
);
(
await
this
.
crowdsale
.
wallet
()).
should
.
be
.
equal
(
wallet
);
(
await
this
.
crowdsale
.
wallet
()).
should
.
be
.
equal
(
wallet
);
(
await
this
.
crowdsale
.
goal
()).
should
.
be
.
bignumber
.
equal
(
GOAL
);
(
await
this
.
crowdsale
.
goal
()).
should
.
be
.
bignumber
.
equal
(
GOAL
);
...
@@ -48,7 +57,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -48,7 +57,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
advanceToBlock
(
this
.
startBlock
-
1
);
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
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
);
...
@@ -56,22 +65,23 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -56,22 +65,23 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
});
});
it
(
'should reject payments after end'
,
async
function
()
{
it
(
'should reject payments after end'
,
async
function
()
{
await
advanceToBlock
(
this
.
endBlock
);
await
increaseTime
(
moment
.
duration
(
2.1
,
'week'
)
);
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
advanceToBlock
(
this
.
startBlock
-
1
);
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
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
advanceToBlock
(
this
.
endBlock
-
1
);
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
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
this
.
crowdsale
.
finalize
({
from
:
owner
});
await
this
.
crowdsale
.
finalize
({
from
:
owner
});
const
afterFinalization
=
web3
.
eth
.
getBalance
(
wallet
);
const
afterFinalization
=
web3
.
eth
.
getBalance
(
wallet
);
...
@@ -81,9 +91,9 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
...
@@ -81,9 +91,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
advanceToBlock
(
this
.
startBlock
-
1
);
await
increaseTime
(
moment
.
duration
(
1
,
'week'
)
);
await
this
.
crowdsale
.
sendTransaction
({
value
:
ether
(
1
),
from
:
investor
,
gasPrice
:
0
});
await
this
.
crowdsale
.
sendTransaction
({
value
:
ether
(
1
),
from
:
investor
,
gasPrice
:
0
});
await
advanceToBlock
(
this
.
endBlock
);
await
increaseTime
(
moment
.
duration
(
1.1
,
'week'
)
);
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
;
...
...
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