-
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
16 changed files
with
404 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Chainlink Cluster (NodeSet) Environment Test | ||
|
||
Create a configuration file `smoke.toml` | ||
```toml | ||
funds_eth = 30.0 | ||
|
||
[blockchain_a] | ||
chain_id = "31337" | ||
image = "f4hrenh9it/foundry:latest" | ||
port = "8545" | ||
type = "anvil" | ||
|
||
[contracts] | ||
|
||
[data_provider] | ||
port = 9111 | ||
|
||
[nodeset] | ||
nodes = 5 | ||
override_mode = "all" | ||
|
||
[[nodeset.node_specs]] | ||
|
||
[nodeset.node_specs.db] | ||
image = "postgres:15.6" | ||
pull_image = true | ||
|
||
[nodeset.node_specs.node] | ||
image = "public.ecr.aws/chainlink/chainlink:v2.17.0" | ||
pull_image = true | ||
|
||
``` | ||
|
||
Create a file `smoke_test.go` | ||
```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/fake" | ||
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set" | ||
"github.com/smartcontractkit/chainlink/e2e/capabilities/components/onchain" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
type Config struct { | ||
FundingETH float64 `toml:"funds_eth"` | ||
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` | ||
Contracts *onchain.Input `toml:"contracts" validate:"required"` | ||
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"` | ||
NodeSet *ns.Input `toml:"nodeset" validate:"required"` | ||
} | ||
|
||
func TestNodeSet(t *testing.T) { | ||
in, err := framework.Load[Config](t) | ||
require.NoError(t, err) | ||
|
||
// deploy docker test environment | ||
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) | ||
require.NoError(t, err) | ||
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider) | ||
require.NoError(t, err) | ||
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker) | ||
require.NoError(t, err) | ||
} | ||
``` | ||
|
||
Run it | ||
```bash | ||
go test -v -run TestNodeSet | ||
``` | ||
|
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,11 +1,6 @@ | ||
## CLI | ||
### Install | ||
``` | ||
go get github.com/smartcontractkit/chainlink-testing-framework/framework/cmd && \ | ||
go install github.com/smartcontractkit/chainlink-testing-framework/framework/cmd && \ | ||
mv ~/go/bin/cmd ~/go/bin/ctf | ||
``` | ||
### Usage | ||
|
||
To keep documentation simple we provide CLI docs in "help" format | ||
``` | ||
ctf -h | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Configuration | ||
|
||
### Environment variables | ||
| Name | Description | Possible values | Default | Required? | | ||
|:----------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|-------------------------:|:-------:|:------------------------:| | ||
| CTF_CONFIGS | Path(s) to test config files. <br/>Can be more than one, ex.: smoke.toml,smoke_1.toml,smoke_2.toml.<br/>First filepath will hold all the merged values | Any valid TOML file path | | ✅ | | ||
| CTF_LOG_LEVEL | Harness log level | `info`, `debug`, `trace` | `info` | 🚫 | | ||
| CTF_LOKI_STREAM | Streams all components logs to `Loki`, see params below | `true`, `false` | `false` | 🚫 | | ||
| LOKI_URL | URL to `Loki` push api, should be like`${host}/loki/api/v1/push` | URL | - | If you use `Loki` then ✅ | | ||
| LOKI_TENANT_ID | Streams all components logs to `Loki`, see params below | `true`, `false` | - | If you use `Loki` then ✅ | | ||
| TESTCONTAINERS_RYUK_DISABLED | Testcontainers-Go reaper container, removes all the containers after the test exit | `true`, `false` | `false` | 🚫 | | ||
| RESTY_DEBUG | Log all Resty client HTTP calls | `true`, `false` | `false` | 🚫 | |
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,80 @@ | ||
# 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. | ||
|
||
|
||
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) |
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,80 @@ | ||
# 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. | ||
|
||
|
||
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) |
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 @@ | ||
# Debugger |
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,55 @@ | ||
# 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. | ||
|
||
Create your configuration in `smoke.toml` | ||
```toml | ||
[blockchain_a] | ||
chain_id = "31337" | ||
image = "ghcr.io/gakonst/foundry:latest" | ||
port = "8545" | ||
type = "anvil" | ||
``` | ||
|
||
Create your test in `smoke_test.go` | ||
```golang | ||
package mymodule_test | ||
|
||
import ( | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework" | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
type Config struct { | ||
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` | ||
} | ||
|
||
func TestMe(t *testing.T) { | ||
in, err := framework.Load[Config](t) | ||
require.NoError(t, err) | ||
|
||
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) | ||
require.NoError(t, err) | ||
|
||
t.Run("test something", func(t *testing.T) { | ||
require.NotEmpty(t, bc.Nodes[0].HostHTTPUrl) | ||
}) | ||
} | ||
``` | ||
|
||
Select your configuration by setting `CTF_CONFIGS=smoke.toml` and run it | ||
```bash | ||
go test -v -run TestMe | ||
``` | ||
|
||
Summary: | ||
- We defined configuration for `BlockchainNetwork` | ||
- We've used one CTF component in test and checked if it's working | ||
|
||
You can learn more about [component design](./components/overview.md) or proceed with another example of [connecting Chainlink node](./connecting_chainlink_node.md) | ||
|
||
Learn more about [anvil](./components/blockchains/anvil.md) component. |
Oops, something went wrong.