Skip to content

Commit 112a680

Browse files
committed
try rebuild
1 parent 2776393 commit 112a680

File tree

18 files changed

+330
-30
lines changed

18 files changed

+330
-30
lines changed

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

book/book.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ src = "src"
66
title = "Chainlink Testing Framework"
77

88
[build]
9-
build-dir = "docs"
9+
build-dir = "docs"
10+
11+
[output.html]
12+
default-theme = "ayu"

book/mdbook

-10.7 MB
Binary file not shown.

book/src/SUMMARY.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
- [Libraries](./libraries.md)
55
- [Seth](./libs/seth.md)
66
- [WASP](./libs/wasp.md)
7-
- [Framework](./framework.md)
8-
- [Components](./components.md)
7+
- [Havoc](./libs/havoc.md)
8+
- [Framework](./framework/overview.md)
9+
- [Getting Started](./framework/getting_started.md)
10+
- [CLI](./framework/cli.md)
11+
- [Components](framework/components/overview.md)
12+
- [Blockchains](framework/components/blockchains/overview.md)
13+
- [Anvil](framework/components/blockchains/anvil.md)
914
- [Secrets](./secrets.md)
15+
16+
---
17+
1018
- [Developing](./developing.md)
1119
- [Releasing modules](./releasing_modules.md)

book/src/framework/cli.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## CLI
2+
### Install
3+
```
4+
go get github.com/smartcontractkit/chainlink-testing-framework/framework/cmd && \
5+
go install github.com/smartcontractkit/chainlink-testing-framework/framework/cmd && \
6+
mv ~/go/bin/cmd ~/go/bin/ctf
7+
```
8+
### Usage
9+
```
10+
ctf -h
11+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Anvil
2+
[Anvil](https://book.getfoundry.sh/anvil/) is a Foundry local EVM blockchain simulator
3+
4+
Use `docker_cmd_params = ['--block-time=1', '...']` to provide more params
5+
6+
## Configuration
7+
```toml
8+
[blockchain_a]
9+
chain_id = "31337"
10+
docker_cmd_params = []
11+
image = "ghcr.io/gakonst/foundry:latest"
12+
port = "8545"
13+
pull_image = false
14+
type = "anvil"
15+
16+
[blockchain_a.out]
17+
chain_id = "31337"
18+
use_cache = true
19+
20+
[[blockchain_a.out.nodes]]
21+
docker_internal_http_url = "http://anvil-14411:8545"
22+
docker_internal_ws_url = "ws://anvil-14411:8545"
23+
http_url = "http://127.0.0.1:33955"
24+
ws_url = "ws://127.0.0.1:33955"
25+
```
26+
27+
## Usage
28+
```golang
29+
package my_test
30+
31+
import (
32+
"os"
33+
"testing"
34+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
35+
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
36+
"github.com/stretchr/testify/require"
37+
)
38+
39+
type Config struct {
40+
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
41+
}
42+
43+
func TestDON(t *testing.T) {
44+
in, err := framework.Load[Config](t)
45+
require.NoError(t, err)
46+
pkey := os.Getenv("PRIVATE_KEY")
47+
48+
// deploy anvil blockchain simulator
49+
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
50+
require.NoError(t, err)
51+
}
52+
```
53+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Blockchain components (Simulators)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Component caching
2+
3+
We use component caching to accelerate test development and enforce idempotent test actions.
4+
5+
Each component is designed to be pure with defined inputs/outputs.
6+
7+
You can use an environment variable to skip deployment steps and use cached outputs if your infrastructure is already running (locally or remotely):
8+
9+
```
10+
export CTF_CONFIGS=smoke-cache.toml
11+
```
12+
13+
### Using remote components
14+
15+
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.
16+
17+
Example:
18+
```
19+
[blockchain_a.out]
20+
use_cache = true
21+
chain_id = '31337'
22+
23+
[[blockchain_a.out.nodes]]
24+
ws_url = 'ws://127.0.0.1:33447'
25+
http_url = 'http://127.0.0.1:33447'
26+
docker_internal_ws_url = 'ws://anvil-3716a:8900'
27+
docker_internal_http_url = 'http://anvil-3716a:8900'
28+
```
29+
Set flag `use_cache = true` on any component output and run your test again
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
package mycomponent
6+
7+
import (
8+
"fmt"
9+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
10+
)
11+
12+
type Input struct {
13+
// inputs fields that component exposes for configuration
14+
...
15+
// outputs are embedded into inputs so framework can automatically save them
16+
Out *Output `toml:"out"`
17+
}
18+
19+
type Output struct {
20+
UseCache bool `toml:"use_cache"`
21+
// outputs that will be dumped to config and cached
22+
}
23+
24+
25+
func NewComponent(input *Input) (*Output, error) {
26+
if input.Out.UseCache {
27+
return input.Out, nil
28+
}
29+
30+
// component logic here
31+
// deploy a docker container(s)
32+
// or deploy a set of smart contracts
33+
34+
input.Out = &Output{
35+
UseCache: true,
36+
// other fields
37+
...
38+
}
39+
return out, nil
40+
}
41+
```
42+
Each component can define inputs and outputs, following these rules:
43+
44+
- Outputs should be included within inputs.
45+
- If your component is used for side effects output can be omitted.
46+
- `input.Out.UseCache` should be added if you'd like to use caching, see more [here](caching)
47+
48+
### Docker components good practices for [testcontainers-go](https://golang.testcontainers.org/):
49+
50+
An example [simple component](components/blockchain/anvil.go)
51+
52+
An example of [complex component](components/clnode/clnode.go)
53+
54+
An example of [composite component](components/node_set_extended/don.go)
55+
56+
- Inputs should include at least `image`, `tag` and `pull_image` field
57+
```
58+
Image string `toml:"image" validate:"required"`
59+
Tag string `toml:"tag" validate:"required"`
60+
PullImage bool `toml:"pull_image" validate:"required"`
61+
```
62+
63+
- `ContainerRequest` must contain labels, network and alias required for local observability stack and deployment isolation
64+
```
65+
Labels: framework.DefaultTCLabels(),
66+
Networks: []string{framework.DefaultNetworkName},
67+
NetworkAliases: map[string][]string{
68+
framework.DefaultNetworkName: {containerName},
69+
},
70+
```
71+
- In order to copy files into container use `framework.WriteTmpFile(data string, fileName string)`
72+
```
73+
userSecretsOverridesFile, err := WriteTmpFile(in.Node.UserSecretsOverrides, "user-secrets-overrides.toml")
74+
if err != nil {
75+
return nil, err
76+
}
77+
```
78+
- Output of docker component must contain all the URLs component exposes for access, both for internal docker usage and external test (host) usage
79+
```
80+
host, err := framework.GetHost(c)
81+
if err != nil {
82+
return nil, err
83+
}
84+
mp, err := c.MappedPort(ctx, nat.Port(bindPort))
85+
if err != nil {
86+
return nil, err
87+
}
88+
89+
return &NodeOut{
90+
UseCache: true,
91+
DockerURL: fmt.Sprintf("http://%s:%s", containerName, in.Node.Port),
92+
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()),
93+
}, nil
94+
```

0 commit comments

Comments
 (0)