Skip to content

Commit e1e06fd

Browse files
authored
Merge branch 'main' into TT-1823-final
2 parents 1b273cb + 0f4e9bd commit e1e06fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3987
-692
lines changed

.github/workflows/docs.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: GH Pages Deploy (Docs, mdbook)
2+
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build-deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
15+
16+
- name: Setup mdBook
17+
uses: peaceiris/actions-mdbook@v1
18+
with:
19+
mdbook-version: '0.4.40'
20+
21+
- name: Install Pre-processors
22+
run: |
23+
cargo install mdbook-alerts
24+
cargo install mdbook-cmdrun
25+
26+
- name: Build
27+
working-directory: book
28+
run: |
29+
mdbook build
30+
31+
- name: Deploy to GitHub Pages
32+
uses: peaceiris/actions-gh-pages@v3
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
publish_dir: book

.github/workflows/framework.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Framework Docker Component Tests
2+
on:
3+
push:
4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.ref }}-framework
6+
cancel-in-progress: true
7+
jobs:
8+
test:
9+
defaults:
10+
run:
11+
working-directory: framework
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
16+
- name: Check for changes in Framework
17+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
18+
id: changes
19+
with:
20+
filters: |
21+
src:
22+
- 'framework/**'
23+
- name: Set up Go
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: 1.22.8
27+
- name: Cache Go modules
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.cache/go-build
32+
~/go/pkg/mod
33+
key: go-modules-${{ hashFiles('**/go.sum') }}-${{ runner.os }}-framework
34+
restore-keys: |
35+
go-modules-${{ hashFiles('**/go.sum') }}-${{ runner.os }}-framework
36+
- name: Install dependencies
37+
run: go mod download
38+
- name: Run Docker Component Tests
39+
if: steps.changes.outputs.src == 'true'
40+
run: |
41+
go test -timeout 5m -v -count 1 -run TestDocker ./...

README.md

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
<div align="center">
22

