-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move project to foundry template and introduce tests
This commit does a couple of things: - moves the project to our foundry template structure and workflows - removes hardhat usage and dependencies - removes unused contracts - ports existing JS tests to foundry tests - adds additional tests for `CommunityERC20` contract - Introduces deploy scripts written in solidity which are also covered by tests The projects can now be build and tests with: ``` $ forge build ``` ``` $ forge test ``` Test deployments can be done via ``` $ forge script script/DeployOwnerToken.sol ```
- Loading branch information
Showing
54 changed files
with
1,335 additions
and
8,915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# EditorConfig http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# All files | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.sol] | ||
indent_size = 4 | ||
|
||
[*.tree] | ||
indent_size = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY" | ||
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN" | ||
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN" | ||
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN" | ||
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN" | ||
export API_KEY_INFURA="YOUR_API_KEY_INFURA" | ||
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN" | ||
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN" | ||
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE" | ||
export MNEMONIC="YOUR_MNEMONIC" | ||
export FOUNDRY_PROFILE="default" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CollectibleV1Test:test_Deployment() (gas: 38626) | ||
CommunityERC20Test:test_Deployment() (gas: 29720) | ||
MintToTest:test_Deployment() (gas: 29742) | ||
MintToTest:test_Deployment() (gas: 38626) | ||
MintToTest:test_Deployment() (gas: 85415) | ||
MintToTest:test_MintTo() (gas: 509977) | ||
MintToTest:test_RevertWhen_AddressesAndAmountsAreNotEqualLength() (gas: 24193) | ||
MintToTest:test_RevertWhen_MaxSupplyIsReached() (gas: 23267) | ||
MintToTest:test_RevertWhen_MaxSupplyIsReached() (gas: 505463) | ||
MintToTest:test_RevertWhen_MaxSupplyReached() (gas: 123426) | ||
MintToTest:test_RevertWhen_SenderIsNotOwner() (gas: 36358) | ||
OwnerTokenTest:test_Deployment() (gas: 85415) | ||
RemoteBurnTest:test_Deployment() (gas: 38626) | ||
RemoteBurnTest:test_Deployment() (gas: 85437) | ||
RemoteBurnTest:test_RemoteBurn() (gas: 455285) | ||
RemoteBurnTest:test_RevertWhen_RemoteBurn() (gas: 19499) | ||
RemoteBurnTest:test_RevertWhen_SenderIsNotOwner() (gas: 25211) | ||
SetMaxSupplyTest:test_Deployment() (gas: 29720) | ||
SetMaxSupplyTest:test_Deployment() (gas: 85437) | ||
SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 16521) | ||
SetMaxSupplyTest:test_RevertWhen_MaxSupplyLowerThanTotalSupply() (gas: 149095) | ||
SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 12852) | ||
SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 17335) | ||
SetMaxSupplyTest:test_SetMaxSupply() (gas: 15597) | ||
SetSignerPublicKeyTest:test_Deployment() (gas: 85415) | ||
SetSignerPublicKeyTest:test_RevertWhen_SenderIsNotOwner() (gas: 18036) | ||
SetSignerPublicKeyTest:test_SetSignerPublicKey() (gas: 26357) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib/** linguist-vendored | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Description | ||
|
||
Describe the changes made in your pull request here. | ||
|
||
## Checklist | ||
|
||
Ensure you completed **all of the steps** below before submitting your pull request: | ||
|
||
- [ ] Added natspec comments? | ||
- [ ] Ran `forge snapshot`? | ||
- [ ] Ran `pnpm lint`? | ||
- [ ] Ran `forge test`? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,94 @@ | ||
name: CI | ||
name: "CI" | ||
|
||
env: | ||
API_KEY_ALCHEMY: ${{ secrets.API_KEY_ALCHEMY }} | ||
FOUNDRY_PROFILE: "ci" | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
- "main" | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
lint: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v3" | ||
with: | ||
submodules: recursive | ||
submodules: "recursive" | ||
|
||
- name: "Install Foundry" | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
- name: "Install Pnpm" | ||
uses: "pnpm/action-setup@v2" | ||
with: | ||
version: nightly | ||
version: "8" | ||
|
||
- name: Run Forge build | ||
- name: "Install Node.js" | ||
uses: "actions/setup-node@v3" | ||
with: | ||
cache: "pnpm" | ||
node-version: "lts/*" | ||
|
||
- name: "Install the Node.js dependencies" | ||
run: "pnpm install" | ||
|
||
- name: "Lint the contracts" | ||
run: "pnpm lint" | ||
|
||
- name: "Add lint summary" | ||
run: | | ||
forge --version | ||
forge build --sizes | ||
id: build | ||
echo "## Lint result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | ||
build: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v3" | ||
with: | ||
submodules: "recursive" | ||
|
||
- name: "Install Foundry" | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: "Build the contracts and print their size" | ||
run: "forge build --sizes" | ||
|
||
- name: "Add build summary" | ||
run: | | ||
echo "## Build result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | ||
test: | ||
needs: ["lint", "build"] | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v3" | ||
with: | ||
submodules: "recursive" | ||
|
||
- name: "Install Foundry" | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: "Show the Foundry config" | ||
run: "forge config" | ||
|
||
- name: "Generate a fuzz seed that changes weekly to avoid burning through RPC allowance" | ||
run: > | ||
echo "FOUNDRY_FUZZ_SEED=$( | ||
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800)) | ||
)" >> $GITHUB_ENV | ||
- name: "Run the tests" | ||
run: "forge test" | ||
|
||
- name: Run Forge tests | ||
- name: "Add test summary" | ||
run: | | ||
forge test -vvv | ||
id: test | ||
echo "## Tests result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
|
||
# directories | ||
cache | ||
node_modules | ||
.env | ||
out | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
#Hardhat files | ||
cache | ||
artifacts | ||
.certora_internal | ||
|
||
# files | ||
*.env | ||
*.log | ||
.DS_Store | ||
.pnp.* | ||
lcov.info | ||
yarn.lock | ||
|
||
# broadcasts | ||
!broadcast | ||
broadcast/* | ||
broadcast/*/31337/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# directories | ||
broadcast | ||
cache | ||
lib | ||
node_modules | ||
out | ||
|
||
# files | ||
*.env | ||
*.log | ||
.DS_Store | ||
.pnp.* | ||
lcov.info | ||
package-lock.json | ||
pnpm-lock.yaml | ||
yarn.lock | ||
|
||
package.json | ||
.solhint.json | ||
slither.config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"code-complexity": ["error", 8], | ||
"compiler-version": ["error", ">=0.8.17"], | ||
"func-name-mixedcase": "off", | ||
"func-visibility": ["error", { "ignoreConstructors": true }], | ||
"max-line-length": ["error", 120], | ||
"named-parameters-mapping": "warn", | ||
"no-console": "off", | ||
"not-rely-on-time": "off" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Protocol properties and invariants | ||
|
||
Below is a list of all documented properties and invariants of this project that must hold true. | ||
|
||
- **Property** - Describes the property of the project / protocol that should ultimately be tested and formaly verified. | ||
- **Type** - Properties are split into 5 main types: **Valid State**, **State Transition**, **Variable Transition**, | ||
**High-Level Property**, **Unit Test** | ||
- **Risk** - One of **High**, **Medium** and **Low**, depending on the property's risk factor | ||
- **Tested** - Whether this property has been (fuzz) tested | ||
|
||
| **Property** | **Type** | **Risk** | **Tested** | | ||
| ------------ | -------- | -------- | ---------- | | ||
| | | | | | ||
| | | | | | ||
| | | | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,88 @@ | ||
# Sample Hardhat Project | ||
# Communities Contracts [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. | ||
[gha]: https://github.com/status-im/communities-contracts/actions | ||
[gha-badge]: https://github.com/status-im/communities-contracts/actions/workflows/ci.yml/badge.svg | ||
[foundry]: https://getfoundry.sh/ | ||
[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg | ||
|
||
Try running some of the following tasks: | ||
## Usage | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat node | ||
npx hardhat run scripts/deploy.ts | ||
This is a list of the most frequently needed commands. | ||
|
||
### Build | ||
|
||
Build the contracts: | ||
|
||
```sh | ||
$ forge build | ||
``` | ||
|
||
### Clean | ||
|
||
Delete the build artifacts and cache directories: | ||
|
||
```sh | ||
$ forge clean | ||
``` | ||
|
||
### Compile | ||
|
||
Compile the contracts: | ||
|
||
```sh | ||
$ forge build | ||
``` | ||
|
||
### Coverage | ||
|
||
Get a test coverage report: | ||
|
||
```sh | ||
$ forge coverage | ||
``` | ||
|
||
### Deploy | ||
|
||
Deploy to Anvil: | ||
|
||
```sh | ||
$ forge script script/DeployOwnerToken.s.sol --broadcast --fork-url http://localhost:8545 | ||
``` | ||
|
||
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid | ||
[BIP39 mnemonic](https://iancoleman.io/bip39/). | ||
|
||
For instructions on how to deploy to a testnet or mainnet, check out the | ||
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial. | ||
|
||
### Format | ||
|
||
Format the contracts: | ||
|
||
```sh | ||
$ forge fmt | ||
``` | ||
|
||
### Gas Usage | ||
|
||
Get a gas report: | ||
|
||
```sh | ||
$ forge test --gas-report | ||
``` | ||
|
||
### Lint | ||
|
||
Lint the contracts: | ||
|
||
```sh | ||
$ pnpm lint | ||
``` | ||
|
||
### Test | ||
|
||
Run the tests: | ||
|
||
```sh | ||
$ forge test | ||
``` |
Oops, something went wrong.