-
Notifications
You must be signed in to change notification settings - Fork 350
/
Copy pathStdError.t.sol
120 lines (95 loc) · 2.66 KB
/
StdError.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import {stdError} from "../src/StdError.sol";
import {Test} from "../src/Test.sol";
contract StdErrorsTest is Test {
ErrorsTest test;
function setUp() public {
test = new ErrorsTest();
}
function test_RevertIf_AssertionError() public {
vm.expectRevert(stdError.assertionError);
test.assertionError();
}
function test_RevertIf_ArithmeticError() public {
vm.expectRevert(stdError.arithmeticError);
test.arithmeticError(10);
}
function test_RevertIf_DivisionError() public {
vm.expectRevert(stdError.divisionError);
test.divError(0);
}
function test_RevertIf_ModError() public {
vm.expectRevert(stdError.divisionError);
test.modError(0);
}
function test_RevertIf_EnumConversionError() public {
vm.expectRevert(stdError.enumConversionError);
test.enumConversion(1);
}
function test_RevertIf_EncodeStgError() public {
vm.expectRevert(stdError.encodeStorageError);
test.encodeStgError();
}
function test_RevertIf_PopError() public {
vm.expectRevert(stdError.popError);
test.pop();
}
function test_RevertIf_IndexOOBError() public {
vm.expectRevert(stdError.indexOOBError);
test.indexOOBError(1);
}
function test_RevertIf_MemOverflowError() public {
vm.expectRevert(stdError.memOverflowError);
test.mem();
}
function test_RevertIf_InternError() public {
vm.expectRevert(stdError.zeroVarError);
test.intern();
}
}
contract ErrorsTest {
enum T {
T1
}
uint256[] public someArr;
bytes someBytes;
function assertionError() public pure {
assert(false);
}
function arithmeticError(uint256 a) public pure {
a -= 100;
}
function divError(uint256 a) public pure {
100 / a;
}
function modError(uint256 a) public pure {
100 % a;
}
function enumConversion(uint256 a) public pure {
T(a);
}
function encodeStgError() public {
/// @solidity memory-safe-assembly
assembly {
sstore(someBytes.slot, 1)
}
keccak256(someBytes);
}
function pop() public {
someArr.pop();
}
function indexOOBError(uint256 a) public pure {
uint256[] memory t = new uint256[](0);
t[a];
}
function mem() public pure {
uint256 l = 2 ** 256 / 32;
new uint256[](l);
}
function intern() public returns (uint256) {
function(uint256) internal returns (uint256) x;
x(2);
return 7;
}
}