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

[TT-561] move chainlink-env as a package #743

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5ec56c5
move chainlink-env as a package
Tofel Oct 20, 2023
d6d49f8
fix go.mod
Tofel Oct 20, 2023
3536450
fix linter errors
Tofel Oct 20, 2023
234b002
update MDs, ignore exposing test db password in SQ
Tofel Oct 20, 2023
02ee426
update env workflows, try to run them
Tofel Oct 20, 2023
8b6bf0c
do not run env e2e tests in unit test job
Tofel Oct 20, 2023
4723fc5
do not run tests from env/examples in unit tests
Tofel Oct 20, 2023
69b1ef5
fix workflow lint
Tofel Oct 20, 2023
4f0e9bc
properly disable spellcheck for test.yaml + try env e2e job
Tofel Oct 20, 2023
11b9c99
trigger env e2e tests
Tofel Oct 20, 2023
a73f86c
reorganise workflows
Tofel Oct 20, 2023
27d94ba
fix custom message in action summary for env e2e tests & make shellch…
Tofel Oct 20, 2023
e67c5d5
review golangci-lint config and fix sensible issues
Tofel Oct 20, 2023
9bd3a23
trigger e2e tests
Tofel Oct 20, 2023
38edb74
fix env/Dockerfile
Tofel Oct 20, 2023
fee07bb
adjust ECR repo name
Tofel Oct 20, 2023
abd4f81
try to fix e2e test summary messages
Tofel Oct 20, 2023
a705bde
adjust test env type name for remote runner tests
Tofel Oct 20, 2023
f405c66
more debug to see which readiness probe is failing
Tofel Oct 23, 2023
ed08e87
restore Dockerfile, add backticks to GH summary output
Tofel Oct 23, 2023
0da03eb
adjust Dockerfile and GH summary again
Tofel Oct 23, 2023
08342b4
fix incorrect char escape
Tofel Oct 23, 2023
cf7b4b1
fix lint
Tofel Oct 23, 2023
e48af06
Fix race condition when applying a chaos experiment
tateexon Oct 23, 2023
b49ba4c
add pre-push hook that will run linters and unit tests (#744)
Tofel Oct 20, 2023
2870b79
fix worklow name typo and remove env/logging package
Tofel Oct 24, 2023
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
123 changes: 123 additions & 0 deletions .github/workflows/env-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Env deployments tests (E2E)
on:
push:
paths:
- "env/**"

concurrency:
group: e2e-tests-chainlink-env-${{ github.ref }}
cancel-in-progress: true

env:
INTERNAL_DOCKER_REPO: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com
ENV_JOB_IMAGE: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/chainlink-testing-framework-tests:ci.${{ github.sha }}
BASE_IMAGE_NAME: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/test-base-image:ci.${{ github.sha }}
CHAINLINK_IMAGE: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/chainlink
CHAINLINK_VERSION: develop
SELECTED_NETWORKS: SIMULATED
CHAINLINK_COMMIT_SHA: ${{ github.sha }}
CHAINLINK_ENV_USER: ${{ github.actor }}
TEST_LOG_LEVEL: debug

jobs:
build_tests:
runs-on: ubuntu-latest
environment: integration
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Build Base Image
uses: smartcontractkit/chainlink-github-actions/docker/build-push@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
with:
tags: ${{ env.BASE_IMAGE_NAME }}
file: env/Dockerfile.base
AWS_REGION: ${{ secrets.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
- name: Base Image Built
run: |
# shellcheck disable=SC2086
cat <<EOT >>$GITHUB_STEP_SUMMARY
### chainlink image tag used for this test run :link: => \`${{ env.CHAINLINK_VERSION }}\`
### test-base-image image tag for this test run :ship: => \`ci.${{ github.sha }}\`
EOT
- name: Build Test Runner
uses: smartcontractkit/chainlink-github-actions/docker/build-push@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
with:
tags: ${{ env.ENV_JOB_IMAGE }}
file: env/Dockerfile
build-args: |
BASE_IMAGE=${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/test-base-image
IMAGE_VERSION=ci.${{ github.sha }}
AWS_REGION: ${{ secrets.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
- name: Test Image Built
run: |
# shellcheck disable=SC2086
cat <<EOT >>$GITHUB_STEP_SUMMARY
### chainlink-env-tests image tag for this test run :ship: -> \`ci.${{ github.sha }}\`
EOT
e2e_tests:
runs-on: ubuntu-latest
environment: integration
permissions:
id-token: write
contents: read
env:
TEST_SUITE: local-runner
steps:
- uses: actions/checkout@v3
- name: Run Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
with:
cl_repo: ${{ env.CHAINLINK_IMAGE }}
cl_image_tag: ${{ env.CHAINLINK_VERSION }}
test_command_to_run: unset ENV_JOB_IMAGE && cd env && make test_e2e_ci
test_download_vendor_packages_command: go mod download
artifacts_location: ./e2e/logs
publish_check_name: E2E Test Results
token: ${{ secrets.GITHUB_TOKEN }}
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
- name: Upload test log
uses: actions/upload-artifact@v3
if: failure()
with:
name: test-log
path: /tmp/gotest.log

e2e_remote_runner_tests:
runs-on: ubuntu-latest
environment: integration
needs: [build_tests]
permissions:
id-token: write
contents: read
env:
TEST_SUITE: remote-runner
TEST_TRIGGERED_BY: chainlink-env-remote-runner-ci
steps:
- uses: actions/checkout@v3
- name: Run Remote Runner Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
with:
cl_repo: ${{ env.CHAINLINK_IMAGE }}
cl_image_tag: ${{ env.CHAINLINK_VERSION }}
test_command_to_run: cd env && make test_e2e_ci_remote_runner
test_download_vendor_packages_command: go mod download
artifacts_location: ./e2e/logs
publish_check_name: E2E Remote Runner Test Results
token: ${{ secrets.GITHUB_TOKEN }}
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
- name: Upload test log
uses: actions/upload-artifact@v2
if: failure()
with:
name: remote-runner-test-log
path: /tmp/remoterunnergotest.log
27 changes: 27 additions & 0 deletions .github/workflows/env-publish-test-bash-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish Test Base Image (Env)
Tofel marked this conversation as resolved.
Show resolved Hide resolved
on:
push:
tags:
- 'v*'
paths:
- "env/**"

jobs:
publish_test_base_image:
if: ${{ false }}
runs-on: ubuntu-latest
environment: integration
permissions:
id-token: write
contents: read
env:
BASE_IMAGE_TAG: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/test-base-image:${{ github.ref_name }}
steps:
- uses: actions/checkout@v3
- name: Build Base Image
uses: smartcontractkit/chainlink-github-actions/docker/build-push@cb4a8f51d77cbf77ea6a765bd1f437ffc7a18730 # v2.0.28
with:
tags: ${{ env.BASE_IMAGE_TAG }}
file: env/Dockerfile.base
AWS_REGION: ${{ secrets.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
PATH=$PATH:$(go env GOPATH)/bin
export PATH
set -euo pipefail
go test -json -cover -covermode=count -coverprofile=unit-test-coverage.out ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
# disabled, because we want to use a multiline output of go list command
# shellcheck disable=SC2046
go test -json -cover -covermode=count -coverprofile=unit-test-coverage.out $(go list ./... | grep -v /env/e2e/ | grep -v /env/examples/) 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Code Coverage
uses: codecov/codecov-action@v3
with:
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ docs/Gemfile.lock
dist/

**/remote_runner_config.yaml
logs/
logs/

env/cmd/chaos
env/bin/
# temp manifest for deployment and validation
tmp-manifest-*.yaml
# remote runner binary
remote.test
e2e.test

k3dvolume/
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ run:
timeout: 5m
skip-dirs:
- contracts/ethereum
- examples
- imports
linters:
enable:
# defaults
Expand Down
5 changes: 4 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
golang 1.21.3
nodejs 14.20.0
k3d 5.4.6
k3d 5.5.1
act 0.2.30
golangci-lint 1.54.2
actionlint 1.6.17
shellcheck 0.9.0
helm 3.10.3
kubectl 1.25.5
yarn 1.22.19
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ compile_contracts:
python3 ./utils/compile_contracts.py

test_unit: install_gotestfmt
go test -json -cover -covermode=count -coverprofile=unit-test-coverage.out ./client ./gauntlet ./testreporters ./docker/test_env 2>&1 | tee /tmp/gotest.log | gotestfmt
go test -json -cover -covermode=count -coverprofile=unit-test-coverage.out ./client ./gauntlet ./testreporters ./docker/test_env ./env/config 2>&1 | tee /tmp/gotest.log | gotestfmt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

</div>

The Chainlink Testing Framework is a blockchain development framework written in Go. Its primary purpose is to help chainlink developers create extensive integration, e2e, performance, and chaos tests to ensure the stability of the chainlink project. It can also be helpful to those who just want to use chainlink oracles in their projects to help test their contracts, or even for those that aren't using chainlink. This project makes ample use of the [chainlink-env](https://github.com/smartcontractkit/chainlink-env) package to launch resources and testing apparatus.
The Chainlink Testing Framework is a blockchain development framework written in Go. Its primary purpose is to help chainlink developers create extensive integration, e2e, performance, and chaos tests to ensure the stability of the chainlink project. It can also be helpful to those who just want to use chainlink oracles in their projects to help test their contracts, or even for those that aren't using chainlink.

If you're looking to implement a new chain integration for the testing framework, head over to the [blockchain](./blockchain/) directory for more info.
2 changes: 1 addition & 1 deletion blockchain/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"go.uber.org/atomic"
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink-env/environment"
"github.com/smartcontractkit/chainlink-testing-framework/env/environment"

"github.com/smartcontractkit/chainlink-testing-framework/utils"
)
Expand Down
6 changes: 3 additions & 3 deletions client/mockserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"strings"

"github.com/go-resty/resty/v2"

"github.com/rs/zerolog/log"
"github.com/smartcontractkit/chainlink-env/environment"
"github.com/smartcontractkit/chainlink-env/pkg/helm/mockserver"

"github.com/smartcontractkit/chainlink-testing-framework/env/environment"
"github.com/smartcontractkit/chainlink-testing-framework/env/pkg/helm/mockserver"
)

// MockserverClient mockserver client
Expand Down
4 changes: 2 additions & 2 deletions client/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"strings"

"github.com/jmoiron/sqlx"
"github.com/smartcontractkit/chainlink-env/environment"

// import for side effect of sql packages
_ "github.com/lib/pq"
"github.com/rs/zerolog/log"

"github.com/smartcontractkit/chainlink-testing-framework/env/environment"
)

// PostgresConnector sqlx postgres connector
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ Here you'll find some guidelines on writing blockchain tests using this framewor

Some notable packages we use include:

* [chainlink-env](https://github.com/smartcontractkit/chainlink-env)
* [zerolog](https://github.com/rs/zerolog)
* [Kubernetes](https://github.com/kubernetes/kubernetes)
6 changes: 3 additions & 3 deletions docs/setup/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ parent: Setup

# Test Setup Code

Now that we've got our config and Kubernetes sorted, we can write a bit of code that will deploy an environment for our test to run. To deploy our simulated geth, mock-server, and Chainlink instances, we rely on another chainlink library, [chainlink-env](https://github.com/smartcontractkit/chainlink-env/). This library handles deploying everything our test needs to the Kubernetes cluster.
Now that we've got our config and Kubernetes sorted, we can write a bit of code that will deploy an environment for our test to run. To deploy our simulated geth, mock-server, and Chainlink instances, we rely on `env` package. This package handles deploying everything our test needs to the Kubernetes cluster.

```go
// We use the chainlink-env library to make and handle deployed resources
import "github.com/smartcontractkit/chainlink-env/environment"
// We use the env package to make and handle deployed resources
import "github.com/smartcontractkit/chainlink-testing-framework/env/environment"

// Deploy a testing environment, and receive it as the `env` variable. This is used to connect to resources.
e = environment.New(nil)
Expand Down
13 changes: 13 additions & 0 deletions env/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmd/chaos
bin/
# temp manifest for deployment and validation
tmp-manifest-*.yaml
# remote runner binary
remote.test
e2e.test

.vscode/
.idea/
.direnv/

k3dvolume/
53 changes: 53 additions & 0 deletions env/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
project_name: chainlink-env

release:
github:
owner: smartcontractkit
name: chainlink-env

builds:
- binary: chainlink-env
goos:
- darwin
- linux
goarch:
- amd64
- arm64
goarm:
- 6
- 7
gomips:
- hardfloat
env:
- CGO_ENABLED=0
main: cmd/wizard/chainlink-env.go
flags:
- -trimpath
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}

archives:
- format: tar.gz
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
files:
- LICENSE
- README.md

snapshot:
name_template: SNAPSHOT-{{ .Commit }}

checksum:
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'

changelog:
sort: asc
filters:
exclude:
- '(?i)^docs?:'
- '(?i)^docs\([^:]+\):'
- '(?i)^docs\[[^:]+\]:'
- '^tests?:'
- '(?i)^dev:'
- '^build\(deps\): bump .* in /docs \(#\d+\)'
- Merge pull request
- Merge branch
7 changes: 7 additions & 0 deletions env/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
golang 1.21.1
helm 3.10.3
golangci-lint 1.51.1
kubectl 1.25.5
nodejs 18.13.0
yarn 1.22.19
k3d 5.5.1
7 changes: 7 additions & 0 deletions env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG BASE_IMAGE
ARG IMAGE_VERSION=latest
FROM ${BASE_IMAGE}:${IMAGE_VERSION}
COPY . testdir/
WORKDIR /go/testdir
RUN ./env/scripts/buildTests
ENTRYPOINT ["./env/scripts/entrypoint"]
Loading
Loading