33
# Chainlink Testing Framework
4+
[![Documentation](https://img.shields.io/badge/Documentation-MDBook-blue?style=for-the-badge)](https://smartcontractkit.github.io/chainlink-testing-framework/overview.html)
45

5-
[![Main branch breaking changes check](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/rc-breaking-changes.yaml/badge.svg)](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/rc-breaking-changes.yaml)
6+
[//]: # ([![Main branch breaking changes check]&#40;https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/rc-breaking-changes.yaml/badge.svg&#41;]&#40;https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/rc-breaking-changes.yaml&#41;)
7+
[![Framework tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Aframework%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)
68
[![Lib tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Alib%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)
79
[![WASP tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Awasp%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)
810
[![Seth tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Aseth%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)
911
[![Havoc tag](https://img.shields.io/github/v/tag/smartcontractkit/chainlink-testing-framework?filter=%2Ahavoc%2A)](https://github.com/smartcontractkit/chainlink-testing-framework/tags)
10-
[![Go Report Card](https://goreportcard.com/badge/github.com/smartcontractkit/chainlink-testing-framework)](https://goreportcard.com/report/github.com/smartcontractkit/chainlink-testing-framework)
11-
[![Go Reference](https://pkg.go.dev/badge/github.com/smartcontractkit/chainlink-testing-framework.svg)](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/lib)
12-
![Go Version](https://img.shields.io/github/go-mod/go-version/smartcontractkit/chainlink-testing-framework?filename=./lib/go.mod)
12+
1313
![Tests](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/test.yaml/badge.svg)
1414
![Lint](https://github.com/smartcontractkit/chainlink-testing-framework/actions/workflows/lint.yaml/badge.svg)
15-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1615

16+
[![Go Report Card](https://goreportcard.com/badge/github.com/smartcontractkit/chainlink-testing-framework)](https://goreportcard.com/report/github.com/smartcontractkit/chainlink-testing-framework)
17+
![Go Version](https://img.shields.io/github/go-mod/go-version/smartcontractkit/chainlink-testing-framework?filename=./lib/go.mod)
18+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1719
</div>
1820

19-
The Chainlink Testing Framework (CTF) 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.
20-
21-
If you're looking to implement a new chain integration for the testing framework, head over to the [blockchain](./blockchain/) directory for more info.
22-
23-
# Content
24-
25-
1. [Libraries](#libraries)
26-
2. [Releasing](#releasing)
27-
28-
## Libraries
29-
30-
CTF monorepository contains a set of libraries:
31-
32-
- [Harness](lib/README.md) - Library to interact with different blockchains, create CL node jobs and use k8s and docker.
33-
- [WASP](wasp/README.md) - Scalable protocol-agnostic load testing library for `Go`
34-
- [Havoc](havoc/README.md) - Chaos testing library
35-
- [Seth](seth/README.md) - Ethereum client library with transaction tracing and gas bumping
36-
37-
## Releasing
38-
39-
We follow [SemVer](https://semver.org/) and follow best Go practices for releasing our modules, please follow the [instruction](RELEASE.md)
21+
The Chainlink Testing Framework (CTF) 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.

book/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: run
2+
run:
3+
mdbook serve -p 9999

book/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## MDBook
2+
Install [mdbook](https://github.com/rust-lang/mdBook)
3+
```
4+
cargo install mdbook && \
5+
cargo install mdbook-alerts && \
6+
cargo install mdbook-cmdrun
7+
```
8+
9+
Run it locally
10+
```
11+
make run
12+
```
13+
Open your browser [here](http://localhost:9999/)
14+
15+
GitHub hosted [version](https://smartcontractkit.github.io/chainlink-testing-framework/overview.html)

book/book.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[book]
2+
authors = ["skudasov"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "Chainlink Testing Framework"
7+
8+
[build]
9+
build-dir = "docs"
10+
11+
[output.html]
12+
default-theme = "ayu"
13+
14+
[preprocessor.alerts]
15+
[preprocessor.cmdrun]

book/src/SUMMARY.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Summary
2+
3+
- [Overview](./overview.md)
4+
- [Framework](./framework/overview.md)
5+
- [Getting Started](./framework/getting_started.md)
6+
- [Your First Test](./framework/first_test.md)
7+
- [Connecting Chainlink Node](./framework/connecting_chainlink_node.md)
8+
- [Connecting Chainlink Node (Multiple networks)]()
9+
- [NodeSet Environment](./framework/nodeset_environment.md)
10+
- [NodeSet with Capabilities](./framework/nodeset_capabilities.md)
11+
- [NodeSet with External Blockchain](./framework/nodeset_external.md)
12+
- [NodeSet (Local Docker builds)](./framework/nodeset_docker_rebuild.md)
13+
- [NodeSet Compat Environment](./framework/nodeset_compatibility.md)
14+
- [CLI](./framework/cli.md)
15+
- [Configuration](./framework/configuration.md)
16+
- [Test Configuration](./framework/test_configuration_overrides.md)
17+
- [Secrets]()
18+
- [Observability Stack](framework/observability/observability_stack.md)
19+
- [Metrics]()
20+
- [Logs](framework/observability/logs.md)
21+
- [Profiling](framework/observability/profiling.md)
22+
- [Traces]()
23+
- [Debugger]()
24+
- [Components](framework/components/overview.md)
25+
- [Blockchains](framework/components/blockchains/overview.md)
26+
- [Anvil](framework/components/blockchains/anvil.md)
27+
- [Geth]()
28+
- [Optimism Stack]()
29+
- [Arbitrum Stack]()
30+
- [Chainlink]()
31+
- [Node]()
32+
- [NodeSet]()
33+
- [Clients]()
34+
- [Chainlink]()
35+
- [RPC]()
36+
- [Loki]()
37+
- [Libraries](./libraries.md)
38+
- [Seth](./libs/seth.md)
39+
- [WASP](./libs/wasp.md)
40+
- [Havoc](./libs/havoc.md)
41+
42+
---
43+
44+
- [Developing](developing.md)
45+
- [Components](developing/developing_components.md)
46+
- [Releasing modules](releasing_modules.md)
47+
48+
---
49+
- [Build info](build_info.md)

book/src/build_info.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Build info
2+
3+
This documentation was generated from:
4+
- Branch `<!-- cmdrun git rev-parse --abbrev-ref HEAD -->`
5+
- Commit: `<!-- cmdrun git rev-parse --short HEAD -->`

book/src/developing.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Developing
2+
3+
Here we describe good practices for developing components for our framework.
4+
5+
Rules for components are simple:
6+
- Component should declare some `Input` and an optional `Output` (we use that so we can skip or cache any component results)
7+
- Components should be isolated, they should not return anything except basic types like `int`, `string`, `maps` or `structs`
8+
- Component **must** have documentation under [Components](./framework/components/overview.md), here is an [example](./framework/components/blockchains/anvil.md)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
## Developing Components
2+
3+
To build a scalable framework that enables the reuse of our product deployments (contracts or services in Docker), we need to establish a clear component structure.
4+
5+
```golang
6+
package mycomponent
7+
8+
import (
9+
"fmt"
10+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
11+
)
12+
13+
type Input struct {
14+
// inputs fields that component exposes for configuration
15+
...
16+
// outputs are embedded into inputs so framework can automatically save them
17+
Out *Output `toml:"out"`
18+
}
19+
20+
type Output struct {
21+
UseCache bool `toml:"use_cache"`
22+
// outputs that will be dumped to config and cached
23+
}
24+
25+
26+
func NewComponent(input *Input) (*Output, error) {
27+
if input.Out != nil && input.Out.UseCache {
28+
return input.Out, nil
29+
}
30+
31+
// component logic here
32+
// deploy a docker container(s)
33+
// or deploy a set of smart contracts
34+
35+
input.Out = &Output{
36+
UseCache: true,
37+
// other fields
38+
...
39+
}
40+
return out, nil
41+
}
42+
```
43+
44+
Each component can define inputs and outputs, following these rules:
45+
46+
- Outputs should be included within inputs.
47+
- If your component is used for side effects output can be omitted.
48+
- `input.Out.UseCache` should be added if you'd like to use caching, see more [here](caching)
49+
50+
### Docker components good practices for [testcontainers-go](https://golang.testcontainers.org/):
51+
52+
An example [simple component](../../../../framework/components/blockchain/anvil.go)
53+
54+
An example of [complex component](../../../../framework/components/clnode/clnode.go)
55+
56+
An example of [composite component](../../../../framework/components/simple_node_set/node_set.go)
57+
58+
- Inputs should include at least `image`, `tag` and `pull_image` field
59+
```golang
60+
Image string `toml:"image" validate:"required"`
61+
Tag string `toml:"tag" validate:"required"`
62+
PullImage bool `toml:"pull_image" validate:"required"`
63+
```
64+
65+
- `ContainerRequest` must contain labels, network and alias required for local observability stack and deployment isolation
66+
```golang
67+
Labels: framework.DefaultTCLabels(),
68+
Networks: []string{framework.DefaultNetworkName},
69+
NetworkAliases: map[string][]string{
70+
framework.DefaultNetworkName: {containerName},
71+
},
72+
```
73+
- In order to copy files into container use `framework.WriteTmpFile(data string, fileName string)`
74+
```golang
75+
userSecretsOverridesFile, err := WriteTmpFile(in.Node.UserSecretsOverrides, "user-secrets-overrides.toml")
76+
if err != nil {
77+
return nil, err
78+
}
79+
```
80+
- Output of docker component must contain all the URLs component exposes for access, both for internal docker usage and external test (host) usage
81+
```golang
82+
host, err := framework.GetHost(c)
83+
if err != nil {
84+
return nil, err
85+
}
86+
mp, err := c.MappedPort(ctx, nat.Port(bindPort))
87+
if err != nil {
88+
return nil, err
89+
}
90+
91+
return &NodeOut{
92+
UseCache: true,
93+
DockerURL: fmt.Sprintf("http://%s:%s", containerName, in.Node.Port),
94+
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()),
95+
}, nil
96+
```

0 commit comments

Comments
 (0)