Skip to content

Commit 49f5bbe

Browse files
JGcarvLucas Manuel
and
Lucas Manuel
authored
chore: Switch to Foundry (SC-4852) (#14)
* feat: switched to forge * added EOF lines * remove circle ci * adjust slither file * adjust PR issues * fix: update test.sh * fix: update runs, test.sh * formatting: rm extra line Co-authored-by: Lucas Manuel <[email protected]>
1 parent d9dbcfa commit 49f5bbe

File tree

13 files changed

+251
-152
lines changed

13 files changed

+251
-152
lines changed

.circleci/config.yml

-24
This file was deleted.

.github/workflows/pull-request.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Basic PR Tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
run-ci:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: Install Foundry
12+
uses: onbjerg/foundry-toolchain@v1
13+
with:
14+
version: nightly
15+
16+
- name: Pull library deps
17+
run: forge update
18+
19+
- name: Run forge tests
20+
run: ./test.sh -p deep

.github/workflows/push-to-main.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 50k fuzz run test on push to main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
run-ci:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Install Foundry
15+
uses: onbjerg/foundry-toolchain@v1
16+
with:
17+
version: nightly
18+
19+
- name: Pull library deps
20+
run: forge update
21+
22+
- name: Run forge tests
23+
run: ./test.sh -p super_deep

.github/workflows/slither.yaml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Static Analysis
2+
on:
3+
push:
4+
branches: "*"
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.8
17+
18+
- name: Install dependencies
19+
run: |
20+
sudo snap install solc
21+
python -m pip install --upgrade pip
22+
pip install slither-analyzer==0.8.2 solc-select==0.2.1
23+
solc-select install 0.8.7
24+
solc-select use 0.8.7
25+
26+
- name: Install submodules
27+
run: |
28+
git config --global url."https://github.com/".insteadOf "[email protected]:"
29+
git submodule update --init --recursive
30+
31+
- name: Summary of static analysis
32+
run: |
33+
slither contracts --print human-summary
34+
35+
- name: Contract summary of static analysis
36+
run: |
37+
slither contracts --print contract-summary
38+
39+
- name: Function summary
40+
run: |
41+
slither contracts --print function-summary
42+
43+
- name: Inheritance
44+
run: |
45+
slither contracts --print inheritance
46+
47+
- name: Data dependency
48+
run: |
49+
slither contracts --print data-dependency
50+
51+
- name: Static Analysis
52+
run: |
53+
slither contracts
54+
continue-on-error: true

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ hevm*
44
artifacts/*
55
docs/*
66
metadata.json
7+
/out
8+
/cache

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This was intentional, as this ERC-20 was intended to have the minimum functional
1717
To clone, set up and run tests:
1818
```
1919
git clone [email protected]:maple-labs/ERC20.git
20-
dapp update
20+
forge update
2121
make test
2222
```
2323

config/ci.json

-29
This file was deleted.

config/dev.json

-28
This file was deleted.

config/prod.json

-33
This file was deleted.

contracts/test/ERC20.t.sol

+45-17
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import { DSTest } from "../../modules/ds-test/src/test.sol";
55

66
import { ERC20User } from "./accounts/ERC20User.sol";
77
import { MockERC20 } from "./mocks/MockERC20.sol";
8+
89
import { InvariantTest } from "./utils/InvariantTest.sol";
10+
import { Vm } from "./utils/Vm.sol";
911

1012
contract ERC20Test is DSTest {
1113

14+
Vm vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
15+
16+
bytes constant ARITHMETIC_ERROR = abi.encodeWithSignature("Panic(uint256)", 0x11);
17+
1218
MockERC20 token;
1319

1420
address internal immutable self = address(this);
@@ -31,14 +37,14 @@ contract ERC20Test is DSTest {
3137
assertEq(mockToken.decimals(), decimals);
3238
}
3339

34-
function prove_mint(address account, uint256 amount) public {
40+
function test_mint(address account, uint256 amount) public {
3541
token.mint(account, amount);
3642

3743
assertEq(token.totalSupply(), amount);
3844
assertEq(token.balanceOf(account), amount);
3945
}
4046

41-
function prove_burn(address account, uint256 amount0, uint256 amount1) public {
47+
function test_burn(address account, uint256 amount0, uint256 amount1) public {
4248
if (amount1 > amount0) return; // Mint amount must exceed burn amount.
4349

4450
token.mint(account, amount0);
@@ -48,13 +54,13 @@ contract ERC20Test is DSTest {
4854
assertEq(token.balanceOf(account), amount0 - amount1);
4955
}
5056

51-
function prove_approve(address account, uint256 amount) public {
57+
function test_approve(address account, uint256 amount) public {
5258
assertTrue(token.approve(account, amount));
5359

5460
assertEq(token.allowance(self, account), amount);
5561
}
5662

57-
function prove_transfer(address account, uint256 amount) public {
63+
function test_transfer(address account, uint256 amount) public {
5864
token.mint(self, amount);
5965

6066
assertTrue(token.transfer(account, amount));
@@ -69,7 +75,7 @@ contract ERC20Test is DSTest {
6975
}
7076
}
7177

72-
function prove_transferFrom(address to, uint256 approval, uint256 amount) public {
78+
function test_transferFrom(address to, uint256 approval, uint256 amount) public {
7379
if (amount > approval) return; // Owner must approve for more than amount.
7480

7581
ERC20User owner = new ERC20User();
@@ -93,33 +99,55 @@ contract ERC20Test is DSTest {
9399
}
94100
}
95101

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;
98104

99105
ERC20User account = new ERC20User();
100106

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);
103116
}
104117

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;
107120

108121
ERC20User owner = new ERC20User();
109122

110123
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);
112128
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);
113134
}
114135

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;
117138

118139
ERC20User owner = new ERC20User();
119140

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);
123151
}
124152

125153
}

0 commit comments

Comments
 (0)