-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathERC20.t.sol.gyb
164 lines (130 loc) · 4.24 KB
/
ERC20.t.sol.gyb
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
%{
import yaml
with open('../test-cases.yml', 'r') as file:
config = yaml.safe_load(file)
contracts = config["contracts"]
}%
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;
import {DSTest} from "@ds-test/test.sol";
import {Vm} from "@forge-std/Vm.sol";
% for variation in contracts["erc20"]["variations"]:
import {ERC20_${variation}} from "$/ERC20_${variation}.sol";
% end
% for variation in contracts["erc20"]["variations"]:
// deploy
contract ERC20_${variation}_deploy_Test is DSTest {
function test_deploy() public {
ERC20_${variation} sut = new ERC20_${variation}();
}
}
// transferToNonOwner
contract ERC20_${variation}_transferToNonOwner_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
}
function test_transferToNonOwner() public {
HEVM.prank(address(0xAAAA));
sut.transfer(address(0xBBBB), 500 ether);
}
}
// transferToOwner
contract ERC20_${variation}_transferToOwner_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
sut.mint(address(0xBBBB), 1000 ether);
}
function test_transferToOwner() public {
HEVM.prank(address(0xAAAA));
sut.transfer(address(0xBBBB), 500 ether);
}
}
// transferFromToNonOwner
contract ERC20_${variation}_transferFromToNonOwner_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
HEVM.prank(address(0xAAAA));
sut.approve(address(0xBBBB), 1000 ether);
}
function test_transferFromToNonOwner() public {
HEVM.prank(address(0xBBBB));
sut.transferFrom(address(0xAAAA), address(0xCCCC), 500 ether);
}
}
// transferFromToOwner
contract ERC20_${variation}_transferFromToOwner_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
sut.mint(address(0xCCCC), 1000 ether);
HEVM.prank(address(0xAAAA));
sut.approve(address(0xBBBB), 1000 ether);
}
function test_transferFromToOwner() public {
HEVM.prank(address(0xBBBB));
sut.transferFrom(address(0xAAAA), address(0xCCCC), 500 ether);
}
}
// approve
contract ERC20_${variation}_approve_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
}
function test_approve() public {
HEVM.prank(address(0xAAAA));
sut.approve(address(0xBBBB), 1000 ether);
}
}
// totalSupply
contract ERC20_${variation}_totalSupply_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
}
function test_totalSupply() public view {
sut.totalSupply();
}
}
// balanceOf
contract ERC20_${variation}_balanceOf_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
}
function test_balanceOf() public view {
sut.balanceOf(address(0xAAAA));
}
}
// allowance
contract ERC20_${variation}_allowance_Test is DSTest {
Vm internal constant HEVM = Vm(HEVM_ADDRESS);
ERC20_${variation} internal sut;
function setUp() public {
sut = new ERC20_${variation}();
sut.mint(address(0xAAAA), 1000 ether);
HEVM.prank(address(0xAAAA));
sut.approve(address(0xBBBB), 1000 ether);
}
function test_allowance() public view {
sut.allowance(address(0xAAAA), address(0xBBBB));
}
}
% end