File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ import {
2+ Web3
3+ } from "@daostack/arc.js" ;
4+
5+ /**
6+ * increase ganache time by the given number of seconds
7+ * @param web3
8+ * @param networkName
9+ * @param seconds
10+ */
11+ export const run = async (
12+ web3 : Web3 ,
13+ networkName : string ,
14+ seconds : string ) : Promise < void > => {
15+
16+ if ( networkName !== "Ganache" ) {
17+ throw new Error ( "Only works on Ganache" ) ;
18+ }
19+
20+ const id = new Date ( ) . getTime ( ) ;
21+
22+ console . log ( `advancing time by (at least) ${ seconds } seconds` ) ;
23+
24+ return new Promise ( ( resolve : ( res : any ) => any , reject : ( err : any ) => any ) : void => {
25+
26+ web3 . currentProvider . sendAsync ( {
27+ id,
28+ jsonrpc : "2.0" ,
29+ method : "evm_increaseTime" ,
30+ params : [ Number . parseInt ( seconds ) ] ,
31+ } , ( err1 : any ) => {
32+ if ( err1 ) { return reject ( err1 ) ; }
33+
34+ web3 . currentProvider . sendAsync ( {
35+ id : id + 1 ,
36+ jsonrpc : "2.0" ,
37+ method : "evm_mine" ,
38+ } , ( err2 : any , res : any ) : void => {
39+ return err2 ? reject ( err2 ) : resolve ( res ) ;
40+ } ) ;
41+ } ) ;
42+ } ) ;
43+
44+ return Promise . resolve ( ) ;
45+ }
You can’t perform that action at this time.
0 commit comments