Skip to content

Commit

Permalink
Merge branch 'main' into TT-1830
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl committed Nov 12, 2024
2 parents 6e37551 + b6fcd0d commit fae9ddc
Show file tree
Hide file tree
Showing 77 changed files with 4,397 additions and 2,849 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ on:
push:
branches:
- main
tags:
- '*'

jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0 # Fetch all history for all tags

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
uses: peaceiris/actions-mdbook@v2
with:
mdbook-version: '0.4.40'

Expand All @@ -29,7 +33,7 @@ jobs:
mdbook build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: book
82 changes: 82 additions & 0 deletions .github/workflows/framework-golden-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Framework Golden Tests Examples
on:
push:

jobs:
test:
defaults:
run:
working-directory: framework/examples/myproject
env:
LOKI_TENANT_ID: promtail
LOKI_URL: http://localhost:3030/loki/api/v1/push
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
test:
- name: TestSmoke
config: smoke.toml
count: 1
timeout: 10m
- name: TestLoad
config: load.toml
count: 1
timeout: 10m
- name: TestChaos
config: chaos.toml
count: 1
timeout: 10m
- name: TestUpgradeAll
config: upgrade_all.toml
count: 1
timeout: 10m
- name: TestUpgradeSome
config: upgrade_some.toml
count: 1
timeout: 10m
steps:
- name: Checkout repo
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ secrets.PUBLIC_AWS_ECR_ROLE }}
aws-region: us-east-1
- name: Authenticate to ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
with:
registry-type: public
- name: Check for changes in Framework
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
filters: |
src:
- 'framework/**'
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22.8
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: go-modules-${{ hashFiles('framework/examples/myproject/go.sum') }}-${{ runner.os }}-framework-golden-examples
restore-keys: |
go-modules-${{ runner.os }}-framework-golden-examples
go-modules-${{ runner.os }}
- name: Install dependencies
run: go mod download
- name: Run Docker Component Tests
if: steps.changes.outputs.src == 'true'
env:
CTF_CONFIGS: ${{ matrix.test.config }}
run: |
go test -timeout ${{ matrix.test.timeout }} -v -count ${{ matrix.test.count }} -run ${{ matrix.test.name }}
15 changes: 14 additions & 1 deletion .github/workflows/framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@ jobs:
run:
working-directory: framework
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ secrets.PUBLIC_AWS_ECR_ROLE }}
aws-region: us-east-1
- name: Authenticate to ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
with:
registry-type: public
- name: Check for changes in Framework
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
Expand All @@ -25,7 +38,7 @@ jobs:
with:
go-version: 1.22.8
- name: Cache Go modules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[![Seth tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Aseth%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)
[![Havoc tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Ahavoc%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)

![Tests](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/test.yaml/badge.svg)
![Lint](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/lint.yaml/badge.svg)
[![Tests](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/test.yaml/badge.svg)](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/test.yaml)
[![Lints](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/lint.yaml/badge.svg)](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/lint.yaml)

[![Go Report Card](https://goreportcard.com/badge/github.com/smartcontractkit/chainlink-testing-framework)](https://goreportcard.com/report/github.com/smartcontractkit/chainlink-testing-framework)
![Go Version](https://img.shields.io/github/go-mod/go-version/smartcontractkit/chainlink-testing-framework?filename=./lib/go.mod)
Expand Down
10 changes: 8 additions & 2 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
- [CLI](./framework/cli.md)
- [Configuration](./framework/configuration.md)
- [Test Configuration](./framework/test_configuration_overrides.md)
- [Caching](framework/components/caching.md)
- [Components Persistence](framework/components/state.md)
- [Components Caching](framework/components/caching.md)
- [External Environment](framework/components/external.md)
- [Secrets]()
- [Docker](framework/docker.md)
- [Observability Stack](framework/observability/observability_stack.md)
- [Metrics](framework/observability/metrics.md)
- [Logs](framework/observability/logs.md)
Expand All @@ -36,8 +39,11 @@
- [Chainlink]()
- [RPC]()
- [Loki]()
- [Testing](framework/testing.md)
- [Smoke]()
- [Performance]()
- [Chaos]()
- [Interactive](framework/interactive.md)
- [Continuous Integration](ci/ci.md)
- [Libraries](./libraries.md)
- [Seth](./libs/seth.md)
- [WASP](./libs/wasp.md)
Expand Down
5 changes: 0 additions & 5 deletions book/src/ci/ci.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/framework/components/blockchains/anvil.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Config struct {
func TestDON(t *testing.T) {
in, err := framework.Load[Config](t)
require.NoError(t, err)
pkey := os.Getenv("PRIVATE_KEY")

// deploy anvil blockchain simulator
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
Expand Down
20 changes: 1 addition & 19 deletions book/src/framework/components/caching.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Component caching

We use component caching to accelerate test development and enforce idempotent test actions.
We use component caching to accelerate test development and enforce idempotent test actions development.

Each component is isolated by means of inputs and outputs.

Expand All @@ -9,21 +9,3 @@ If cached config has any outputs with `use_cache = true` it will be used instead
```
export CTF_CONFIGS=smoke-cache.toml
```

### Using remote components

Because components are decoupled through outputs, you can use a cached config and switch outputs to any deployed infrastructure, such as staging. This allows you to reuse the same testing logic for behavior validation.

Example:
```
[blockchain_a.out]
use_cache = true
chain_id = '31337'
[[blockchain_a.out.nodes]]
ws_url = 'ws://127.0.0.1:33447'
http_url = 'http://127.0.0.1:33447'
docker_internal_ws_url = 'ws://anvil-3716a:8900'
docker_internal_http_url = 'http://anvil-3716a:8900'
```
Set flag `use_cache = true` on any component output, change output fields as needed and run your test again.
105 changes: 105 additions & 0 deletions book/src/framework/components/chainlink/node.md
Original file line number Diff line number Diff line change
@@ -1 +1,106 @@
# Node

Here we provide *full* configuration parameters for `Node`

<div class="warning">
Here we provide full configuration reference, if you want to copy and run it, please remove all .out fields before!
</div>


## Configuration
```toml
[cl_node]
# Optional URL for fake data provider URL
# usually set up in test with local mock server
data_provider_url = "http://example.com"

[cl_node.db]
# PostgreSQL image version and tag
image = "postgres:15.6"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = true

[cl_node.node]
# A list of paths to capability binaries
capabilities = ["./capability_1", "./capability_2"]
# Default capabilities directory inside container
capabilities_container_dir = "/home/capabilities"
# Image to use, you can either provide "image" or "docker_file" + "docker_ctx" fields
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
# Path to your Chainlink Dockerfile
docker_file = "../../core/chainlink.Dockerfile"
# Path to docker context that should be used to build from
docker_ctx = "../.."
# Optional name for image we build, default is "ctftmp"
docker_image_name = "ctftmp"
# Pulls the image every time if set to 'true', used like that in CI. Can be set to 'false' to speed up local runs
pull_image = true
# Overrides Chainlink node TOML configuration
# can be multiline, see example
user_config_overrides = """
[Log]
level = 'info'
"""
# Overrides Chainlink node secrets TOML configuration
# you can only add fields, overriding existing fields is prohibited by Chainlink node
user_secrets_overrides = """
[AnotherSecret]
mySecret = 'a'
"""

# Outputs are the results of deploying a component that can be used by another component
[cl_node.out]
# If 'use_cache' equals 'true' we skip component setup when we run the test and return the outputs
use_cache = true
# Describes deployed or external Chainlink node
[cl_node.out.node]
# Host Docker URLs the test uses
# in case of using external component you can replace these URLs with another deployment
p2p_url = "http://127.0.0.1:32812"
url = "http://127.0.0.1:32847"

# Describes deployed or external Chainlink node
[cl_node.out.postgresql]
# PostgreSQL connection string
# in case of using external database can be overriden
url = "postgresql://chainlink:[email protected]:32846/chainlink?sslmode=disable"
```

## Usage
```golang
package yourpackage_test

import (
"fmt"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/clnode"
"github.com/stretchr/testify/require"
"testing"
)

type Step2Cfg struct {
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
CLNode *clnode.Input `toml:"cl_node" validate:"required"`
}

func TestMe(t *testing.T) {
in, err := framework.Load[Step2Cfg](t)
require.NoError(t, err)

bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
require.NoError(t, err)

networkCfg, err := clnode.NewNetworkCfgOneNetworkAllNodes(bc)
require.NoError(t, err)
in.CLNode.Node.TestConfigOverrides = networkCfg

output, err := clnode.NewNodeWithDB(in.CLNode)
require.NoError(t, err)

t.Run("test something", func(t *testing.T) {
fmt.Printf("node url: %s\n", output.Node.HostURL)
require.NotEmpty(t, output.Node.HostURL)
})
}
```
Loading

0 comments on commit fae9ddc

Please sign in to comment.