Refactor and remove moment.js usages

This commit is contained in:
Jakub Wojciechowski
2017-08-14 00:27:09 +02:00
parent 99e0f5b5cb
commit e86ac90853
8 changed files with 9 additions and 11 deletions

View File

@ -27,7 +27,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
}) })
beforeEach(async function () { beforeEach(async function () {
this.startTime = latestTime().unix() + duration.weeks(1); this.startTime = latestTime() + duration.weeks(1);
this.endTime = this.startTime + duration.weeks(1); this.endTime = this.startTime + duration.weeks(1);
this.crowdsale = await CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, cap) this.crowdsale = await CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, cap)

View File

@ -27,7 +27,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
}) })
beforeEach(async function () { beforeEach(async function () {
this.startTime = latestTime().unix() + duration.weeks(1); this.startTime = latestTime() + duration.weeks(1);
this.endTime = this.startTime + duration.weeks(1); this.endTime = this.startTime + duration.weeks(1);
this.afterEndTime = this.endTime + duration.seconds(1) this.afterEndTime = this.endTime + duration.seconds(1)

View File

@ -23,7 +23,7 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
}) })
beforeEach(async function () { beforeEach(async function () {
this.startTime = latestTime().unix() + duration.weeks(1) this.startTime = latestTime() + duration.weeks(1)
this.endTime = this.startTime + duration.weeks(1) this.endTime = this.startTime + duration.weeks(1)
this.afterEndTime = this.endTime + duration.seconds(1) this.afterEndTime = this.endTime + duration.seconds(1)

View File

@ -25,7 +25,7 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
}) })
beforeEach(async function () { beforeEach(async function () {
this.startTime = latestTime().unix() + duration.weeks(1) this.startTime = latestTime() + duration.weeks(1)
this.endTime = this.startTime + duration.weeks(1) this.endTime = this.startTime + duration.weeks(1)
this.afterEndTime = this.endTime + duration.seconds(1) this.afterEndTime = this.endTime + duration.seconds(1)

View File

@ -26,7 +26,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
}) })
beforeEach(async function () { beforeEach(async function () {
this.startTime = latestTime().unix() + duration.weeks(1); this.startTime = latestTime() + duration.weeks(1);
this.endTime = this.startTime + duration.weeks(1); this.endTime = this.startTime + duration.weeks(1);
this.afterEndTime = this.endTime + duration.seconds(1); this.afterEndTime = this.endTime + duration.seconds(1);

View File

@ -18,7 +18,7 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
beforeEach(async function () { beforeEach(async function () {
this.token = await MintableToken.new({from: owner}) 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) this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime)
await this.token.mint(this.timelock.address, amount, {from: owner}) await this.token.mint(this.timelock.address, amount, {from: owner})
}) })

View File

@ -32,7 +32,7 @@ export default function increaseTime(duration) {
* @param target time in seconds * @param target time in seconds
*/ */
export function increaseTimeTo(target) { 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})`); if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`);
let diff = target - now; let diff = target - now;
return increaseTime(diff); return increaseTime(diff);

View File

@ -1,6 +1,4 @@
import moment from 'moment' // Returns the time of the last mined block in seconds
// Returns a moment.js instance representing the time of the last mined block
export default function latestTime() { export default function latestTime() {
return moment.unix(web3.eth.getBlock('latest').timestamp) return web3.eth.getBlock('latest').timestamp;
} }