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