Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example foundry package #1287

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
17909e5
chore: forge init
wojciech-turek Nov 6, 2023
5b91b46
forge install: forge-std
wojciech-turek Nov 6, 2023
8753126
forge install: openzeppelin-contracts
wojciech-turek Nov 6, 2023
bb9570b
forge install: openzeppelin-contracts-upgradeable
wojciech-turek Nov 6, 2023
630704f
Add openzeppelin deps
wojciech-turek Nov 6, 2023
b5e7b39
Fix formatting
wojciech-turek Nov 6, 2023
4fd6887
Set the out folder to artifacts
wojciech-turek Nov 7, 2023
51b56a4
Move openzeppelin deps to node modules from lib
wojciech-turek Nov 7, 2023
f30c81f
Add package json
wojciech-turek Nov 7, 2023
a93d32f
Remove oz submodules
wojciech-turek Nov 7, 2023
eb00bc1
Avoid using submodules
wojciech-turek Nov 7, 2023
57aafc7
Rename folder
wojciech-turek Nov 7, 2023
cc054e0
Add basic config
wojciech-turek Nov 7, 2023
0bac9b0
Update deploy script
wojciech-turek Nov 7, 2023
88c8a52
Update package json scripts
wojciech-turek Nov 7, 2023
a04a3f6
Add Lock sol files and tests
wojciech-turek Nov 8, 2023
cda8313
Merge branch 'master' of https://github.com/thesandboxgame/sandbox-sm…
wojciech-turek Nov 21, 2023
aed4d2c
Update gitmodules
wojciech-turek Nov 21, 2023
ad8fa87
Revert the lock file to match master
wojciech-turek Nov 21, 2023
ca59682
Add example foundry to lock file
wojciech-turek Nov 21, 2023
4e8f297
Update github test action
wojciech-turek Nov 21, 2023
5458128
Install foundry for coverage
wojciech-turek Nov 21, 2023
f2613af
Update readme
wojciech-turek Nov 21, 2023
b294b08
Include env variables
wojciech-turek Nov 21, 2023
c1272c5
Rm unused gh action file
wojciech-turek Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"

- name: Install Slither
run: pip3 install slither-analyzer
Expand All @@ -39,8 +39,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: "./.github/setup"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Running tests
run: yarn test:ci
env:
Expand All @@ -50,8 +55,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: "./.github/setup"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Running coverage
run: yarn coverage:ci

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/example-foundry/lib/forge-std"]
path = packages/example-foundry/lib/forge-std
url = https://github.com/foundry-rs/forge-std
34 changes: 34 additions & 0 deletions packages/example-foundry/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this file ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, since we run those from the root we don't need it here.

14 changes: 14 additions & 0 deletions packages/example-foundry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/
artifacts/
# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
66 changes: 66 additions & 0 deletions packages/example-foundry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
27 changes: 27 additions & 0 deletions packages/example-foundry/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[profile.default]
src = "src"
out = "artifacts"
libs = ["lib"]
remappings = [
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
]

# OPTIMIZER SETTINGS
optimizer = true
optimizer_runs = 200

# RPC SETTINGS

[rpc_endpoints]
default = "http://localhost:8545"
mumbai = "https://rpc-mumbai.maticvigil.com/"

# ETHERSCAN SETTINGS

[etherscan]
mumbai = { key = "YOUR_API_KEY_HERE" }

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file contains secrets maybe is better to rename it to foundry.toml.example and add foundry.toml to git ignore file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can import env secrets into foundry.toml there is no need to create .example.
I will update it slightly so its shown how to do it.

134 changes: 134 additions & 0 deletions packages/example-foundry/lib/forge-std/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

# Backwards compatibility checks:
# - the oldest and newest version of each supported minor version
# - versions with specific issues
- name: Check compatibility with latest
if: always()
run: |
output=$(forge build --skip test)

if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.8.0
if: always()
run: |
output=$(forge build --skip test --use solc:0.8.0)

if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.7.6
if: always()
run: |
output=$(forge build --skip test --use solc:0.7.6)

if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.7.0
if: always()
run: |
output=$(forge build --skip test --use solc:0.7.0)

if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.6.12
if: always()
run: |
output=$(forge build --skip test --use solc:0.6.12)

if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.6.2
if: always()
run: |
output=$(forge build --skip test --use solc:0.6.2)

if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

# via-ir compilation time checks.
- name: Measure compilation time of Test with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of TestBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of Script with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Run tests
run: forge test -vvv

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Check formatting
run: forge fmt --check
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Sync Release Branch

on:
release:
types:
- created

jobs:
sync-release-branch:
runs-on: ubuntu-latest
if: startsWith(github.event.release.tag_name, 'v1')
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: v1

- name: Configure Git
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Sync Release Branch
run: |
git fetch --tags
git checkout v1
git reset --hard ${GITHUB_REF}
git push --force
4 changes: 4 additions & 0 deletions packages/example-foundry/lib/forge-std/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache/
out/
.vscode
.idea
3 changes: 3 additions & 0 deletions packages/example-foundry/lib/forge-std/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
Loading