diff --git a/.github/ISSUE_TEMPLATE/FEATURE_IMPROVEMENT.yaml b/.github/ISSUE_TEMPLATE/FEATURE_IMPROVEMENT.yaml index 098688d..c942227 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE_IMPROVEMENT.yaml +++ b/.github/ISSUE_TEMPLATE/FEATURE_IMPROVEMENT.yaml @@ -15,6 +15,7 @@ body: options: - Gas Optimization - General design optimization (improving efficiency, cleanliness, or developer experience) + - Testing - Documentation - type: textarea attributes: diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml deleted file mode 100644 index d8bd79b..0000000 --- a/.github/workflows/coverage.yaml +++ /dev/null @@ -1,88 +0,0 @@ -name: code coverage - -on: - pull_request: - branches: [main, master, staging, dev] - -jobs: - comment-forge-coverage: - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - - 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 coverage - id: coverage - run: | - { - echo 'COVERAGE<> "$GITHUB_OUTPUT" - env: - FOUNDRY_RPC_URL: "${{ secrets.RPC_URL }}" - - - name: Check coverage is updated - uses: actions/github-script@v5 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const fs = require('fs'); - const file = "coverage.txt" - if(!fs.existsSync(file)) { - console.log("Nothing to check"); - return - } - const currentCoverage = fs.readFileSync(file, "utf8").trim(); - const newCoverage = (`${{ steps.coverage.outputs.COVERAGE }}`).trim(); - if (newCoverage != currentCoverage) { - core.setFailed(`Code coverage not updated. Run : forge coverage | grep '^|' | grep -v 'test/' > coverage.txt`); - } - - - name: Comment on PR - id: comment - uses: actions/github-script@v5 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const {data: comments} = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }) - - const botComment = comments.find(comment => comment.user.id === 41898282) - - const output = `${{ steps.coverage.outputs.COVERAGE }}`; - const commentBody = `Forge code coverage:\n${output}\n`; - - if (botComment) { - github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: commentBody - }) - } else { - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: commentBody - }); - } diff --git a/.gitignore b/.gitignore index 95a845d..39541da 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /out /cache /coverage +/report lcov.info .DS_Store .env @@ -10,7 +11,3 @@ lcov.info broadcast/*/31337 deployments/**/31337.* - -# storage layout checker library -storage_check_cache -storage_check_report \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 578b680..95b5244 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,7 @@ - [Install](#install) - [Pre-commit Hooks](#pre-commit-hooks) +- [Requirements for merge](#requirements-for-merge) - [Branching](#branching) - [Main](#main) - [Staging](#staging) @@ -38,6 +39,17 @@ This repo includes the following pre-commit hooks that are defined in the `.pre- - `doc`: This hook uses `forge doc` to automatically generate documentation for all Solidity files whenever the NatSpec documentation changes. The `script/util/doc_gen.sh` script is used to generate documentation. Forge updates the commit hash in the documentation automatically. To only generate new documentation when the documentation has actually changed, the script checks whether more than just the hash has changed in the documentation and discard all changes if only the hash has changed. - `prettier`: All remaining files are formatted using prettier. +## Requirements for merge + +In order for a PR to be merged, it must pass the following requirements: + +- All commits within the PR must be signed +- CI must pass (tests, linting, etc.) +- New features must be merged with associated tests +- Bug fixes must have a corresponding test that fails without the fix +- The PR must be approved by at least one maintainer + - The PR must be approved by 2+ maintainers if the PR is a new feature or > 100 LOC changed + ## Branching This section outlines the branching strategy of this repo. diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 2529d83..216f766 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -8,8 +8,8 @@ import {Counter} from 'src/Counter.sol'; contract Deploy is Script { using stdJson for string; - function run() public { + function run() public returns (Counter) { uint256 initialNumber = 5; - new Counter(initialNumber); + return new Counter(initialNumber); } } diff --git a/test/Counter.t.sol b/test/Counter.t.sol index 9770497..084b23d 100644 --- a/test/Counter.t.sol +++ b/test/Counter.t.sol @@ -3,11 +3,11 @@ pragma solidity 0.8.26; import {GasSnapshot} from 'forge-gas-snapshot/GasSnapshot.sol'; import 'forge-std/Test.sol'; -import 'test/util/TestHelpers.sol'; +import {Deploy} from 'script/Deploy.s.sol'; import {Counter} from 'src/Counter.sol'; -abstract contract Deployed is Test, TestHelpers { +abstract contract Deployed is Test { Counter counter; function setUp() public virtual { @@ -38,3 +38,15 @@ contract CounterTest_Deployed is Deployed, GasSnapshot { snapLastCall('Set counter number'); } } + +contract DeploymentTest is Test { + Counter counter; + + function setUp() public virtual { + counter = new Deploy().run(); + } + + function test_IsDeployedCorrectly() public view { + assertEq(counter.number(), 5); + } +} diff --git a/test/util/TestHelpers.sol b/test/util/TestHelpers.sol deleted file mode 100644 index 934127f..0000000 --- a/test/util/TestHelpers.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.26; - -import 'forge-std/Test.sol'; - -abstract contract TestHelpers is Test { - Account internal DEPLOYER; - - constructor() { - DEPLOYER = makeAccount('DEPLOYER'); - vm.setEnv('PRIVATE_KEY', vm.toString(DEPLOYER.key)); - } -}