forked from Layr-Labs/eigenlayer-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeMachine.t.sol
51 lines (41 loc) · 1.71 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;
import "forge-std/Test.sol";
import "src/test/utils/Logger.t.sol";
contract TimeMachine is Test, Logger {
uint256[] public snapshots;
function NAME() public view virtual override returns (string memory) {
return "TimeMachine";
}
/// -----------------------------------------------------------------------
/// Setters
/// -----------------------------------------------------------------------
function createSnapshot() public returns (uint256 snapshot) {
snapshots.push(snapshot = cheats.snapshotState());
print.method("createSnapshot", cheats.toString(snapshot));
}
function travelToLast() public returns (uint256 currentSnapshot) {
// Safety check to make sure createSnapshot is called before attempting
// to warp so we don't accidentally prevent our own births.
assertTrue(pastExists(), "Global.warpToPast: invalid usage, past does not exist");
uint256 last = lastSnapshot();
print.method("travelToLast", cheats.toString(last));
currentSnapshot = createSnapshot();
cheats.revertToState(last);
}
function travel(
uint256 snapshot
) public {
print.method("travel", cheats.toString(snapshot));
cheats.revertToState(snapshot);
}
/// -----------------------------------------------------------------------
/// Getters
/// -----------------------------------------------------------------------
function lastSnapshot() public view returns (uint256) {
return snapshots[snapshots.length - 1];
}
function pastExists() public view returns (bool) {
return snapshots.length != 0;
}
}