-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7705e07
commit ea119dd
Showing
4 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ eslint-report.json | |
override*.toml | ||
# go work files | ||
go.work* | ||
gauntlet-*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) | ||
} | ||
} |