Browse Source

Merge pull request #368 from jakub-wojciechowski/master

Remove moment.js dependencies
Francisco Giordano 8 years ago
parent
commit
0ed98ea9b9

+ 0 - 1
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"

+ 1 - 1
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)

+ 1 - 1
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)
 

+ 1 - 1
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)
 

+ 1 - 1
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)
 

+ 1 - 1
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);
 

+ 6 - 7
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)

+ 3 - 2
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)} 
 };

+ 2 - 4
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;
 }

+ 0 - 4
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"