From 07250a3a867b437f198829bb7e36284fd730fd1e Mon Sep 17 00:00:00 2001 From: DeoluA Date: Sun, 4 Jul 2021 15:20:28 +0100 Subject: [PATCH] Update to time.js helper Ran the old code and got the `web3.currentProvider.sendAsync is undefined` error. Research indicates function should now be `web3.currentProvider.send`. Implementing fix with promises. --- lesson-11/chapter-12/test/helpers/time.js | 45 +++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/lesson-11/chapter-12/test/helpers/time.js b/lesson-11/chapter-12/test/helpers/time.js index 730790a..80feff7 100644 --- a/lesson-11/chapter-12/test/helpers/time.js +++ b/lesson-11/chapter-12/test/helpers/time.js @@ -1,22 +1,37 @@ -async function increase(duration) { +// new function: custom_sendAsync +function custom_sendAsync(the_method, the_params){ + return new Promise((resolve, reject) => { + + web3.currentProvider.send({ + jsonrpc: "2.0", + method: the_method, + params: the_params, + id: new Date().getTime() + }, (err, resp) => { + if(!err){ + resolve(resp); + } + else reject(); + }); - //first, let's increase time - await web3.currentProvider.sendAsync({ - jsonrpc: "2.0", - method: "evm_increaseTime", - params: [duration], // there are 86400 seconds in a day - id: new Date().getTime() - }, () => {}); + }) + /* uncomment if you want to catch it here + .catch((caught)=>{ + return(caught); + }); + */ +}; + +// use 'increase' as normal here: +async function increase(duration_value) { + + // first, let's increase time + await custom_sendAsync("evm_increaseTime", [duration_value]); //next, let's mine a new block - web3.currentProvider.send({ - jsonrpc: '2.0', - method: 'evm_mine', - params: [], - id: new Date().getTime() - }) + await custom_sendAsync("evm_mine", []); -} +}; const duration = {