1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ pragma solidity ^ 0.8.27 ;
3
+
4
+ import "forge-std/Test.sol " ;
5
+ import "src/contracts/libraries/Snapshots.sol " ;
6
+
7
+ contract SnapshotsUnitTests is Test {
8
+ using Snapshots for Snapshots.DefaultWadHistory;
9
+
10
+ Snapshots.DefaultWadHistory history;
11
+
12
+ function test_Revert_InvalidSnapshotOrdering (uint256 r ) public {
13
+ uint32 key = uint32 (bound (r, 1 , type (uint32 ).max));
14
+ uint32 smallerKey = uint32 (bound (r, 0 , key - 1 ));
15
+
16
+ history.push (key, 1 );
17
+
18
+ vm.expectRevert (Snapshots.InvalidSnapshotOrdering.selector );
19
+ history.push (smallerKey, 2 );
20
+ }
21
+
22
+ function test_Push_Correctness (uint256 r ) public {
23
+ uint32 key = uint32 (bound (r, 0 , type (uint32 ).max));
24
+ uint64 value = uint32 (bound (r, 0 , type (uint64 ).max));
25
+
26
+ history.push (key, value);
27
+
28
+ assertEq (history.upperLookup (key), value);
29
+ assertEq (history.latest (), value);
30
+ assertEq (history.length (), 1 );
31
+ }
32
+
33
+ function test_UpperLookup_InitiallyWad (uint32 r ) public {
34
+ assertEq (history.upperLookup (r), 1e18 );
35
+ }
36
+
37
+ function test_Latest_InitiallyWad () public {
38
+ assertEq (history.latest (), 1e18 );
39
+ }
40
+
41
+ function test_Length_InitiallyZero () public {
42
+ assertEq (history.length (), 0 );
43
+ }
44
+ }
0 commit comments