time units + proper handle of incresetime

This commit is contained in:
Ricardo Guilherme Schmidt 2018-05-15 17:00:40 -03:00
parent a4ab1cbe11
commit 8520b8afb4
1 changed files with 27 additions and 4 deletions

View File

@ -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)
}
}
)
}
}
)