import { network } from 'hardhat' ; export const advanceTimeAndBlock = async ( time ) : Promise < void > => { await advanceTime ( time ) ; await advanceBlock ( ) ; } ; export const advanceToTimeAndBlock = async ( time ) : Promise < void > => { await advanceToTime ( time ) ; await advanceBlock ( ) ; } ; export const advanceTime = async ( time ) : Promise < void > => { await network . provider . request ( { method : 'evm_increaseTime' , params : [ time ] , } ) ; } ; export const advanceToTime = async ( time ) : Promise < void > => { await network . provider . request ( { method : 'evm_setNextBlockTimestamp' , params : [ time ] , } ) ; } ; export const advanceBlock = async ( ) => { await network . provider . request ( { method : 'evm_mine' , params : [ ] , } ) ; } ; export const reset = async ( forking ? ) => { const params = forking ? [ { forking } ] : [ ] ; await network . provider . request ( { method : 'hardhat_reset' , params , } ) ; } ; class SnapshotManager { snapshots : { [ id ] : string ; } = { } ; async take ( ) { const id = await this . takeSnapshot ( ) ; this . snapshots [ id ] = id ; return id ; } async revert ( id ) { await this . revertSnapshot ( this . snapshots [ id ] ) ; this . snapshots [ id ] = await this . takeSnapshot ( ) ; } private async takeSnapshot ( ) { return ( await network . provider . request ( { method : 'evm_snapshot' , params : [ ] , } ) ) as string ; } private async revertSnapshot ( id ) { await network . provider . request ( { method : 'evm_revert' , params : [ id ] , } ) ; } } export const snapshot = new SnapshotManager ( ) ;