Skip to content

Commit

Permalink
Make time helper tests more robust by giving a bit of leeway (#381)
Browse files Browse the repository at this point in the history
I think if there's a split second change between the requests for time, we get back different values.

It should never be more than one second off.
  • Loading branch information
sohkai committed Aug 21, 2018
1 parent 7090b7c commit d07e4a1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/time_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ contract('TimeHelpers test', accounts => {
})

it('checks time stamp', async () => {
assert.equal((await timeHelpersMock.getTimestampExt.call()).toString(), (await timeHelpersMock.getTimestamp64Ext.call()).toString(), "time stamps should match")
assert.equal((await timeHelpersMock.getTimestampExt.call()).toString(), (await timeHelpersMock.getTimestampDirect.call()).toString(), "time stamp should match with real one")
const timestamp = await timeHelpersMock.getTimestampExt.call()
const timestamp64 = await timeHelpersMock.getTimestamp64Ext.call()
const timestampReal = await timeHelpersMock.getTimestampDirect.call()

const timestamp64Diff = timestamp64.minus(timestamp)
const timestampRealDiff = timestampReal.minus(timestamp)
assert.isTrue(timestamp64Diff.lessThanOrEqualTo(1), "time stamps should match (or be very close to)")
assert.isTrue(timestampRealDiff.lessThanOrEqualTo(1), "time stamp should match with real one (or be very close to)")
})
})

0 comments on commit d07e4a1

Please sign in to comment.