From d07e4a1f7e1e8610328308702add9def94e817c0 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Tue, 21 Aug 2018 21:38:44 +0200 Subject: [PATCH] Make time helper tests more robust by giving a bit of leeway (#381) 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. --- test/time_helpers.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/time_helpers.js b/test/time_helpers.js index 55f795547..a613677bb 100644 --- a/test/time_helpers.js +++ b/test/time_helpers.js @@ -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)") }) })