Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Nov 7, 2024
1 parent 81ed16b commit 938000e
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/framework-golden-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
count: 1
timeout: 10m
- name: TestReload
config: reload.toml
config: upgrade_all.toml
count: 1
timeout: 10m
steps:
Expand Down
18 changes: 15 additions & 3 deletions framework/components/simple_node_set/reload.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package simple_node_set

// UpdateNodeConfigs updates nodes configuration TOML files
import (
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"time"
)

// UpgradeNodeSet updates nodes configuration TOML files
// this API is discouraged, however, you can use it if nodes require restart or configuration updates, temporarily!
func UpdateNodeConfigs(in *Input, cfg string) {
in.NodeSpecs[0].Node.UserConfigOverrides = in.NodeSpecs[0].Node.UserConfigOverrides + cfg
func UpgradeNodeSet(in *Input, bc *blockchain.Output, url string, wait time.Duration) (*Output, error) {
_, err := chaos.ExecPumba("rm --volumes=false re2:node.*|postgresql.*", wait)
if err != nil {
return nil, err
}
in.Out = nil
out, err := NewSharedDBNodeSet(in, bc, url)
in.Out = out
return out, err
}
23 changes: 0 additions & 23 deletions framework/examples/myproject/reload.toml

This file was deleted.

58 changes: 58 additions & 0 deletions framework/examples/myproject/upgrade_all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package examples

import (
"fmt"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
"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/stretchr/testify/require"
"testing"
"time"
)

type CfgUpgradeAll struct {
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
}

func TestUpgradeAll(t *testing.T) {
in, err := framework.Load[CfgReload](t)
require.NoError(t, err)

bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
require.NoError(t, err)
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider)
require.NoError(t, err)

// deploy first time
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
require.NoError(t, err)

c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
require.NoError(t, err)
_, _, err = c[0].CreateJobRaw(testJob)
require.NoError(t, err)

in.NodeSet.NodeSpecs[0].Node.Image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
in.NodeSet.NodeSpecs[0].Node.UserConfigOverrides = `
[Log]
level = 'info'
`

out, err = ns.UpgradeNodeSet(in.NodeSet, bc, dp.BaseURLDocker, 10*time.Second)
require.NoError(t, err)

jobs, _, err := c[0].ReadJobs()
require.NoError(t, err)
fmt.Println(jobs)

t.Run("test something", func(t *testing.T) {
for _, n := range out.CLNodes {
require.NotEmpty(t, n.Node.HostURL)
require.NotEmpty(t, n.Node.HostP2PURL)
}
})
}
63 changes: 63 additions & 0 deletions framework/examples/myproject/upgrade_all.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

[blockchain_a]
chain_id = "31337"
image = "f4hrenh9it/foundry:latest"
port = "8545"
type = "anvil"

[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package examples
import (
"fmt"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
Expand All @@ -13,6 +12,25 @@ import (
"time"
)

const (
testJob = `
type = "cron"
schemaVersion = 1
schedule = "CRON_TZ=UTC */10 * * * * *" # every 10 secs
observationSource = """
// data source 2
fetch [type=http method=GET url="https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"];
parse [type=jsonparse path="RAW,ETH,USD,PRICE"];
multiply [type="multiply" input="$(parse)" times=100]
encode_tx [type="ethabiencode"
abi="submit(uint256 value)"
data="{ \\"value\\": $(multiply) }"]
submit_tx [type="ethtx" to="0x859AAa51961284C94d970B47E82b8771942F1980" data="$(encode_tx)"]
fetch -> parse -> multiply -> encode_tx -> submit_tx
"""`
)

type CfgReload struct {
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
Expand All @@ -34,33 +52,23 @@ func TestReload(t *testing.T) {

c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
require.NoError(t, err)
_, _, err = c[0].CreateJobRaw(`
type = "cron"
schemaVersion = 1
schedule = "CRON_TZ=UTC */10 * * * * *" # every 10 secs
observationSource = """
// data source 2
fetch [type=http method=GET url="https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"];
parse [type=jsonparse path="RAW,ETH,USD,PRICE"];
multiply [type="multiply" input="$(parse)" times=100]
encode_tx [type="ethabiencode"
abi="submit(uint256 value)"
data="{ \\"value\\": $(multiply) }"]
submit_tx [type="ethtx" to="0x859AAa51961284C94d970B47E82b8771942F1980" data="$(encode_tx)"]
fetch -> parse -> multiply -> encode_tx -> submit_tx
"""`)
_, _, err = c[0].CreateJobRaw(testJob)
require.NoError(t, err)

// deploy second time
_, err = chaos.ExecPumba("rm --volumes=false re2:node.*|postgresql.*", 5*time.Second)
require.NoError(t, err)
ns.UpdateNodeConfigs(in.NodeSet, `
[Log]
level = 'info'
`)
out, err = ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
in.NodeSet.NodeSpecs[0].Node.Image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
in.NodeSet.NodeSpecs[0].Node.UserConfigOverrides = `
[Log]
level = 'info'
`
in.NodeSet.NodeSpecs[4].Node.Image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
in.NodeSet.NodeSpecs[4].Node.UserConfigOverrides = `
[Log]
level = 'info'
`

out, err = ns.UpgradeNodeSet(in.NodeSet, bc, dp.BaseURLDocker, 10*time.Second)
require.NoError(t, err)

jobs, _, err := c[0].ReadJobs()
require.NoError(t, err)
fmt.Println(jobs)
Expand Down
63 changes: 63 additions & 0 deletions framework/examples/myproject/upgrade_some.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

[blockchain_a]
chain_id = "31337"
image = "f4hrenh9it/foundry:latest"
port = "8545"
type = "anvil"

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "each"

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

[[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.16.0"
pull_image = false

0 comments on commit 938000e

Please sign in to comment.