forked from Layr-Labs/eigenlayer-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeMachine.t.sol
45 lines (35 loc) · 1.3 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
// 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;
uint64 public proofGenStartTime;
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, "Global.warpToPast: invalid usage, past does not exist");
curState = cheats.snapshot();
cheats.revertTo(lastSnapshot);
return curState;
}
function warpToPresent(uint curState) public {
cheats.revertTo(curState);
}
/// @dev Sets the timestamp we use for proof gen to now,
/// then sets block timestamp to now + secondsAgo.
///
/// This means we can create mock proofs using an oracle time
/// of `proofGenStartTime`.
function setProofGenStartTime(uint secondsAgo) public {
proofGenStartTime = uint64(block.timestamp);
cheats.warp(block.timestamp + secondsAgo);
}
}