-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
542 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
# Developing | ||
|
||
Here we describe good practices for developing components for our framework. | ||
|
||
Rules for components are simple: | ||
- Component should declare some `Input` and an optional `Output` (we use that so we can skip or cache any component results) | ||
- Components should be isolated, they should not return anything except basic types like `int`, `string`, `maps` or `structs` | ||
- Component **must** have documentation under [Components](./framework/components/overview.md), here is an [example](./framework/components/blockchains/anvil.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
## Developing Components | ||
|
||
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. | ||
|
||
```golang | ||
package mycomponent | ||
|
||
import ( | ||
"fmt" | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework" | ||
) | ||
|
||
type Input struct { | ||
// inputs fields that component exposes for configuration | ||
... | ||
// outputs are embedded into inputs so framework can automatically save them | ||
Out *Output `toml:"out"` | ||
} | ||
|
||
type Output struct { | ||
UseCache bool `toml:"use_cache"` | ||
// outputs that will be dumped to config and cached | ||
} | ||
|
||
|
||
func NewComponent(input *Input) (*Output, error) { | ||
if input.Out != nil && input.Out.UseCache { | ||
return input.Out, nil | ||
} | ||
|
||
// component logic here | ||
// deploy a docker container(s) | ||
// or deploy a set of smart contracts | ||
|
||
input.Out = &Output{ | ||
UseCache: true, | ||
// other fields | ||
... | ||
} | ||
return out, nil | ||
} | ||
``` | ||
|
||
Each component can define inputs and outputs, following these rules: | ||
|
||
- Outputs should be included within inputs. | ||
- If your component is used for side effects output can be omitted. | ||
- `input.Out.UseCache` should be added if you'd like to use caching, see more [here](caching) | ||
|
||
### Docker components good practices for [testcontainers-go](https://golang.testcontainers.org/): | ||
|
||
An example [simple component](../../../../framework/components/blockchain/anvil.go) | ||
|
||
An example of [complex component](../../../../framework/components/clnode/clnode.go) | ||
|
||
An example of [composite component](../../../../framework/components/simple_node_set/node_set.go) | ||
|
||
- Inputs should include at least `image`, `tag` and `pull_image` field | ||
```golang | ||
Image string `toml:"image" validate:"required"` | ||
Tag string `toml:"tag" validate:"required"` | ||
PullImage bool `toml:"pull_image" validate:"required"` | ||
``` | ||
|
||
- `ContainerRequest` must contain labels, network and alias required for local observability stack and deployment isolation | ||
```golang | ||
Labels: framework.DefaultTCLabels(), | ||
Networks: []string{framework.DefaultNetworkName}, | ||
NetworkAliases: map[string][]string{ | ||
framework.DefaultNetworkName: {containerName}, | ||
}, | ||
``` | ||
- In order to copy files into container use `framework.WriteTmpFile(data string, fileName string)` | ||
```golang | ||
userSecretsOverridesFile, err := WriteTmpFile(in.Node.UserSecretsOverrides, "user-secrets-overrides.toml") | ||
if err != nil { | ||
return nil, err | ||
} | ||
``` | ||
- Output of docker component must contain all the URLs component exposes for access, both for internal docker usage and external test (host) usage | ||
```golang | ||
host, err := framework.GetHost(c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mp, err := c.MappedPort(ctx, nat.Port(bindPort)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &NodeOut{ | ||
UseCache: true, | ||
DockerURL: fmt.Sprintf("http://%s:%s", containerName, in.Node.Port), | ||
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()), | ||
}, nil | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
# Components | ||
|
||
CTF contains a lot of useful components, some of them are off-chain services like `Chainlink Node`, `NodeSet` | ||
|
||
CTF contains three groups of components: | ||
- Off-chain services like `CL Node`, `NodeSet`, `JobDistributor`, etc. | ||
- On-chain wrappers for [chainlink-deployments](https://github.com/smartcontractkit/chainlink-deployments) repository | ||
- Test components, blockchain simulators, fakes, etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
# Connecting Chainlink Node | ||
|
||
The Chainlink Testing Framework (CTF) is a modular, data-driven tool that lets you explicitly define and configure various Chainlink components. | ||
|
||
Let's spin up a simple component. | ||
|
||
Now let's have an example of Chainlink node connected to some local blockchain. | ||
|
||
Create your configuration in `smoke.toml` | ||
```toml | ||
|
@@ -72,9 +69,15 @@ Select your configuration by setting `CTF_CONFIGS=smoke.toml` and run it | |
go test -v -run TestNode | ||
``` | ||
|
||
Check `node url: ...` in logs, open it and login using default credentials: | ||
``` | ||
[email protected] | ||
fj293fbBnlQ!f9vNs | ||
``` | ||
|
||
Summary: | ||
- We defined configuration for `BlockchainNetwork` and `NodeWithDB` (Chainlink + PostgreSQL) | ||
- We connected them together by creating common network config in `NewNetworkCfgOneNetworkAllNodes` | ||
- We have a Chainlink node running, check `node url: ...` messages in logs to open UI | ||
- We explored the Chainlink node UI | ||
|
||
You can learn more about [component design](./components/overview.md) or proceed with another example of [connecting Chainlink node](./connecting_chainlink_node.md) | ||
Let's proceed with another example of [using node sets](./nodeset_environment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,14 @@ | ||
# Writing your first test | ||
|
||
The Chainlink Testing Framework (CTF) is a modular, data-driven tool that lets you explicitly define and configure various Chainlink components. | ||
|
||
Let's spin up a simple component. | ||
# Connecting Multiple Blockchain Nodes | ||
|
||
|
||
Create your configuration in `smoke.toml` | ||
```toml | ||
[blockchain_a] | ||
chain_id = "31337" | ||
image = "ghcr.io/gakonst/foundry:latest" | ||
port = "8545" | ||
type = "anvil" | ||
|
||
[cl_node] | ||
data_provider_url = "http://example.com" | ||
|
||
[cl_node.db] | ||
image = "postgres:15.6" | ||
pull_image = true | ||
|
||
[cl_node.node] | ||
image = "public.ecr.aws/chainlink/chainlink:v2.17.0" | ||
pull_image = true | ||
``` | ||
|
||
Create your test in `smoke_test.go` | ||
```golang | ||
|
||
package capabilities_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 Config struct { | ||
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` | ||
CLNode *clnode.Input `toml:"cl_node" validate:"required"` | ||
} | ||
|
||
func TestNode(t *testing.T) { | ||
in, err := framework.Load[Config](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) | ||
}) | ||
} | ||
|
||
|
||
``` | ||
|
||
Select your configuration by setting `CTF_CONFIGS=smoke.toml` and run it | ||
```bash | ||
go test -v -run TestNode | ||
``` | ||
|
||
Summary: | ||
- We defined configuration for `BlockchainNetwork` and `NodeWithDB` (Chainlink + PostgreSQL) | ||
- We connected them together by creating common network config in `NewNetworkCfgOneNetworkAllNodes` | ||
- We have a Chainlink node running, check `node url: ...` messages in logs to open UI | ||
|
||
You can learn more about [component design](./components/overview.md) or proceed with another example of [connecting Chainlink node](./connecting_chainlink_node.md) | ||
``` |
Oops, something went wrong.