Skip to content

Commit df00337

Browse files
committed
better foundry opt, tidy some scripts
1 parent b585866 commit df00337

18 files changed

+281
-629
lines changed

.solhint.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "solhint:default",
3+
"rules": {
4+
"max-line-length": ["off", 120]
5+
}
6+
}

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["JuanBlanco.solidity"]
3+
}

.vscode/settings.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"editor.formatOnSave": true
3-
}
2+
"solidity.packageDefaultDependenciesContractsDirectory": "src",
3+
"solidity.packageDefaultDependenciesDirectory": "lib",
4+
"editor.formatOnSave": true,
5+
"[solidity]": {
6+
"editor.defaultFormatter": "JuanBlanco.solidity"
7+
},
8+
"solidity.formatter": "forge"
9+
}

README.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,14 @@ forge install
4545
Compile the contracts with:
4646

4747
```sh
48-
forge clean && forge build
48+
forge build
4949
```
5050

51-
### Upgradability
52-
53-
We are using [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) library. To make sure upgrades are **safe**, you must do one of the following (as per their [docs](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades?tab=readme-ov-file#before-running)) before you run `forge script` or `forge test`:
54-
55-
- `forge clean` beforehand, e.g. `forge clean && forge test`
56-
- include `--force` option when running, e.g. `forge test --force`
57-
5851
> [!NOTE]
5952
>
60-
> Note that for some users this may fail (see [issue](https://github.com/firstbatchxyz/dria-oracle-contracts/issues/16)) due to a missing NPM package called `@openzeppelin/upgrades-core`. To fix it, do:
53+
> We are using [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) library, which [requires](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades?tab=readme-ov-file#before-running) clean-up per compilation to ensure upgrades are done safely. We use `force = true` option in `foundry.toml` for this, which may increase build times.
54+
>
55+
> Note that for some users this may fail (see [issue](https://github.com/firstbatchxyz/dria-oracle-contracts/issues/16)) due to a missing NPM package called `@openzeppelin/upgrades-core`. To fix it, you can install the package manually:
6156
>
6257
> ```sh
6358
> npm install @openzeppelin/upgrades-core@latest -g
@@ -115,7 +110,7 @@ You will use this endpoint for the commands that interact with the blockchain, s
115110
Deploy the contract with:
116111

117112
```sh
118-
forge clean && forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
113+
forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
119114
--rpc-url <RPC_URL> \
120115
--account <WALLET_NAME> \
121116
--broadcast
@@ -126,7 +121,7 @@ You can see deployed contract addresses under the `deployment/<chainid>.json`
126121
You can verify the contract during deployment by adding the verification arguments as well:
127122

128123
```sh
129-
forge clean && forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
124+
forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
130125
--rpc-url <RPC_URL> \
131126
--account <WALLET_NAME> \
132127
--broadcast \
@@ -155,57 +150,79 @@ Note that the `--verifier-url` value should be the target explorer's homepage UR
155150
>
156151
> The `--verifier` can accept any of the following: `etherscan`, `blockscout`, `sourcify`, `oklink`. We are using Blockscout most of the time.
157152
153+
### Generate ABIs
154+
155+
To interact with the contracts, you need the contract ABIs. We store the ABIs under the [`abis`](./abis/) folder, and these can be generated using the following script:
156+
157+
```sh
158+
./export-abis.sh
159+
```
160+
158161
## Testing & Diagnostics
159162

160163
Run tests on local network:
161164

162165
```sh
163-
forge clean && forge test
166+
forge test
164167

165168
# or -vvv to show reverts in detail
166-
forge clean && forge test -vvv
169+
forge test -vvv
167170
```
168171

169172
or fork an existing chain and run the tests on it:
170173

171174
```sh
172-
forge clean && forge test --rpc-url <RPC_URL>
175+
forge test --rpc-url <RPC_URL>
173176
```
174177

175178
### Code Coverage
176179

177180
We have a script that generates the coverage information as an HTML page. This script requires [`lcov`](https://linux.die.net/man/1/lcov) and [`genhtml`](https://linux.die.net/man/1/genhtml) command line tools. To run, do:
178181

179182
```sh
180-
forge clean && ./coverage.sh
183+
./coverage.sh
181184
```
182185

183186
Alternatively, you can see a summarized text-only output as well:
184187

185188
```sh
186-
forge clean && forge coverage --no-match-coverage "(test|mock|script)"
189+
forge coverage --no-match-coverage "(test|mock|script)"
187190
```
188191

189192
### Storage Layout
190193

191-
Get storage layout with:
194+
You can print storage layouts for each contract using:
192195

193196
```sh
194197
./storage.sh
195198
```
196199

197-
You can see storage layouts under the [`storage`](./storage/) directory.
200+
The resulting Markdown files will be created under the [`storage`](./storage/) directory.
198201

199202
### Gas Snapshot
200203

201-
Take the gas snapshot with:
204+
You can examine the gas usage metrics using the command:
202205

203206
```sh
204-
forge clean && forge snapshot
207+
forge snapshot --snap ./test/.gas-snapshot
205208
```
206209

207210
You can see the snapshot `.gas-snapshot` file in the current directory.
208211

212+
### Styling
213+
214+
You can format the contracts with:
215+
216+
```sh
217+
forge fmt ./src/**/*.sol ./script/**/*.sol
218+
```
219+
220+
If you have solhint installed, you can lint all contracts with:
221+
222+
```sh
223+
solhint 'contracts/**/*.sol'
224+
```
225+
209226
## Documentation
210227

211228
We have auto-generated MDBook documentations under the [`docs`](./docs) folder, generated with the following command:
@@ -219,4 +236,4 @@ forge doc --serve
219236

220237
## License
221238

222-
We are using Apache-2.0 license.
239+
We are using [Apache-2.0](./LICENSE) license.

coverage.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ then
1717
exit
1818
fi
1919

20+
# create coverage directory for outputs
21+
mkdir -p coverage
22+
2023
# generate coverage info
2124
forge coverage \
2225
--report lcov \
2326
--report summary \
24-
--no-match-coverage "(test|mock|script)"
27+
--no-match-coverage "(test|mock|script)" \
28+
--report-file ./coverage/lcov.info
2529

2630
# generate HTML report from lcov.info
27-
genhtml lcov.info -o coverage --branch-coverage --ignore-errors inconsistent,category,corrupt
31+
genhtml ./coverage/lcov.info -o coverage --branch-coverage --ignore-errors inconsistent,category,corrupt
2832

2933
# open report
30-
open coverage/index.html
34+
open ./coverage/index.html

foundry.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ test = 'test'
66
script = 'script'
77
cache_path = 'cache'
88

9+
optimizer = true
10+
11+
# required by upgradability
12+
# see: https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
913
ffi = true
1014
ast = true
1115
build_info = true
12-
optimizer = true
1316
extra_output = ["storageLayout"]
1417

18+
# forces recompilation, required by Upgradable contracts
19+
force = true
20+
1521
# fs permissions for deployment (false by default)
1622
fs_permissions = [
1723
{ access = "read", path = "out" },

0 commit comments

Comments
 (0)