@@ -5,10 +5,16 @@ import { DSTest } from "../../modules/ds-test/src/test.sol";
5
5
6
6
import { ERC20User } from "./accounts/ERC20User.sol " ;
7
7
import { MockERC20 } from "./mocks/MockERC20.sol " ;
8
+
8
9
import { InvariantTest } from "./utils/InvariantTest.sol " ;
10
+ import { Vm } from "./utils/Vm.sol " ;
9
11
10
12
contract ERC20Test is DSTest {
11
13
14
+ Vm vm = Vm (0x7109709ECfa91a80626fF3989D68f67F5b1DD12D );
15
+
16
+ bytes constant ARITHMETIC_ERROR = abi.encodeWithSignature ("Panic(uint256) " , 0x11 );
17
+
12
18
MockERC20 token;
13
19
14
20
address internal immutable self = address (this );
@@ -31,14 +37,14 @@ contract ERC20Test is DSTest {
31
37
assertEq (mockToken.decimals (), decimals);
32
38
}
33
39
34
- function prove_mint (address account , uint256 amount ) public {
40
+ function test_mint (address account , uint256 amount ) public {
35
41
token.mint (account, amount);
36
42
37
43
assertEq (token.totalSupply (), amount);
38
44
assertEq (token.balanceOf (account), amount);
39
45
}
40
46
41
- function prove_burn (address account , uint256 amount0 , uint256 amount1 ) public {
47
+ function test_burn (address account , uint256 amount0 , uint256 amount1 ) public {
42
48
if (amount1 > amount0) return ; // Mint amount must exceed burn amount.
43
49
44
50
token.mint (account, amount0);
@@ -48,13 +54,13 @@ contract ERC20Test is DSTest {
48
54
assertEq (token.balanceOf (account), amount0 - amount1);
49
55
}
50
56
51
- function prove_approve (address account , uint256 amount ) public {
57
+ function test_approve (address account , uint256 amount ) public {
52
58
assertTrue (token.approve (account, amount));
53
59
54
60
assertEq (token.allowance (self, account), amount);
55
61
}
56
62
57
- function prove_transfer (address account , uint256 amount ) public {
63
+ function test_transfer (address account , uint256 amount ) public {
58
64
token.mint (self, amount);
59
65
60
66
assertTrue (token.transfer (account, amount));
@@ -69,7 +75,7 @@ contract ERC20Test is DSTest {
69
75
}
70
76
}
71
77
72
- function prove_transferFrom (address to , uint256 approval , uint256 amount ) public {
78
+ function test_transferFrom (address to , uint256 approval , uint256 amount ) public {
73
79
if (amount > approval) return ; // Owner must approve for more than amount.
74
80
75
81
ERC20User owner = new ERC20User ();
@@ -93,33 +99,55 @@ contract ERC20Test is DSTest {
93
99
}
94
100
}
95
101
96
- function proveFail_transfer_insufficientBalance (address to , uint256 mintAmount , uint256 sendAmount ) public {
97
- require (mintAmount < sendAmount) ;
102
+ function test_transfer_insufficientBalance (address to , uint256 amount ) public {
103
+ amount = amount == 0 ? 1 : amount ;
98
104
99
105
ERC20User account = new ERC20User ();
100
106
101
- token.mint (address (account), mintAmount);
102
- account.erc20_transfer (address (token), to, sendAmount);
107
+ token.mint (address (account), amount - 1 );
108
+
109
+ vm.expectRevert (ARITHMETIC_ERROR);
110
+ account.erc20_transfer (address (token), to, amount);
111
+
112
+ token.mint (address (account), 1 );
113
+ account.erc20_transfer (address (token), to, amount);
114
+
115
+ assertEq (token.balanceOf (to), amount);
103
116
}
104
117
105
- function proveFail_transferFrom_insufficientAllowance (address to , uint256 approval , uint256 amount ) public {
106
- require (approval < amount) ;
118
+ function test_transferFrom_insufficientAllowance (address to , uint256 amount ) public {
119
+ amount = amount == 0 ? 1 : amount ;
107
120
108
121
ERC20User owner = new ERC20User ();
109
122
110
123
token.mint (address (owner), amount);
111
- owner.erc20_approve (address (token), self, approval);
124
+
125
+ owner.erc20_approve (address (token), self, amount - 1 );
126
+
127
+ vm.expectRevert (ARITHMETIC_ERROR);
112
128
token.transferFrom (address (owner), to, amount);
129
+
130
+ owner.erc20_approve (address (token), self, amount);
131
+ token.transferFrom (address (owner), to, amount);
132
+
133
+ assertEq (token.balanceOf (to), amount);
113
134
}
114
135
115
- function proveFail_transferFrom_insufficientBalance (address to , uint256 mintAmount , uint256 sendAmount ) public {
116
- require (mintAmount < sendAmount) ;
136
+ function test_transferFrom_insufficientBalance (address to , uint256 amount ) public {
137
+ amount = amount == 0 ? 1 : amount ;
117
138
118
139
ERC20User owner = new ERC20User ();
119
140
120
- token.mint (address (owner), mintAmount);
121
- owner.erc20_approve (address (token), self, sendAmount);
122
- token.transferFrom (address (owner), to, sendAmount);
141
+ token.mint (address (owner), amount - 1 );
142
+ owner.erc20_approve (address (token), self, amount);
143
+
144
+ vm.expectRevert (ARITHMETIC_ERROR);
145
+ token.transferFrom (address (owner), to, amount);
146
+
147
+ token.mint (address (owner), 1 );
148
+ token.transferFrom (address (owner), to, amount);
149
+
150
+ assertEq (token.balanceOf (to), amount);
123
151
}
124
152
125
153
}
0 commit comments