From cc8061f38e15417afed1a5c37bba4107860da4fe Mon Sep 17 00:00:00 2001 From: mfw78 <53399572+mfw78@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:23:18 +0000 Subject: [PATCH] feat: foundry and devcontainer (#111) ## Description This PR: 1. Adds [foundry](https://getfoundry.sh/) configuration for the contracts. 2. Configures the solidity compiler for foundry to replicate that currently used within the contracts. 3. Adds a devcontainer containing foundry and node (for still running hardhat during the migration phase). 4. Configures a VS Code environment for solidity development. ## Test Plan 1. Observe CI/CD continues to pass. ## Related Issues Closes #99 Closes #98 --------- Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com> --- .devcontainer/devcontainer.json | 15 ++++++++ .gas-snapshot | 1 + .github/workflows/gas.yml | 53 ++++++++++++++++++++++++++++ .github/workflows/test.yml | 62 +++++++++++++++++++++++++++++++++ .gitignore | 12 +++++++ .gitmodules | 3 ++ .vscode/settings.json | 7 ++++ foundry.toml | 10 ++++++ lib/forge-std | 1 + test/TestNoOp.sol | 7 ++++ 10 files changed, 171 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gas-snapshot create mode 100644 .github/workflows/gas.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitmodules create mode 100644 .vscode/settings.json create mode 100644 foundry.toml create mode 160000 lib/forge-std create mode 100644 test/TestNoOp.sol diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..6dffa2b6 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,15 @@ +{ + "name": "Foundry + Node", + "image": "mcr.microsoft.com/devcontainers/base:0", + "features": { + "ghcr.io/nlordell/features/foundry": {}, + "ghcr.io/devcontainers/features/node:1": {} + }, + "customizations": { + "vscode" : { + "extensions": [ + "JuanBlanco.solidity" + ] + } + } +} \ No newline at end of file diff --git a/.gas-snapshot b/.gas-snapshot new file mode 100644 index 00000000..a8056b1f --- /dev/null +++ b/.gas-snapshot @@ -0,0 +1 @@ +TestNoOp:test_noOp() (gas: 122) \ No newline at end of file diff --git a/.github/workflows/gas.yml b/.github/workflows/gas.yml new file mode 100644 index 00000000..03f7f4b5 --- /dev/null +++ b/.github/workflows/gas.yml @@ -0,0 +1,53 @@ +name: Gas + +on: + pull_request: + paths: + - '**.sol' + - '**.yml' + - '**.toml' + - 'lib/**' + - '.gitmodules' + - '.gas-snapshot' + push: + branches: + - main + paths: + - '**.sol' + - '**.yml' + - '**.toml' + - 'lib/**' + - '.gitmodules' + - '.gas-snapshot' + +env: + FOUNDRY_PROFILE: ci + +jobs: + gas: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: actions/setup-node@v4 + - id: yarn-cache + run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT" + - uses: actions/cache@v4 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn- + - run: yarn --frozen-lockfile + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Check gas snapshots + run: forge snapshot --check + # TODO: remove failure allowance once foundry migration is complete + continue-on-error: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..bb0837f0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,62 @@ +name: Test + +on: + workflow_dispatch: + pull_request: + paths: + - '**.sol' + - '**.yml' + - '**.toml' + - 'lib/**' + - '.gitmodules' + push: + branches: + - main + paths: + - '**.sol' + - '**.yml' + - '**.toml' + - 'lib/**' + - '.gitmodules' + +env: + FOUNDRY_PROFILE: ci + +jobs: + test: + strategy: + fail-fast: true + + name: Foundry project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: actions/setup-node@v4 + - id: yarn-cache + run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT" + - uses: actions/cache@v4 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn- + - run: yarn --frozen-lockfile + + - 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 diff --git a/.gitignore b/.gitignore index 75834057..d482968b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,15 @@ yarn-error.log *.tgz state.json .mocharc.json + +# Compiler files +cache/ +out/ + +# Ignores development broadcast logs +!/broadcast +/broadcast/*/31337/ +/broadcast/**/dry-run/ + +# Dotenv file +.env \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..888d42dc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/forge-std"] + path = lib/forge-std + url = https://github.com/foundry-rs/forge-std diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..f0edb045 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "solidity.packageDefaultDependenciesDirectory": ["node_modules", "lib"], + "[solidity]": { + "editor.defaultFormatter": "JuanBlanco.solidity" + }, + "solidity.compileUsingRemoteVersion": "v0.7.6+commit.7338295f", +} diff --git a/foundry.toml b/foundry.toml new file mode 100644 index 00000000..9cfdd148 --- /dev/null +++ b/foundry.toml @@ -0,0 +1,10 @@ +[profile.default] +src = "src" +out = "out" +libs = ["node_modules", "lib"] + +# Compiler settings +solc = "0.7.6" +via_ir = false +optimizer = true +optimizer_runs = 1000000 diff --git a/lib/forge-std b/lib/forge-std new file mode 160000 index 00000000..978ac6fa --- /dev/null +++ b/lib/forge-std @@ -0,0 +1 @@ +Subproject commit 978ac6fadb62f5f0b723c996f64be52eddba6801 diff --git a/test/TestNoOp.sol b/test/TestNoOp.sol new file mode 100644 index 00000000..a697cfc0 --- /dev/null +++ b/test/TestNoOp.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity ^0.7.6; + +/// @dev No-op contract for start of forgifying contracts. Delete this! +contract TestNoOp { + function test_noOp() external pure {} +}