Skip to content

Commit

Permalink
[TT-549] Renable Live Test Runs (#10379)
Browse files Browse the repository at this point in the history
* Debug on

* Bypass build test

* Change secret names

* Strip Private Keys

* Fix strip

* Fix funding

* Clean imports

* Cleanup

* Formatting

* Remove if check

* Regularly Scheduled Programming
  • Loading branch information
kalverra authored Sep 1, 2023
1 parent 11490c6 commit 50d5570
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 84 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ jobs:
pull-requests: write
id-token: write
contents: read
needs: [build-chainlink, build-test-image]
needs: [build-chainlink]
env:
SELECTED_NETWORKS: ${{ matrix.testnet }}
CHAINLINK_COMMIT_SHA: ${{ github.sha }}
Expand All @@ -812,11 +812,11 @@ jobs:
EVM_KEYS: ${{ secrets.QA_EVM_KEYS }}
TEST_EVM_KEYS: ${{ secrets.QA_EVM_KEYS }}

TEST_OPTIMISM_GOERLI_URLS: ${{ secrets.QA_OPTIMISM_GOERLI_URLS }}
TEST_OPTIMISM_GOERLI_HTTP_URLS: ${{ secrets.QA_OPTIMISM_GOERLI_HTTP_URLS }}
OPTIMISM_GOERLI_URLS: ${{ secrets.QA_OPTIMISM_GOERLI_URLS }}
OPTIMISM_GOERLI_HTTP_URLS: ${{ secrets.QA_OPTIMISM_GOERLI_HTTP_URLS }}

TEST_ARBITRUM_GOERLI_URLS: ${{ secrets.QA_ARBITRUM_GOERLI_URLS }}
TEST_ARBITRUM_GOERLI_HTTP_URLS: ${{ secrets.QA_ARBITRUM_GOERLI_HTTP_URLS }}
ARBITRUM_GOERLI_URLS: ${{ secrets.QA_ARBITRUM_GOERLI_URLS }}
ARBITRUM_GOERLI_HTTP_URLS: ${{ secrets.QA_ARBITRUM_GOERLI_HTTP_URLS }}
strategy:
fail-fast: false
matrix:
Expand Down
9 changes: 5 additions & 4 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TeardownSuite(

for _, c := range clients {
if c != nil && chainlinkNodes != nil && len(chainlinkNodes) > 0 {
if err := returnFunds(chainlinkNodes, c); err != nil {
if err := ReturnFunds(chainlinkNodes, c); err != nil {
// This printed line is required for tests that use real funds to propagate the failure
// out to the system running the test. Do not remove
fmt.Println(environment.FAILED_FUND_RETURN)
Expand Down Expand Up @@ -306,7 +306,7 @@ func TeardownRemoteSuite(
l.Warn().Msgf("Error deleting jobs %+v", err)
}

if err = returnFunds(chainlinkNodes, client); err != nil {
if err = ReturnFunds(chainlinkNodes, client); err != nil {
l.Error().Err(err).Str("Namespace", namespace).
Msg("Error attempting to return funds from chainlink nodes to network's default wallet. " +
"Environment is left running so you can try manually!")
Expand Down Expand Up @@ -337,8 +337,9 @@ func DeleteAllJobs(chainlinkNodes []*client.ChainlinkK8sClient) error {
return nil
}

// Returns all the funds from the chainlink nodes to the networks default address
func returnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient blockchain.EVMClient) error {
// ReturnFunds attempts to return all the funds from the chainlink nodes to the network's default address
// all from a remote, k8s style environment
func ReturnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient blockchain.EVMClient) error {
if blockchainClient == nil {
return errors.New("blockchain client is nil, unable to return funds from chainlink nodes")
}
Expand Down
16 changes: 7 additions & 9 deletions integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/lib/pq"
ocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
ocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers20config "github.com/smartcontractkit/ocr2keepers/pkg/v2/config"
ocr2keepers30config "github.com/smartcontractkit/ocr2keepers/pkg/v3/config"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"

"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func BuildAutoOCR2ConfigVars(
Expand Down
7 changes: 3 additions & 4 deletions integration-tests/docker/test_env/cl_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ import (
"github.com/pelletier/go-toml/v2"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
tc "github.com/testcontainers/testcontainers-go"
tcwait "github.com/testcontainers/testcontainers-go/wait"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logwatch"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"

"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/utils"
Expand Down
43 changes: 42 additions & 1 deletion integration-tests/docker/test_env/test_env.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package test_env

import (
"encoding/json"
"math/big"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
Expand All @@ -12,7 +14,6 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logwatch"

"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"

"github.com/smartcontractkit/chainlink/integration-tests/client"
Expand Down Expand Up @@ -194,3 +195,43 @@ func (te *CLClusterTestEnv) Terminate() error {
// the containers and the Network
return nil
}

// Cleanup cleans the environment up after it's done being used, mainly for returning funds when on live networks.
// Intended to be used as part of t.Cleanup() in tests.
func (te *CLClusterTestEnv) Cleanup() error {
log.Info().Msg("Attempting to return Chainlink node funds to default network wallets")
if te.EVMClient == nil {
return errors.New("blockchain client is nil, unable to return funds from chainlink nodes")
}
if te.CLNodes == nil {
return errors.New("chainlink nodes are nil, unable to return funds from chainlink nodes")
}
if te.EVMClient.NetworkSimulated() {
log.Info().Str("Network Name", te.EVMClient.GetNetworkName()).
Msg("Network is a simulated network. Skipping fund return.")
return nil
}

for _, chainlinkNode := range te.CLNodes {
fundedKeys, err := chainlinkNode.API.ExportEVMKeysForChain(te.EVMClient.GetChainID().String())
if err != nil {
return err
}
for _, key := range fundedKeys {
keyToDecrypt, err := json.Marshal(key)
if err != nil {
return err
}
// This can take up a good bit of RAM and time. When running on the remote-test-runner, this can lead to OOM
// issues. So we avoid running in parallel; slower, but safer.
decryptedKey, err := keystore.DecryptKey(keyToDecrypt, client.ChainlinkKeyPassword)
if err != nil {
return err
}
if err = te.EVMClient.ReturnFunds(decryptedKey.PrivateKey); err != nil {
return err
}
}
}
return nil
}
3 changes: 1 addition & 2 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logwatch"

"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"

"github.com/smartcontractkit/chainlink/integration-tests/contracts"
Expand Down
13 changes: 7 additions & 6 deletions integration-tests/networks/known_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,17 +558,18 @@ func setKeys(prefix string, network *blockchain.EVMNetwork) {
}

envVar := fmt.Sprintf("%s_KEYS", prefix)
keysEnv, err := utils.GetEnv(envVar)
keysFromEnv, err := utils.GetEnv(envVar)
if err != nil {
log.Fatal().Err(err).Str("env var", envVar).Msg("Error getting env var")
}
if keysEnv == "" {
keys := strings.Split(os.Getenv("EVM_KEYS"), ",")
if keysFromEnv == "" {
log.Warn().Msg(fmt.Sprintf("No '%s' env var defined, defaulting to 'EVM_KEYS'", envVar))
network.PrivateKeys = keys
return
keysFromEnv = os.Getenv("EVM_KEYS")
}
keys := strings.Split(keysFromEnv, ",")
for i, key := range keys {
keys[i] = strings.TrimPrefix(key, "0x")
}
keys := strings.Split(keysEnv, ",")
network.PrivateKeys = keys

// log public keys for debugging
Expand Down
44 changes: 34 additions & 10 deletions integration-tests/smoke/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/onsi/gomega"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -108,7 +109,9 @@ func SetupAutomationBasic(t *testing.T, nodeUpgrade bool) {
"registry_2_1_logtrigger": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -234,7 +237,9 @@ func TestAutomationAddFunds(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -288,7 +293,9 @@ func TestAutomationPauseUnPause(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand All @@ -303,7 +310,7 @@ func TestAutomationPauseUnPause(t *testing.T) {

gom := gomega.NewGomegaWithT(t)
gom.Eventually(func(g gomega.Gomega) {
// Check if the upkeeps are performing multiple times by analysing their counters and checking they are greater than 5
// Check if the upkeeps are performing multiple times by analyzing their counters and checking they are greater than 5
for i := 0; i < len(upkeepIDs); i++ {
counter, err := consumers[i].Counter(context.Background())
g.Expect(err).ShouldNot(gomega.HaveOccurred(), "Failed to retrieve consumer counter for upkeep at index %d", i)
Expand Down Expand Up @@ -374,7 +381,9 @@ func TestAutomationRegisterUpkeep(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -448,7 +457,9 @@ func TestAutomationPauseRegistry(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()
chainClient, _, contractDeployer, linkToken, registry, registrar, onlyStartRunner, _ := setupAutomationTest(
Expand Down Expand Up @@ -508,7 +519,9 @@ func TestAutomationKeeperNodesDown(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -596,7 +609,9 @@ func TestAutomationPerformSimulation(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -663,7 +678,9 @@ func TestAutomationCheckPerformGasLimit(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -779,7 +796,9 @@ func TestUpdateCheckData(t *testing.T) {
"registry_2_1": ethereum.RegistryVersion_2_1,
}

for name, registryVersion := range registryVersions {
for n, rv := range registryVersions {
name := n
registryVersion := rv
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -902,6 +921,11 @@ func setupAutomationTest(
require.NoError(t, err, "Error building contract deployer")
chainlinkNodes, err = client.ConnectChainlinkNodes(testEnvironment)
require.NoError(t, err, "Error connecting to Chainlink nodes")
t.Cleanup(func() {
if err := actions.ReturnFunds(chainlinkNodes, chainClient); err != nil {
log.Error().Err(err).Msg("Error returning funds")
}
})
chainClient.ParallelTransactions(true)

txCost, err := chainClient.EstimateCostForChainlinkOperations(1000)
Expand Down
15 changes: 13 additions & 2 deletions integration-tests/smoke/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,34 @@ package smoke

import (
"fmt"
"testing"

"github.com/google/uuid"
"github.com/onsi/gomega"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/utils"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
"github.com/stretchr/testify/require"
"testing"
)

func TestCronBasic(t *testing.T) {
t.Parallel()
l := utils.GetTestLogger(t)

env, err := test_env.NewCLTestEnvBuilder().
WithGeth().
WithMockServer(1).
WithCLNodes(1).
Build()
require.NoError(t, err)
t.Cleanup(func() {
if err := env.Cleanup(); err != nil {
l.Error().Err(err).Msg("Error cleaning up test environment")
}
})

err = env.MockServer.Client.SetValuePath("/variable", 5)
require.NoError(t, err, "Setting value path in mockserver shouldn't fail")

Expand Down
Loading

0 comments on commit 50d5570

Please sign in to comment.