Hi everyone,
I am dealing with a situation here:
How will I create a timeTravel function that will increase the time in the EVM and mine blocks?
I tried this:
timeTravelFunction
async function timeTravel(){
await advanceTime(travelTime);
await advanceBlock();
return Promise.resolve(web3.eth.getBlock('latest'));
}
let travelTime = 1000;
advanceTime = (travelTime) => {
return new Promise((resolve, reject) => {
web3.currentProvider.sendAsync({
jsonrpc: "2.0",
method: "evm_increaseTime",
params: [travelTime],
id: new Date().getTime()
}, (err, result) => {
if (err) { return reject(err); }
return resolve(result);
});
});
}
advanceBlock = () => {
return new Promise((resolve, reject) => {
web3.currentProvider.sendAsync({
jsonrpc: "2.0",
method: "evm_mine",
id: new Date().getTime()
}, (err, result) => {
if (err) { return reject(err); }
const newBlockHash = web3.eth.getBlock('latest').hash;
return resolve(newBlockHash)
});
});
}
but got this error: