From c126f00640635bdd7d97ebe5a7b1f3ea53638c81 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Mon, 3 Jun 2024 23:38:45 +0000 Subject: [PATCH 1/3] install avalanchego & subnetevm via avalanche-cli --- .github/workflows/test.yml | 3 + scripts/install_avalanchego_release.sh | 133 ------------------------- scripts/install_subnetevm_release.sh | 118 ---------------------- scripts/local/e2e_test.sh | 33 ++++-- 4 files changed, 29 insertions(+), 258 deletions(-) delete mode 100755 scripts/install_avalanchego_release.sh delete mode 100755 scripts/install_subnetevm_release.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7040c7126..08410f658 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,6 +73,9 @@ jobs: - name: Install Foundry run: ./scripts/install_foundry.sh + - name: Install avalanche-cli + run: curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-cli/main/scripts/install.sh | sh -s -- -b /usr/local/bin v1.5.3 + - name: Run E2E Tests # Forge installs to BASE_DIR, but updates the PATH definition in $HOME/.bashrc run: | diff --git a/scripts/install_avalanchego_release.sh b/scripts/install_avalanchego_release.sh deleted file mode 100755 index eed230b31..000000000 --- a/scripts/install_avalanchego_release.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2023, Ava Labs, Inc. All rights reserved. -# See the file LICENSE for licensing terms. - -# Following script is adapted from https://github.com/ava-labs/subnet-evm/blob/master/scripts/install_avalanchego_release.sh -set -e - -# Load the versions -TELEPORTER_PATH=$( - cd "$(dirname "${BASH_SOURCE[0]}")" - cd .. && pwd -) -source "$TELEPORTER_PATH"/scripts/versions.sh - -# Load the constants -source "$TELEPORTER_PATH"/scripts/constants.sh - -############################ -# download avalanchego -# https://github.com/ava-labs/avalanchego/releases -GOARCH=$(go env GOARCH) -GOOS=$(go env GOOS) -BASEDIR=${BASEDIR:-"/tmp/avalanchego-release"} -AVALANCHEGO_BUILD_PATH=${AVALANCHEGO_BUILD_PATH:-${BASEDIR}/avalanchego} - -mkdir -p ${BASEDIR} - -AVAGO_DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/${AVALANCHEGO_VERSION}/avalanchego-linux-${GOARCH}-${AVALANCHEGO_VERSION}.tar.gz -AVAGO_DOWNLOAD_PATH=${BASEDIR}/avalanchego-linux-${GOARCH}-${AVALANCHEGO_VERSION}.tar.gz - -if [[ ${GOOS} == "darwin" ]]; then - AVAGO_DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/${AVALANCHEGO_VERSION}/avalanchego-macos-${AVALANCHEGO_VERSION}.zip - AVAGO_DOWNLOAD_PATH=${BASEDIR}/avalanchego-macos-${AVALANCHEGO_VERSION}.zip -fi - -BUILD_DIR=${AVALANCHEGO_BUILD_PATH}-${AVALANCHEGO_VERSION} - -extract_archive() { - mkdir -p ${BUILD_DIR} - - if [[ ${AVAGO_DOWNLOAD_PATH} == *.tar.gz ]]; then - tar xzvf ${AVAGO_DOWNLOAD_PATH} --directory ${BUILD_DIR} --strip-components 1 - elif [[ ${AVAGO_DOWNLOAD_PATH} == *.zip ]]; then - unzip ${AVAGO_DOWNLOAD_PATH} -d ${BUILD_DIR} - mv ${BUILD_DIR}/build/* ${BUILD_DIR} - rm -rf ${BUILD_DIR}/build/ - fi -} - -# first check if we already have the archive -if [[ -f ${AVAGO_DOWNLOAD_PATH} ]]; then - # if the download path already exists, extract and exit - echo "found avalanchego ${AVALANCHEGO_VERSION} at ${AVAGO_DOWNLOAD_PATH}" - - extract_archive -else - # try to download the archive if it exists - if curl -s --head --request GET ${AVAGO_DOWNLOAD_URL} | grep "302" > /dev/null; then - echo "${AVAGO_DOWNLOAD_URL} found" - echo "downloading to ${AVAGO_DOWNLOAD_PATH}" - curl -L ${AVAGO_DOWNLOAD_URL} -o ${AVAGO_DOWNLOAD_PATH} - - extract_archive - else - # else the version is a git commit (or it's invalid) - GIT_CLONE_URL=https://github.com/ava-labs/avalanchego.git - GIT_CLONE_PATH=${BASEDIR}/avalanchego-repo/ - - # check to see if the repo already exists, if not clone it - if [[ ! -d ${GIT_CLONE_PATH} ]]; then - echo "cloning ${GIT_CLONE_URL} to ${GIT_CLONE_PATH}" - git clone --no-checkout ${GIT_CLONE_URL} ${GIT_CLONE_PATH} - fi - - # check to see if the commitish exists in the repo - WORKDIR=$(pwd) - - cd ${GIT_CLONE_PATH} - - git fetch - - echo "checking out ${AVALANCHEGO_VERSION}" - - set +e - # try to checkout the branch - git checkout origin/${AVALANCHEGO_VERSION} > /dev/null 2>&1 - CHECKOUT_STATUS=$? - set -e - - # if it's not a branch, try to checkout the commit - # Try to checkout the branch. If it fails, try the commit. - if ! git checkout "origin/${AVALANCHEGO_VERSION}" > /dev/null 2>&1; then - if ! git checkout "${AVALANCHEGO_VERSION}" > /dev/null 2>&1; then - # If the version is in the format of tag-commit, try to extract the commit and checkout. - AVALANCHEGO_VERSION=$(extract_commit "${AVALANCHEGO_VERSION}") - if ! git checkout "${AVALANCHEGO_VERSION}" > /dev/null 2>&1; then - echo - echo "'${AVALANCHEGO_VERSION}' is not a valid release tag, commit hash, or branch name" - exit 1 - fi - fi - fi - - COMMIT=$(git rev-parse HEAD) - - # use the commit hash instead of the branch name or tag - BUILD_DIR=${AVALANCHEGO_BUILD_PATH}-${COMMIT} - - # if the build-directory doesn't exist, build avalanchego - if [[ ! -d ${BUILD_DIR} ]]; then - echo "building avalanchego ${COMMIT} to ${BUILD_DIR}" - ./scripts/build.sh - mkdir -p ${BUILD_DIR} - - mv ${GIT_CLONE_PATH}/build/* ${BUILD_DIR}/ - fi - - cd $WORKDIR - fi -fi - -AVALANCHEGO_PATH=${AVALANCHEGO_BUILD_PATH}/avalanchego -AVALANCHEGO_PLUGIN_DIR=${AVALANCHEGO_BUILD_PATH}/plugins - -mkdir -p ${AVALANCHEGO_BUILD_PATH} -mkdir -p ${AVALANCHEGO_PLUGIN_DIR} - -cp ${BUILD_DIR}/avalanchego ${AVALANCHEGO_PATH} - - -echo "Installed AvalancheGo release ${AVALANCHEGO_VERSION}" -echo "AvalancheGo Path: ${AVALANCHEGO_PATH}" -echo "Plugin Dir: ${AVALANCHEGO_PLUGIN_DIR}" diff --git a/scripts/install_subnetevm_release.sh b/scripts/install_subnetevm_release.sh deleted file mode 100755 index bd14df502..000000000 --- a/scripts/install_subnetevm_release.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2023, Ava Labs, Inc. All rights reserved. -# See the file LICENSE for licensing terms. - -# Following script is adapted from https://github.com/ava-labs/subnet-evm/blob/master/scripts/install_avalanchego_release.sh -set -e - -# Load the versions -TELEPORTER_PATH=$( - cd "$(dirname "${BASH_SOURCE[0]}")" - cd .. && pwd -) -source "$TELEPORTER_PATH"/scripts/versions.sh -source "$TELEPORTER_PATH"/scripts/constants.sh - -############################ -# download subnet-evm -# https://github.com/ava-labs/subnet-evm/releases -GOARCH=$(go env GOARCH) -GOOS=$(go env GOOS) -BASEDIR=${BASEDIR:-"/tmp/subnet-evm-release"} -SUBNET_EVM_BUILD_PATH=${SUBNET_EVM_BUILD_PATH:-${BASEDIR}/subnet-evm} - -mkdir -p ${BASEDIR} - -SUBNET_EVM_DOWNLOAD_URL=https://github.com/ava-labs/subnet-evm/releases/download/${SUBNET_EVM_VERSION}/subnet-evm_${SUBNET_EVM_VERSION#v}_linux_${GOARCH}.tar.gz -SUBNET_EVM_DOWNLOAD_PATH=${BASEDIR}/subnet-evm-linux-${GOARCH}-${SUBNET_EVM_VERSION}.tar.gz - -if [[ ${GOOS} == "darwin" ]]; then - SUBNET_EVM_DOWNLOAD_URL=https://github.com/ava-labs/subnet-evm/releases/download/${SUBNET_EVM_VERSION}/subnet-evm_${SUBNET_EVM_VERSION#v}_darwin_${GOARCH}.tar.gz - SUBNET_EVM_DOWNLOAD_PATH=${BASEDIR}/subnet-evm-darwin-${GOARCH}-${SUBNET_EVM_VERSION}.tar.gz -fi - -BUILD_DIR=${SUBNET_EVM_BUILD_PATH}-${SUBNET_EVM_VERSION} - -extract_archive() { - mkdir -p ${BUILD_DIR} - - if [[ ${SUBNET_EVM_DOWNLOAD_PATH} == *.tar.gz ]]; then - tar xzvf ${SUBNET_EVM_DOWNLOAD_PATH} --directory ${BUILD_DIR} - elif [[ ${SUBNET_EVM_DOWNLOAD_PATH} == *.zip ]]; then - unzip ${SUBNET_EVM_DOWNLOAD_PATH} -d ${BUILD_DIR} - mv ${BUILD_DIR}/build/* ${BUILD_DIR} - rm -rf ${BUILD_DIR}/build/ - fi -} - -# first check if we already have the archive -if [[ -f ${SUBNET_EVM_DOWNLOAD_PATH} ]]; then - # if the download path already exists, extract and exit - echo "found subnet-evm ${SUBNET_EVM_VERSION} at ${SUBNET_EVM_DOWNLOAD_PATH}" - - extract_archive -else - # try to download the archive if it exists - if curl -s --head --request GET ${SUBNET_EVM_DOWNLOAD_URL} | grep "302" > /dev/null; then - echo "${SUBNET_EVM_DOWNLOAD_URL} found" - echo "downloading to ${SUBNET_EVM_DOWNLOAD_PATH}" - curl -L ${SUBNET_EVM_DOWNLOAD_URL} -o ${SUBNET_EVM_DOWNLOAD_PATH} - - extract_archive - else - # else the version is a git commit (or it's invalid) - GIT_CLONE_URL=https://github.com/ava-labs/subnet-evm.git - GIT_CLONE_PATH=${BASEDIR}/subnet-evm-repo/ - - # check to see if the repo already exists, if not clone it - if [[ ! -d ${GIT_CLONE_PATH} ]]; then - echo "cloning ${GIT_CLONE_URL} to ${GIT_CLONE_PATH}" - git clone --no-checkout ${GIT_CLONE_URL} ${GIT_CLONE_PATH} - fi - - # check to see if the commitish exists in the repo - WORKDIR=$(pwd) - - cd ${GIT_CLONE_PATH} - - git fetch - - echo "checking out ${SUBNET_EVM_VERSION}" - - # Try to checkout the branch. If it fails, try the commit. - if ! git checkout "origin/${SUBNET_EVM_VERSION}" > /dev/null 2>&1; then - if ! git checkout "${SUBNET_EVM_VERSION}" > /dev/null 2>&1; then - # If the version is in the format of tag-commit, try to extract the commit and checkout. - SUBNET_EVM_VERSION=$(extract_commit "${SUBNET_EVM_VERSION}") - if ! git checkout "${SUBNET_EVM_VERSION}" > /dev/null 2>&1; then - echo - echo "'${SUBNET_EVM_VERSION}' is not a valid release tag, commit hash, or branch name" - exit 1 - fi - fi - fi - - COMMIT=$(git rev-parse HEAD) - - # use the commit hash instead of the branch name or tag - BUILD_DIR=${SUBNET_EVM_BUILD_PATH}-${COMMIT} - - # if the build-directory doesn't exist, build subnet-evm - if [[ ! -d ${BUILD_DIR} ]]; then - echo "building subnet-evm ${COMMIT} to ${BUILD_DIR}" - mkdir -p ${BUILD_DIR} - ./scripts/build.sh ${BUILD_DIR}/subnet-evm - fi - - cd $WORKDIR - fi -fi - -SUBNET_EVM_PATH=${SUBNET_EVM_BUILD_PATH}/subnet-evm -mkdir -p ${SUBNET_EVM_BUILD_PATH} - -cp ${BUILD_DIR}/subnet-evm ${SUBNET_EVM_PATH} - - -echo "Installed Subnet-EVM release ${SUBNET_EVM_VERSION}" -echo "Subnet-EVM Path: ${SUBNET_EVM_PATH}" diff --git a/scripts/local/e2e_test.sh b/scripts/local/e2e_test.sh index 51f58dbfb..af1f0d668 100755 --- a/scripts/local/e2e_test.sh +++ b/scripts/local/e2e_test.sh @@ -15,15 +15,34 @@ source "$TELEPORTER_PATH"/scripts/versions.sh BASEDIR=${BASEDIR:-"$HOME/.teleporter-deps"} cwd=$(pwd) -# Install the avalanchego and subnet-evm binaries -rm -rf $BASEDIR/avalanchego -BASEDIR=$BASEDIR AVALANCHEGO_BUILD_PATH=$BASEDIR/avalanchego ./scripts/install_avalanchego_release.sh -BASEDIR=$BASEDIR ./scripts/install_subnetevm_release.sh -cp ${BASEDIR}/subnet-evm/subnet-evm ${BASEDIR}/avalanchego/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy -echo "Copied ${BASEDIR}/subnet-evm/subnet-evm binary to ${BASEDIR}/avalanchego/plugins/" +AVALANCHE_CLI_DIR=$HOME/.avalanche-cli -export AVALANCHEGO_BUILD_PATH=$BASEDIR/avalanchego +export AVALANCHEGO_BUILD_PATH=${AVALANCHE_CLI_DIR}/bin/avalanchego/avalanchego-${AVALANCHEGO_VERSION} + +# ensure that avalanche-cli has installed the version of avalanchego that we need: +if [[ ! -x "$AVALANCHEGO_BUILD_PATH/avalanchego" ]]; then + avalanche network clean + avalanche network start --avalanchego-version "$AVALANCHEGO_VERSION" + avalanche network clean +fi + +# ensure that avalanche-cli has installed the version of subnetevm that we need: +subnetevm_bin=${AVALANCHE_CLI_DIR}/bin/subnet-evm/subnet-evm-${SUBNET_EVM_VERSION}/subnet-evm +if [[ ! -x "$subnetevm_bin" ]]; then + avalanche subnet create dummy --evm --vm-version "$SUBNET_EVM_VERSION" \ + --force \ + --teleporter --relayer --evm-chain-id 1 --evm-token DUM --evm-defaults # this line is just to avoid the dialog prompts +fi + +# Install the subnet-evm binary as a plugin within the avalanche-cli resources. +# This is a hack that can probably be undone when we stop setting up the +# avalanche network and subnet ourselves (via BeforeSuite/AfterSuite in +# tests/local/e2e_test.go) and start having avalanche-cli do that for us +# instead. +mkdir -p "${AVALANCHEGO_BUILD_PATH}/plugins" +cp "$subnetevm_bin" \ + "${AVALANCHEGO_BUILD_PATH}/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy" cd $TELEPORTER_PATH/contracts if command -v forge &> /dev/null; then From f93ed0220d8b2dba9edb0742cd8a53902d752da5 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Tue, 4 Jun 2024 11:00:57 -0400 Subject: [PATCH 2/3] Update README.md Signed-off-by: F. Eugene Aumson --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9d52c895..a9cc981e6 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ source vars.sh # source the variables needed to interact with the In addition to the docker setup, end-to-end integration tests written using Ginkgo are provided in the `tests/` directory. E2E tests are run as part of CI, but can also be run locally. Any new features or cross-chain example applications checked into the repository should be accompanied by an end-to-end tests. See the [Contribution Guide](./CONTRIBUTING.md) for additional details. -To run the E2E tests locally, you'll need to install Gingko following the instructions [here](https://onsi.github.io/ginkgo/#installing-ginkgo). +To run the E2E tests locally, you'll need to install Gingko following the instructions [here](https://onsi.github.io/ginkgo/#installing-ginkgo), and avalanche-cli as instructed [here](https://docs.avax.network/tooling/cli-guides/install-avalanche-cli). Then run the following command from the root of the repository: From 5c48264f2aedf30c812f49c362336172e3819a52 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Thu, 6 Jun 2024 15:33:23 +0000 Subject: [PATCH 3/3] e2e_test.sh: consistent order of operations addresses review comment https://github.com/ava-labs/teleporter/pull/392#discussion_r1627939911 --- scripts/local/e2e_test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/local/e2e_test.sh b/scripts/local/e2e_test.sh index af1f0d668..9175dd840 100755 --- a/scripts/local/e2e_test.sh +++ b/scripts/local/e2e_test.sh @@ -27,8 +27,9 @@ if [[ ! -x "$AVALANCHEGO_BUILD_PATH/avalanchego" ]]; then avalanche network clean fi -# ensure that avalanche-cli has installed the version of subnetevm that we need: subnetevm_bin=${AVALANCHE_CLI_DIR}/bin/subnet-evm/subnet-evm-${SUBNET_EVM_VERSION}/subnet-evm + +# ensure that avalanche-cli has installed the version of subnetevm that we need: if [[ ! -x "$subnetevm_bin" ]]; then avalanche subnet create dummy --evm --vm-version "$SUBNET_EVM_VERSION" \ --force \