Merge pull request #353 from jakub-wojciechowski/master
Change crowdsales to use timestamps instead of block numbers #350
This commit is contained in:
@ -7,13 +7,13 @@ import '../../contracts/crowdsale/CappedCrowdsale.sol';
|
||||
contract CappedCrowdsaleImpl is CappedCrowdsale {
|
||||
|
||||
function CappedCrowdsaleImpl (
|
||||
uint256 _startBlock,
|
||||
uint256 _endBlock,
|
||||
uint256 _startTime,
|
||||
uint256 _endTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
uint256 _cap
|
||||
)
|
||||
Crowdsale(_startBlock, _endBlock, _rate, _wallet)
|
||||
Crowdsale(_startTime, _endTime, _rate, _wallet)
|
||||
CappedCrowdsale(_cap)
|
||||
{
|
||||
}
|
||||
|
||||
@ -7,12 +7,12 @@ import '../../contracts/crowdsale/FinalizableCrowdsale.sol';
|
||||
contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {
|
||||
|
||||
function FinalizableCrowdsaleImpl (
|
||||
uint256 _startBlock,
|
||||
uint256 _endBlock,
|
||||
uint256 _startTime,
|
||||
uint256 _endTime,
|
||||
uint256 _rate,
|
||||
address _wallet
|
||||
)
|
||||
Crowdsale(_startBlock, _endBlock, _rate, _wallet)
|
||||
Crowdsale(_startTime, _endTime, _rate, _wallet)
|
||||
FinalizableCrowdsale()
|
||||
{
|
||||
}
|
||||
|
||||
@ -7,13 +7,13 @@ import '../../contracts/crowdsale/RefundableCrowdsale.sol';
|
||||
contract RefundableCrowdsaleImpl is RefundableCrowdsale {
|
||||
|
||||
function RefundableCrowdsaleImpl (
|
||||
uint256 _startBlock,
|
||||
uint256 _endBlock,
|
||||
uint256 _startTime,
|
||||
uint256 _endTime,
|
||||
uint256 _rate,
|
||||
address _wallet,
|
||||
uint256 _goal
|
||||
)
|
||||
Crowdsale(_startBlock, _endBlock, _rate, _wallet)
|
||||
Crowdsale(_startTime, _endTime, _rate, _wallet)
|
||||
RefundableCrowdsale(_goal)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
// Increases testrpc time by the passed duration (a moment.js instance)
|
||||
import latestTime from './latestTime'
|
||||
|
||||
// Increases testrpc time by the passed duration in seconds
|
||||
export default function increaseTime(duration) {
|
||||
const id = Date.now()
|
||||
|
||||
@ -6,7 +8,7 @@ export default function increaseTime(duration) {
|
||||
web3.currentProvider.sendAsync({
|
||||
jsonrpc: '2.0',
|
||||
method: 'evm_increaseTime',
|
||||
params: [duration.asSeconds()],
|
||||
params: [duration],
|
||||
id: id,
|
||||
}, err1 => {
|
||||
if (err1) return reject(err1)
|
||||
@ -21,3 +23,25 @@ export default function increaseTime(duration) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Beware that due to the need of calling two separate testrpc methods and rpc calls overhead
|
||||
* it's hard to increase time precisely to a target point so design your test to tolerate
|
||||
* small fluctuations from time to time.
|
||||
*
|
||||
* @param target time in seconds
|
||||
*/
|
||||
export function increaseTimeTo(target) {
|
||||
let now = latestTime().unix();
|
||||
if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`);
|
||||
let diff = target - now;
|
||||
return increaseTime(diff);
|
||||
}
|
||||
|
||||
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) }
|
||||
};
|
||||
Reference in New Issue
Block a user