|
| 1 | +# Connecting Chainlink Node |
| 2 | + |
| 3 | +The Chainlink Testing Framework (CTF) is a modular, data-driven tool that lets you explicitly define and configure various Chainlink components. |
| 4 | + |
| 5 | +Let's spin up a simple component. |
| 6 | + |
| 7 | + |
| 8 | +Create your configuration in `smoke.toml` |
| 9 | +```toml |
| 10 | +[blockchain_a] |
| 11 | + chain_id = "31337" |
| 12 | + image = "ghcr.io/gakonst/foundry:latest" |
| 13 | + port = "8545" |
| 14 | + type = "anvil" |
| 15 | + |
| 16 | +[cl_node] |
| 17 | + data_provider_url = "http://example.com" |
| 18 | + |
| 19 | + [cl_node.db] |
| 20 | + image = "postgres:15.6" |
| 21 | + pull_image = true |
| 22 | + |
| 23 | + [cl_node.node] |
| 24 | + image = "public.ecr.aws/chainlink/chainlink:v2.17.0" |
| 25 | + pull_image = true |
| 26 | +``` |
| 27 | + |
| 28 | +Create your test in `smoke_test.go` |
| 29 | +```golang |
| 30 | + |
| 31 | +package capabilities_test |
| 32 | + |
| 33 | +import ( |
| 34 | + "fmt" |
| 35 | + "github.com/smartcontractkit/chainlink-testing-framework/framework" |
| 36 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" |
| 37 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/clnode" |
| 38 | + "github.com/stretchr/testify/require" |
| 39 | + "testing" |
| 40 | +) |
| 41 | + |
| 42 | +type Config struct { |
| 43 | + BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` |
| 44 | + CLNode *clnode.Input `toml:"cl_node" validate:"required"` |
| 45 | +} |
| 46 | + |
| 47 | +func TestNode(t *testing.T) { |
| 48 | + in, err := framework.Load[Config](t) |
| 49 | + require.NoError(t, err) |
| 50 | + |
| 51 | + bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) |
| 52 | + require.NoError(t, err) |
| 53 | + |
| 54 | + networkCfg, err := clnode.NewNetworkCfgOneNetworkAllNodes(bc) |
| 55 | + require.NoError(t, err) |
| 56 | + in.CLNode.Node.TestConfigOverrides = networkCfg |
| 57 | + |
| 58 | + output, err := clnode.NewNodeWithDB(in.CLNode) |
| 59 | + require.NoError(t, err) |
| 60 | + |
| 61 | + t.Run("test something", func(t *testing.T) { |
| 62 | + fmt.Printf("node url: %s\n", output.Node.HostURL) |
| 63 | + require.NotEmpty(t, output.Node.HostURL) |
| 64 | + }) |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +``` |
| 69 | + |
| 70 | +Select your configuration by setting `CTF_CONFIGS=smoke.toml` and run it |
| 71 | +```bash |
| 72 | +go test -v -run TestNode |
| 73 | +``` |
| 74 | + |
| 75 | +Summary: |
| 76 | +- We defined configuration for `BlockchainNetwork` and `NodeWithDB` (Chainlink + PostgreSQL) |
| 77 | +- We connected them together by creating common network config in `NewNetworkCfgOneNetworkAllNodes` |
| 78 | +- We have a Chainlink node running, check `node url: ...` messages in logs to open UI |
| 79 | + |
| 80 | +You can learn more about [component design](./components/overview.md) or proceed with another example of [connecting Chainlink node](./connecting_chainlink_node.md) |
0 commit comments