Skip to content

Commit

Permalink
Merge pull request #368 from jakub-wojciechowski/master
Browse files Browse the repository at this point in the history
Remove moment.js dependencies
  • Loading branch information
frangio authored Aug 16, 2017
2 parents 0b66144 + 0d6846a commit 0ed98ea
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 23 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/CappedCrowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/Crowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/FinalizableCrowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/RefundableCrowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/SampleCrowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 6 additions & 7 deletions test/TokenTimelock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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})
})
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/increaseTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)}
};
6 changes: 2 additions & 4 deletions test/helpers/latestTime.js
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0ed98ea

Please sign in to comment.