From 8520b8afb4da47b527ec31510b957a4a9075632f Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Tue, 15 May 2018 17:00:40 -0300 Subject: [PATCH] time units + proper handle of incresetime --- utils/testUtils.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/utils/testUtils.js b/utils/testUtils.js index 0186af4..6f0a6df 100644 --- a/utils/testUtils.js +++ b/utils/testUtils.js @@ -187,6 +187,15 @@ exports.promisify = (func) => exports.zeroAddress = '0x0000000000000000000000000000000000000000'; exports.zeroBytes32 = "0x0000000000000000000000000000000000000000000000000000000000000000"; +exports.timeUnits = { + seconds: 1, + minutes: 60, + hours: 60 * 60, + days: 24 * 60 * 60, + weeks: 7 * 24 * 60 * 60, + years: 365 * 24 * 60 * 60 +} + exports.ensureException = function(error) { assert(isException(error), error.toString()); }; @@ -196,7 +205,7 @@ function isException(error) { return strError.includes('invalid opcode') || strError.includes('invalid JUMP') || strError.includes('revert'); } -exports.increaseTime = async (web3, amount) => { +exports.increaseTime = async (amount) => { web3.currentProvider.sendAsync( { jsonrpc: '2.0', @@ -204,9 +213,23 @@ exports.increaseTime = async (web3, amount) => { params: [amount], id: new Date().getSeconds() }, - (err, resp) => { - console.log(err) - console.log(resp) + (error) => { + if(error) { + console.log(error) + } else { + web3.currentProvider.sendAsync( + { + jsonrpc: '2.0', + method: 'evm_mine', + params: [], + id: new Date().getSeconds() + }, (error) => { + if(error) { + console.log(error) + } + } + ) + } } )