Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E Testing with Avalanche Network Runner #110

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
tags:
- "*"
pull_request:

env:
Expand All @@ -14,22 +16,41 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: ${{ env.go_version }}
- run: make build
Test:
unit_test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: ${{ env.go_version }}
- run: make test
e2e_test:
name: E2E Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: ${{ env.go_version }}
- shell: bash
run: E2E=true ./scripts/run.sh 1.7.10
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: golangci/golangci-lint-action@v2
with:
version: latest
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ setup:
go mod download

test:
go test -v -cover -race ./...
go test -v -cover -race $(shell go list ./... | grep -v /tests/e2e)

docker-build:
docker build \
Expand Down
16 changes: 13 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module github.com/ava-labs/avalanche-rosetta
go 1.17

require (
github.com/ava-labs/avalanche-network-runner-sdk v0.0.0
github.com/ava-labs/avalanchego v1.7.10
github.com/ava-labs/coreth v0.8.9-rc.1
github.com/coinbase/rosetta-sdk-go v0.6.5
github.com/ethereum/go-ethereum v1.10.16
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down Expand Up @@ -67,13 +70,20 @@ require (
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tyler-smith/go-bip39 v1.0.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gonum.org/v1/gonum v0.9.1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
59 changes: 53 additions & 6 deletions go.sum

Large diffs are not rendered by default.

129 changes: 129 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env bash
set -e

# e.g.,
#
# run without e2e tests
# ./scripts/run.sh 1.7.10
#
# run without e2e tests with DEBUG log level
# AVALANCHE_LOG_LEVEL=DEBUG ./scripts/run.sh 1.7.10
#
# run with e2e tests
# E2E=true ./scripts/run.sh 1.7.10
if ! [[ "$0" =~ scripts/run.sh ]]; then
echo "must be run from repository root"
exit 255
fi

VERSION=$1
if [[ -z "${VERSION}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION]" >> /dev/stderr
exit 255
fi

MODE=${MODE:-run}
E2E=${E2E:-false}
if [[ ${E2E} == true ]]; then
MODE="test"
fi

AVALANCHE_LOG_LEVEL=${AVALANCHE_LOG_LEVEL:-INFO}

echo "Running with:"
echo VERSION: ${VERSION}
echo MODE: ${MODE}
echo AVALANCHE_LOG_LEVEL: ${AVALANCHE_LOG_LEVEL}

############################
# download avalanchego
# https://github.com/ava-labs/avalanchego/releases
GOARCH=$(go env GOARCH)
GOOS=$(go env GOOS)
DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/v${VERSION}/avalanchego-linux-${GOARCH}-v${VERSION}.tar.gz
DOWNLOAD_PATH=/tmp/avalanchego.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/v${VERSION}/avalanchego-macos-v${VERSION}.zip
DOWNLOAD_PATH=/tmp/avalanchego.zip
fi

rm -rf /tmp/avalanchego-v${VERSION}
rm -f ${DOWNLOAD_PATH}

echo "downloading avalanchego ${VERSION} at ${DOWNLOAD_URL}"
curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded avalanchego"
if [[ ${GOOS} == "linux" ]]; then
tar xzvf ${DOWNLOAD_PATH} -C /tmp
elif [[ ${GOOS} == "darwin" ]]; then
unzip ${DOWNLOAD_PATH} -d /tmp/avalanchego-build
mv /tmp/avalanchego-build/build /tmp/avalanchego-v${VERSION}
fi
find /tmp/avalanchego-v${VERSION}

AVALANCHEGO_PATH=/tmp/avalanchego-v${VERSION}/avalanchego
AVALANCHEGO_PLUGIN_DIR=/tmp/avalanchego-v${VERSION}/plugins

#################################
# download avalanche-network-runner
# https://github.com/ava-labs/avalanche-network-runner
# TODO: use "go install -v github.com/ava-labs/avalanche-network-runner/cmd/avalanche-network-runner@v${NETWORK_RUNNER_VERSION}"
NETWORK_RUNNER_VERSION=1.0.16
DOWNLOAD_PATH=/tmp/avalanche-network-runner.tar.gz
DOWNLOAD_URL=https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_linux_amd64.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
DOWNLOAD_URL=https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_darwin_amd64.tar.gz
fi

rm -f ${DOWNLOAD_PATH}
rm -f /tmp/avalanche-network-runner

echo "downloading avalanche-network-runner ${NETWORK_RUNNER_VERSION} at ${DOWNLOAD_URL}"
curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded avalanche-network-runner"
tar xzvf ${DOWNLOAD_PATH} -C /tmp
/tmp/avalanche-network-runner -h

#################################
echo "building e2e.test"
# to install the ginkgo binary (required for test build and run)
go install -v github.com/onsi/ginkgo/v2/ginkgo@v2.1.3
ACK_GINKGO_RC=true ginkgo build ./tests/e2e
./tests/e2e/e2e.test --help

#################################
# run "avalanche-network-runner" server
echo "launch avalanche-network-runner in the background"
/tmp/avalanche-network-runner \
server \
--log-level debug \
--port=":12342" \
--disable-grpc-gateway &
PID=${!}

#################################
# By default, it runs all e2e test cases!
# Use "--ginkgo.skip" to skip tests.
# Use "--ginkgo.focus" to select tests.
echo "running e2e tests"
./tests/e2e/e2e.test \
--ginkgo.v \
--log-level debug \
--network-runner-grpc-endpoint="0.0.0.0:12342" \
--network-runner-avalanchego-path=${AVALANCHEGO_PATH} \
--network-runner-avalanchego-log-level=${AVALANCHE_LOG_LEVEL} || EXIT_CODE=$?

# "e2e.test" already terminates the cluster
# just in case tests are aborted, manually terminate them again
pkill -P ${PID} || true
kill -2 ${PID}

if [[ ${EXIT_CODE} -gt 0 ]]; then
echo "FAILURE with exit code ${EXIT_CODE}"
exit ${EXIT_CODE}
else
echo "ALL SUCCESS!"
fi
86 changes: 86 additions & 0 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// e2e implements the e2e tests.
package e2e

import (
"sync"
"time"

runner_sdk "github.com/ava-labs/avalanche-network-runner-sdk"
)

const (
// Enough for primary.NewWallet to fetch initial UTXOs.
DefaultWalletCreationTimeout = 5 * time.Second

// Defines default tx confirmation timeout.
// Enough for test/custom networks.
DefaultConfirmTxTimeout = 10 * time.Second
)

var (
runnerMu sync.RWMutex
runnerCli runner_sdk.Client
runnerGRPCEp string
)

func SetRunnerClient(logLevel string, gRPCEp string) (cli runner_sdk.Client, err error) {
runnerMu.Lock()
defer runnerMu.Unlock()

cli, err = runner_sdk.New(runner_sdk.Config{
LogLevel: logLevel,
Endpoint: gRPCEp,
DialTimeout: 10 * time.Second,
})
if err != nil {
return nil, err
}
if runnerCli != nil {
runnerCli.Close()
}
runnerCli = cli
runnerGRPCEp = gRPCEp
return cli, err
}

func GetRunnerClient() (cli runner_sdk.Client) {
runnerMu.RLock()
cli = runnerCli
runnerMu.RUnlock()
return cli
}

func CloseRunnerClient() (err error) {
runnerMu.Lock()
err = runnerCli.Close()
runnerMu.Unlock()
return err
}

func GetRunnerGRPCEndpoint() (ep string) {
runnerMu.RLock()
ep = runnerGRPCEp
runnerMu.RUnlock()
return ep
}

var (
urisMu sync.RWMutex
uris []string
)

func SetURIs(us []string) {
urisMu.Lock()
uris = us
urisMu.Unlock()
}

func GetURIs() []string {
urisMu.RLock()
us := uris
urisMu.RUnlock()
return us
}
Loading