diff --git a/package.json b/package.json index d22ff0e3e16..80efe2c05e0 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "coveralls": "^2.13.1", "ethereumjs-testrpc": "^3.0.2", "mocha-lcov-reporter": "^1.3.0", - "moment": "^2.18.1", "solidity-coverage": "^0.2.1", "truffle": "^3.4.6", "truffle-hdwallet-provider": "0.0.3" diff --git a/test/CappedCrowdsale.js b/test/CappedCrowdsale.js index 9dd027b3581..c3a7458ea86 100644 --- a/test/CappedCrowdsale.js +++ b/test/CappedCrowdsale.js @@ -27,7 +27,7 @@ contract('CappedCrowdsale', function ([_, wallet]) { }) beforeEach(async function () { - this.startTime = latestTime().unix() + duration.weeks(1); + this.startTime = latestTime() + duration.weeks(1); this.endTime = this.startTime + duration.weeks(1); this.crowdsale = await CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, cap) diff --git a/test/Crowdsale.js b/test/Crowdsale.js index e3abe197523..3294818a28b 100644 --- a/test/Crowdsale.js +++ b/test/Crowdsale.js @@ -27,7 +27,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { }) beforeEach(async function () { - this.startTime = latestTime().unix() + duration.weeks(1); + this.startTime = latestTime() + duration.weeks(1); this.endTime = this.startTime + duration.weeks(1); this.afterEndTime = this.endTime + duration.seconds(1) diff --git a/test/FinalizableCrowdsale.js b/test/FinalizableCrowdsale.js index a7e76bfbf3f..b138ec36d78 100644 --- a/test/FinalizableCrowdsale.js +++ b/test/FinalizableCrowdsale.js @@ -23,7 +23,7 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) { }) beforeEach(async function () { - this.startTime = latestTime().unix() + duration.weeks(1) + this.startTime = latestTime() + duration.weeks(1) this.endTime = this.startTime + duration.weeks(1) this.afterEndTime = this.endTime + duration.seconds(1) diff --git a/test/RefundableCrowdsale.js b/test/RefundableCrowdsale.js index d3150a94fa0..ce9515bb6cc 100644 --- a/test/RefundableCrowdsale.js +++ b/test/RefundableCrowdsale.js @@ -25,7 +25,7 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) { }) beforeEach(async function () { - this.startTime = latestTime().unix() + duration.weeks(1) + this.startTime = latestTime() + duration.weeks(1) this.endTime = this.startTime + duration.weeks(1) this.afterEndTime = this.endTime + duration.seconds(1) diff --git a/test/SampleCrowdsale.js b/test/SampleCrowdsale.js index b17c15aeb49..709c4bebdda 100644 --- a/test/SampleCrowdsale.js +++ b/test/SampleCrowdsale.js @@ -26,7 +26,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) { }) beforeEach(async function () { - this.startTime = latestTime().unix() + duration.weeks(1); + this.startTime = latestTime() + duration.weeks(1); this.endTime = this.startTime + duration.weeks(1); this.afterEndTime = this.endTime + duration.seconds(1); diff --git a/test/TokenTimelock.js b/test/TokenTimelock.js index 25ffd9e2e93..bbe431d3d21 100644 --- a/test/TokenTimelock.js +++ b/test/TokenTimelock.js @@ -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() + 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 increaseTimeTo(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 increaseTimeTo(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 increaseTimeTo(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 increaseTimeTo(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) diff --git a/test/helpers/increaseTime.js b/test/helpers/increaseTime.js index 5a6a8e2c284..a563caa5ddc 100644 --- a/test/helpers/increaseTime.js +++ b/test/helpers/increaseTime.js @@ -32,7 +32,7 @@ export default function increaseTime(duration) { * @param target time in seconds */ export function increaseTimeTo(target) { - let now = latestTime().unix(); + let now = latestTime(); if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`); let diff = target - now; return increaseTime(diff); @@ -43,5 +43,6 @@ 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) }, + years: function(val) { return val * this.days(365)} }; \ No newline at end of file diff --git a/test/helpers/latestTime.js b/test/helpers/latestTime.js index 1461a227cc3..bdc97053aa5 100644 --- a/test/helpers/latestTime.js +++ b/test/helpers/latestTime.js @@ -1,6 +1,4 @@ -import moment from 'moment' - -// Returns a moment.js instance representing the time of the last mined block +// Returns the time of the last mined block in seconds export default function latestTime() { - return moment.unix(web3.eth.getBlock('latest').timestamp) + return web3.eth.getBlock('latest').timestamp; } diff --git a/yarn.lock b/yarn.lock index 007160c50d5..a2b96f077f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2706,10 +2706,6 @@ mocha@^3.4.2: mkdirp "0.5.1" supports-color "3.1.2" -moment@^2.18.1: - version "2.18.1" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f" - ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"