Skip to content

Commit

Permalink
Adding soak support
Browse files Browse the repository at this point in the history
  • Loading branch information
smickovskid committed Jun 6, 2024
1 parent 7705e07 commit ea119dd
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ eslint-report.json
override*.toml
# go work files
go.work*
gauntlet-*/
8 changes: 7 additions & 1 deletion integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (m *OCRv2TestState) DeployCluster(contractsDir string) {
if *m.Config.TestConfig.Common.InsideK8s {
m.DeployEnv(contractsDir)

if m.Common.Env.WillUseRemoteRunner() {
return
}

// Setting up the URLs
m.Common.ChainDetails.RPCURLExternal = m.Common.Env.URLs["sol"][0]
m.Common.ChainDetails.WSURLExternal = m.Common.Env.URLs["sol"][1]
Expand Down Expand Up @@ -181,7 +185,9 @@ func (m *OCRv2TestState) DeployEnv(contractsDir string) {
err := m.Common.Env.Run()
require.NoError(m.Config.T, err)

m.UploadProgramBinaries(contractsDir)
if !m.Common.Env.WillUseRemoteRunner() {
m.UploadProgramBinaries(contractsDir)
}
}

func (m *OCRv2TestState) NewSolanaClientSetup(networkSettings *solclient.SolNetwork) (*solclient.Client, error) {
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func TestSolanaOCRV2Smoke(t *testing.T) {
}

state.DeployCluster(utils.ContractsDir)
if state.Common.Env.WillUseRemoteRunner() {
return
}

// copy gauntlet folder to run in parallel (gauntlet generates an output file that is read by the e2e tests - causes conflict if shared)
gauntletCopyPath := utils.ProjectRoot + "/" + name
Expand Down
170 changes: 170 additions & 0 deletions integration-tests/soak/ocr2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package smoke

import (
"fmt"
"maps"
"os/exec"
"testing"
"time"

"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"

"github.com/smartcontractkit/chainlink-solana/integration-tests/common"
ocr_config "github.com/smartcontractkit/chainlink-solana/integration-tests/config"
"github.com/smartcontractkit/chainlink-solana/integration-tests/gauntlet"
tc "github.com/smartcontractkit/chainlink-solana/integration-tests/testconfig"
"github.com/smartcontractkit/chainlink-solana/integration-tests/utils"
)

func TestSolanaOCRV2Soak(t *testing.T) {
for _, test := range []struct {
name string
env map[string]string
}{
{name: "embedded"},
{name: "plugins", env: map[string]string{
"CL_MEDIAN_CMD": "chainlink-feeds",
"CL_SOLANA_CMD": "chainlink-solana",
}},
} {
config, err := tc.GetConfig("Soak", tc.OCR2)
if err != nil {
t.Fatal(err)
}

test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

name := "gauntlet-" + test.name
state, err := common.NewOCRv2State(t, 1, name, &config)
require.NoError(t, err, "Could not setup the ocrv2 state")
if len(test.env) > 0 {
state.Common.TestEnvDetails.NodeOpts = append(state.Common.TestEnvDetails.NodeOpts, func(n *test_env.ClNode) {
if n.ContainerEnvs == nil {
n.ContainerEnvs = map[string]string{}
}
maps.Copy(n.ContainerEnvs, test.env)
})
}

state.DeployCluster(utils.ContractsDir)

if state.Common.Env.WillUseRemoteRunner() {
return
}

// copy gauntlet folder to run in parallel (gauntlet generates an output file that is read by the e2e tests - causes conflict if shared)
gauntletCopyPath := utils.ProjectRoot + "/" + name
if out, cpErr := exec.Command("cp", "-r", utils.ProjectRoot+"/gauntlet", gauntletCopyPath).Output(); cpErr != nil { // nolint:gosec
require.NoError(t, err, "output: "+string(out))
}

sg, err := gauntlet.NewSolanaGauntlet(gauntletCopyPath)
require.NoError(t, err)
state.Gauntlet = sg

if *config.Common.InsideK8s {
t.Cleanup(func() {
if err = actions.TeardownRemoteSuite(t, state.Common.Env.Cfg.Namespace, state.Clients.ChainlinkClient.ChainlinkClientK8s, nil, nil, nil); err != nil {
log.Error().Err(err).Msg("Error tearing down environment")
}
})
}
state.SetupClients()
require.NoError(t, err)

gauntletConfig := map[string]string{
"SECRET": fmt.Sprintf("\"%s\"", *config.SolanaConfig.Secret),
"NODE_URL": state.Common.ChainDetails.RPCURLExternal,
"WS_URL": state.Common.ChainDetails.WSURLExternal,
"PRIVATE_KEY": state.Common.AccountDetails.PrivateKey,
}

err = sg.SetupNetwork(gauntletConfig)
require.NoError(t, err, "Error setting gauntlet network")
err = sg.InstallDependencies()
require.NoError(t, err, "Error installing gauntlet dependencies")

if *config.Common.Network == "devnet" {
state.Common.ChainDetails.ProgramAddresses.OCR2 = *config.SolanaConfig.OCR2ProgramID
state.Common.ChainDetails.ProgramAddresses.AccessController = *config.SolanaConfig.AccessControllerProgramID
state.Common.ChainDetails.ProgramAddresses.Store = *config.SolanaConfig.StoreProgramID
sg.LinkAddress = *config.SolanaConfig.LinkTokenAddress
sg.VaultAddress = *config.SolanaConfig.VaultAddress
} else {
// Deploying LINK in case of localnet
err = sg.DeployLinkToken()
require.NoError(t, err)
}

err = sg.G.WriteNetworkConfigVar(sg.NetworkFilePath, "PROGRAM_ID_OCR2", state.Common.ChainDetails.ProgramAddresses.OCR2)
require.NoError(t, err, "Error adding gauntlet variable")
err = sg.G.WriteNetworkConfigVar(sg.NetworkFilePath, "PROGRAM_ID_ACCESS_CONTROLLER", state.Common.ChainDetails.ProgramAddresses.AccessController)
require.NoError(t, err, "Error adding gauntlet variable")
err = sg.G.WriteNetworkConfigVar(sg.NetworkFilePath, "PROGRAM_ID_STORE", state.Common.ChainDetails.ProgramAddresses.Store)
require.NoError(t, err, "Error adding gauntlet variable")
err = sg.G.WriteNetworkConfigVar(sg.NetworkFilePath, "LINK", sg.LinkAddress)
require.NoError(t, err, "Error adding gauntlet variable")
err = sg.G.WriteNetworkConfigVar(sg.NetworkFilePath, "VAULT_ADDRESS", sg.VaultAddress)
require.NoError(t, err, "Error adding gauntlet variable")

_, err = sg.DeployOCR2()
require.NoError(t, err, "Error deploying OCR")
// Generating default OCR2 config
ocr2Config := ocr_config.NewOCR2Config(state.Clients.ChainlinkClient.NKeys, sg.ProposalAddress, sg.VaultAddress, *config.SolanaConfig.Secret)
ocr2Config.Default()
sg.OCR2Config = ocr2Config

err = sg.ConfigureOCR2()
require.NoError(t, err)

state.CreateJobs()

// Test start
stuck := 0
successFullRounds := 0
prevRound := gauntlet.Transmission{
RoundID: 0,
}
for successFullRounds < *config.OCR2.Smoke.NumberOfRounds {
// Since it is a soak bumping the stuck count
require.Less(t, stuck, 100, "Rounds have been stuck for more than 10 iterations")
log.Info().Str("Transmission", sg.OcrAddress).Msg("Inspecting transmissions")
transmissions, err := sg.FetchTransmissions(sg.OcrAddress)
if err != nil {
log.Error().Str("Contract", "Error fetching transmissions").Msg(fmt.Sprintf("%v", err))
}
if len(transmissions) <= 1 {
log.Info().Str("Contract", sg.OcrAddress).Str("No", "Transmissions")
stuck++
continue
}
currentRound := common.GetLatestRound(transmissions)
if prevRound.RoundID == 0 {
prevRound = currentRound
}
if currentRound.RoundID <= prevRound.RoundID {
log.Info().Str("Transmission", sg.OcrAddress).Msg("No new transmissions")
stuck++
continue
}
log.Info().Str("Contract", sg.OcrAddress).Interface("Answer", currentRound.Answer).Int64("RoundID", currentRound.Answer).Msg("New answer found")
if currentRound.Answer != 5 {
log.Error().Str("Answer", "difference in answer").Msg(fmt.Sprintf("Expected %d, got %d", 5, currentRound.Answer))
}
if prevRound.RoundID > currentRound.RoundID {
log.Error().Str("Answer", "difference in answer").Msg(fmt.Sprintf("Expected round %d to be less than %d", prevRound.RoundID, currentRound.RoundID))
}
prevRound = currentRound
successFullRounds++
time.Sleep(time.Second * 6)
stuck = 0
}
})
}
}

0 comments on commit ea119dd

Please sign in to comment.