From 20ccd2f94b820f83ccfd41dbc2b643fa63b3e996 Mon Sep 17 00:00:00 2001 From: Reptile <43194093+gator-boi@users.noreply.github.com> Date: Thu, 30 Mar 2023 09:15:15 -0500 Subject: [PATCH] Add github action (#29) * evm: add ci * add forge test to CI * add foundry install script --------- Co-authored-by: gator-boi --- .github/main.yml | 17 ++++ evm/env/testing.env | 2 + evm/shell-scripts/run_integration_tests.sh | 2 + scripts/install_foundry.sh | 92 ++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 .github/main.yml create mode 100644 scripts/install_foundry.sh diff --git a/.github/main.yml b/.github/main.yml new file mode 100644 index 0000000..6d8dcb4 --- /dev/null +++ b/.github/main.yml @@ -0,0 +1,17 @@ +name: Build +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +jobs: + ethereum: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - run: cd evm && bash ../scripts/install_foundry.sh + - run: cd evm && PATH=$PATH:$HOME/.foundry/bin/ make dependencies + - run: cd evm && PATH=$PATH:$HOME/.foundry/bin/ && source env/testing.env && ETH_FORK_RPC=${{ secrets.ETH_RPC }} forge test --fork-url ${{ secrets.ETH_RPC }} diff --git a/evm/env/testing.env b/evm/env/testing.env index 538293f..d3608d6 100644 --- a/evm/env/testing.env +++ b/evm/env/testing.env @@ -8,6 +8,7 @@ export ETH_FORK_CHAIN_ID=5 export ETH_USDC_TOKEN_ADDRESS=0x07865c6E87B9F70255377e024ace6630C1Eaa37F export ETH_CIRCLE_BRIDGE_ADDRESS=0xd0c3da58f55358142b8d3e06c1c30c5c6114efe8 export ETH_WORMHOLE_ADDRESS=0x706abc4E45D419950511e474C7B9Ed348A4a716c +export ETH_WORMHOLE_FINALITY=15 ############################################################################### # @@ -19,6 +20,7 @@ export AVAX_FORK_CHAIN_ID=43113 export AVAX_USDC_TOKEN_ADDRESS=0x5425890298aed601595a70AB815c96711a31Bc65 export AVAX_CIRCLE_BRIDGE_ADDRESS=0xeb08f243e5d3fcff26a9e38ae5520a669f4019d0 export AVAX_WORMHOLE_ADDRESS=0x7bbcE28e64B3F8b84d876Ab298393c38ad7aac4C +export AVAX_ETH_WORMHOLE_FINALITY=1 ############################################################################### # diff --git a/evm/shell-scripts/run_integration_tests.sh b/evm/shell-scripts/run_integration_tests.sh index e5771b1..beb24bb 100644 --- a/evm/shell-scripts/run_integration_tests.sh +++ b/evm/shell-scripts/run_integration_tests.sh @@ -32,6 +32,7 @@ EVM_ROOT=$(dirname $0)/../ echo "deploy contracts" RELEASE_WORMHOLE_ADDRESS=$ETH_WORMHOLE_ADDRESS \ RELEASE_CIRCLE_BRIDGE_ADDRESS=$ETH_CIRCLE_BRIDGE_ADDRESS \ +RELEASE_WORMHOLE_FINALITY=$ETH_WORMHOLE_FINALITY \ forge script $EVM_ROOT/forge-scripts/deploy_contracts.sol \ --rpc-url http://localhost:8546 \ --private-key $PRIVATE_KEY \ @@ -39,6 +40,7 @@ forge script $EVM_ROOT/forge-scripts/deploy_contracts.sol \ RELEASE_WORMHOLE_ADDRESS=$AVAX_WORMHOLE_ADDRESS \ RELEASE_CIRCLE_BRIDGE_ADDRESS=$AVAX_CIRCLE_BRIDGE_ADDRESS \ +RELEASE_WORMHOLE_FINALITY=$AVAX_WORMHOLE_FINALITY \ forge script $EVM_ROOT/forge-scripts/deploy_contracts.sol \ --rpc-url http://localhost:8547 \ --private-key $PRIVATE_KEY \ diff --git a/scripts/install_foundry.sh b/scripts/install_foundry.sh new file mode 100644 index 0000000..ef071b7 --- /dev/null +++ b/scripts/install_foundry.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# This script install foundry and the solidity compiler required to build the +# ethereum contracts. Foundry itself provides a mechanism to install solc, but +# it doesn't work with certain firewall configurations. + +set -euo pipefail + +# check if foundry.toml exists +if [ ! -f foundry.toml ]; then + echo "foundry.toml not found. Please call from the ethereum directory." >& 2 + exit 1 +fi + +# Read compiler version from foundry.toml +SOLC_VERSION=$(grep solc_version foundry.toml | cut -d'=' -f2 | tr -d '" ') || true + +if [ -z "$SOLC_VERSION" ]; then + echo "solc_version not found in foundry.toml." >& 2 + exit 1 +fi + +main() { + OS=$(uname -s) + case "$OS" in + Darwin) + install_mac + ;; + Linux) + install_linux + ;; + *) + echo "Unsupported OS: $OS" + exit 1 + ;; + esac +} + +function install_mac() { + if ! command -v brew > /dev/null; then + echo "brew is unavailable. Please install: https://brew.sh" + fi + + if ! brew list libusb > /dev/null 2>&1; then + echo "Installing libusb" + brew install libusb + fi + + if ! command -v foundryup > /dev/null; then + curl -L https://foundry.paradigm.xyz --silent | bash + "$HOME/.foundry/bin/foundryup" + fi + + INSTALL_DIR="$HOME/.svm/$SOLC_VERSION" + + mkdir -p "$INSTALL_DIR" + + SOLC_PATH="$INSTALL_DIR/solc-$SOLC_VERSION" + + if [ ! -f "$SOLC_PATH" ]; then + echo "Installing solc-$SOLC_VERSION" + curl -L --silent "https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solc-macos" > "$SOLC_PATH" + chmod +x "$SOLC_PATH" + echo "Installed $SOLC_PATH" + else + echo "Solidity compiler found: $SOLC_PATH" + fi +} + +function install_linux() { + if ! command -v foundryup > /dev/null; then + curl -L https://foundry.paradigm.xyz --silent | bash + "$HOME/.foundry/bin/foundryup" + fi + + INSTALL_DIR="$HOME/.svm/$SOLC_VERSION" + + mkdir -p "$INSTALL_DIR" + + SOLC_PATH="$INSTALL_DIR/solc-$SOLC_VERSION" + + if [ ! -f "$SOLC_PATH" ]; then + echo "Installing solc-$SOLC_VERSION" + curl -L --silent "https://github.com/ethereum/solidity/releases/download/v$SOLC_VERSION/solc-static-linux" > "$SOLC_PATH" + chmod +x "$SOLC_PATH" + echo "Installed $SOLC_PATH" + else + echo "Solidity compiler found: $SOLC_PATH" + fi +} + +main "$@"; exit