From e86ac90853649808b56ee675d8399cbb61c007a0 Mon Sep 17 00:00:00 2001 From: Jakub Wojciechowski Date: Mon, 14 Aug 2017 00:27:09 +0200 Subject: [PATCH] Refactor and remove moment.js usages --- test/CappedCrowdsale.js | 2 +- test/Crowdsale.js | 2 +- test/FinalizableCrowdsale.js | 2 +- test/RefundableCrowdsale.js | 2 +- test/SampleCrowdsale.js | 2 +- test/TokenTimelock.js | 2 +- test/helpers/increaseTime.js | 2 +- test/helpers/latestTime.js | 6 ++---- 8 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/CappedCrowdsale.js b/test/CappedCrowdsale.js index 9dd027b35..c3a7458ea 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 e3abe1975..3294818a2 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 a7e76bfbf..b138ec36d 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 d3150a94f..ce9515bb6 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 b17c15aeb..709c4bebd 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 8dd1a335a..bbe431d3d 100644 --- a/test/TokenTimelock.js +++ b/test/TokenTimelock.js @@ -18,7 +18,7 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) { beforeEach(async function () { this.token = await MintableToken.new({from: owner}) - this.releaseTime = latestTime().unix() + duration.years(1) + 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}) }) diff --git a/test/helpers/increaseTime.js b/test/helpers/increaseTime.js index 9d9f0d094..2b5511215 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); diff --git a/test/helpers/latestTime.js b/test/helpers/latestTime.js index 1461a227c..bdc97053a 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; }