forked from Layr-Labs/eigenlayer-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeMachine.t.sol
33 lines (25 loc) · 906 Bytes
/
TimeMachine.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;
import "forge-std/Test.sol";
contract TimeMachine is Test {
Vm cheats = Vm(HEVM_ADDRESS);
bool pastExists = false;
uint lastSnapshot;
function createSnapshot() public returns (uint) {
uint snapshot = cheats.snapshot();
lastSnapshot = snapshot;
pastExists = true;
return snapshot;
}
function warpToLast() public returns (uint curState) {
// Safety check to make sure createSnapshot is called before attempting to warp
// so we don't accidentally prevent our own births
assertTrue(pastExists, "TimeMachine.warpToLast: invalid usage, past does not exist");
curState = cheats.snapshot();
cheats.revertTo(lastSnapshot);
return curState;
}
function warpToPresent(uint curState) public {
cheats.revertTo(curState);
}
}