Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TT-472 migration docker tests #10199

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 19 additions & 60 deletions integration-tests/migration/upgrade_version_test.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,37 @@
package migration

import (
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-env/environment"
"github.com/smartcontractkit/chainlink-env/pkg/helm/chainlink"
"github.com/smartcontractkit/chainlink-env/pkg/helm/ethereum"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/config"
"github.com/smartcontractkit/chainlink/integration-tests/networks"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
"os"
)

func TestVersionUpgrade(t *testing.T) {
t.Parallel()
testEnvironment, testNetwork := setupUpgradeTest(t)
if testEnvironment.WillUseRemoteRunner() {
return
}
env, err := test_env.NewCLTestEnvBuilder().
WithGeth().
WithCLNodes(1).
Build()
require.NoError(t, err)

upgradeImage, err := utils.GetEnv("UPGRADE_IMAGE")
require.NoError(t, err, "Error getting upgrade image")
upgradeVersion, err := utils.GetEnv("UPGRADE_VERSION")
require.NoError(t, err, "Error getting upgrade version")

chainClient, err := blockchain.NewEVMClient(testNetwork, testEnvironment)
require.NoError(t, err, "Connecting to blockchain nodes shouldn't fail")
chainlinkNodes, err := client.ConnectChainlinkNodes(testEnvironment)
require.NoError(t, err, "Connecting to chainlink nodes shouldn't fail")

t.Cleanup(func() {
err := actions.TeardownSuite(t, testEnvironment, utils.ProjectRoot, chainlinkNodes, nil, zapcore.ErrorLevel, chainClient)
require.NoError(t, err, "Error tearing down environment")
})

err = actions.UpgradeChainlinkNodeVersions(testEnvironment, upgradeImage, upgradeVersion, chainlinkNodes[0])
require.NoError(t, err, "Upgrading chainlink nodes shouldn't fail")
}

func setupUpgradeTest(t *testing.T) (
testEnvironment *environment.Environment,
testNetwork blockchain.EVMNetwork,
) {
testNetwork = networks.SelectedNetwork
evmConfig := ethereum.New(nil)
if !testNetwork.Simulated {
evmConfig = ethereum.New(&ethereum.Props{
NetworkName: testNetwork.Name,
Simulated: testNetwork.Simulated,
WsURLs: testNetwork.URLs,
})
}
charts, err := chainlink.NewDeployment(1, map[string]any{
"toml": client.AddNetworksConfig(config.BaseOCRP2PV1Config, testNetwork),
"db": map[string]any{
"stateful": true,
},
})
require.NoError(t, err, "Error creating chainlink deployments")
testEnvironment = environment.New(&environment.Config{
NamespacePrefix: fmt.Sprintf("upgrade-version-%s", strings.ReplaceAll(strings.ToLower(testNetwork.Name), " ", "-")),
Test: t,
}).
AddHelm(evmConfig).
AddHelmCharts(charts)
err = testEnvironment.Run()
require.NoError(t, err, "Error launching test environment")
return testEnvironment, testNetwork
_ = os.Setenv("CHAINLINK_IMAGE", upgradeImage)
_ = os.Setenv("CHAINLINK_VERSION", upgradeVersion)

// just restarting CL container with the same name, DB is still the same
//
// [Database]
// MigrateOnStartup = true
//
// by default
err = env.CLNodes[0].Restart(env.CLNodes[0].NodeConfig)
require.NoError(t, err)
}
Loading