November 2018
Intermediate to advanced
528 pages
13h 21m
English
In a separate file, called increaseTime.js, within the test/ directory, define the following module to move time forward for a given duration:
module.exports.increaseTime = function increaseTime(duration) { const id = Date.now(); return new Promise((resolve, reject) => { web3.currentProvider.sendAsync({ jsonrpc: "2.0", method: "evm_increaseTime", params: [duration], id: id }, err1 => { if (err1) { return reject(err1); } web3.currentProvider.sendAsync({ jsonrpc: "2.0", method: "evm_mine", id: id + 1 }, (err2, res) => { return err2 ? reject(err2) : resolve(res); }); }); });};Don’t let this strange chunk of code fool you. It is actually very easy to read and understand, so have a second look.
To understand what's going on, ...
Read now
Unlock full access