diff --git a/.github/workflows/framework-golden-tests.yml b/.github/workflows/framework-golden-tests.yml index ce1f114fd..ace6d5bc1 100644 --- a/.github/workflows/framework-golden-tests.yml +++ b/.github/workflows/framework-golden-tests.yml @@ -31,7 +31,7 @@ jobs: count: 1 timeout: 10m - name: TestReload - config: reload.toml + config: upgrade_all.toml count: 1 timeout: 10m steps: diff --git a/framework/components/simple_node_set/reload.go b/framework/components/simple_node_set/reload.go index 9180defa5..56ed84f56 100644 --- a/framework/components/simple_node_set/reload.go +++ b/framework/components/simple_node_set/reload.go @@ -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 } diff --git a/framework/examples/myproject/reload.toml b/framework/examples/myproject/reload.toml deleted file mode 100644 index acbac497d..000000000 --- a/framework/examples/myproject/reload.toml +++ /dev/null @@ -1,23 +0,0 @@ - -[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.17.0" - pull_image = false diff --git a/framework/examples/myproject/upgrade_all.go b/framework/examples/myproject/upgrade_all.go new file mode 100644 index 000000000..4c383b4bd --- /dev/null +++ b/framework/examples/myproject/upgrade_all.go @@ -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) + } + }) +} diff --git a/framework/examples/myproject/upgrade_all.toml b/framework/examples/myproject/upgrade_all.toml new file mode 100644 index 000000000..0b3a75640 --- /dev/null +++ b/framework/examples/myproject/upgrade_all.toml @@ -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 diff --git a/framework/examples/myproject/reload_test.go b/framework/examples/myproject/upgrade_some.go similarity index 81% rename from framework/examples/myproject/reload_test.go rename to framework/examples/myproject/upgrade_some.go index 9e9732b5c..3242540d5 100644 --- a/framework/examples/myproject/reload_test.go +++ b/framework/examples/myproject/upgrade_some.go @@ -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" @@ -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"` @@ -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) diff --git a/framework/examples/myproject/upgrade_some.toml b/framework/examples/myproject/upgrade_some.toml new file mode 100644 index 000000000..1b21da98d --- /dev/null +++ b/framework/examples/myproject/upgrade_some.toml @@ -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