diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..cfbdbb9 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,44 @@ +name: Soldity Linter + +on: + push: + branches: + - main + pull_request: + branches: + - "*" + +jobs: + solhint: + runs-on: ubuntu-20.04 + timeout-minutes: 2 + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install solhint + run: | + npm install solhint -g + solhint --version + + - name: Run Linter + run: ./scripts/lint.sh --sol-lint + + format-solidity: + runs-on: ubuntu-20.04 + timeout-minutes: 2 + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Foundry + run: ./scripts/install_foundry.sh + + - name: Check Solidity Formatting + run: | + export PATH=$PATH:$HOME/.foundry/bin + ./scripts/lint.sh --sol-format-check diff --git a/.github/workflows/slither.yml b/.github/workflows/slither.yml new file mode 100644 index 0000000..1f7ede5 --- /dev/null +++ b/.github/workflows/slither.yml @@ -0,0 +1,46 @@ +name: Slither Analyze + +on: + push: + branches: + - main + pull_request: + branches: + - "*" + +jobs: + slither-analyze: + name: Slither Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.8 + + - name: Install Slither + run: | + pip install slither-analyzer + + - name: Install Foundry + run: ./scripts/install_foundry.sh + + - name: Run Slither + run: | + export PATH=$PATH:$HOME/.foundry/bin + cd contracts + slither ./ --fail-none --sarif ./results.sarif + + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: contracts/results.sarif diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..90a1aa1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Solidity Unit Tests + +on: + push: + branches: + - "*" + +jobs: + solidity-unit-tests: + runs-on: ubuntu-20.04 + timeout-minutes: 10 + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Foundry + run: ./scripts/install_foundry.sh + + - name: Run unit tests + run: | + export PATH=$PATH:$HOME/.foundry/bin + cd contracts/ + forge test -vvv diff --git a/contracts/slither.config.json b/contracts/slither.config.json new file mode 100644 index 0000000..24abc06 --- /dev/null +++ b/contracts/slither.config.json @@ -0,0 +1,3 @@ +{ + "filter_paths": "lib" +} diff --git a/scripts/install_foundry.sh b/scripts/install_foundry.sh new file mode 100755 index 0000000..1429a5c --- /dev/null +++ b/scripts/install_foundry.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +# See the file LICENSE for licensing terms. + +set -e + +# The foundry install script uses XDG_CONFIG_HOME as the root of the install. +# This can vary for different environments, so it is set to $HOME for consistency. +export XDG_CONFIG_HOME=$HOME + +# This installs from ava-labs fork of the foundry repo. +FOUNDRY_VERSION=v0.1.0 +curl -L https://raw.githubusercontent.com/ava-labs/foundry/${FOUNDRY_VERSION}/foundryup/install > /tmp/foundry-install-script +# Set the foundry version in the install script +# Avoid using sed -i due to macos m1 incompatibility +sed "s/\/ava-labs\/foundry\/master\/foundryup/\/ava-labs\/foundry\/${FOUNDRY_VERSION}\/foundryup/g" /tmp/foundry-install-script +cat /tmp/foundry-install-script | bash + +export PATH=$PATH:$HOME/.foundry/bin:$HOME/.foundry:$HOME/.cargo/bin +foundryup --version ${FOUNDRY_VERSION}