From 004e02506cecded0c9d48bfd0e86c01ca9acb5f2 Mon Sep 17 00:00:00 2001 From: Marius Poke Date: Mon, 22 Apr 2024 20:12:21 +0200 Subject: [PATCH] refactor: linting (#1806) make format --- Makefile | 9 +- app/consumer/genesis.go | 5 +- app/consumer/genesis_test.go | 27 +++--- app/sovereign/app.go | 1 - tests/e2e/actions.go | 74 +++++------------ tests/e2e/builder.go | 4 +- tests/e2e/config.go | 4 +- tests/e2e/main.go | 20 ++--- tests/e2e/steps_compatibility.go | 83 +------------------ tests/e2e/test_runner.go | 2 +- tests/e2e/test_target.go | 2 +- tests/integration/soft_opt_out.go | 4 +- tests/mbt/driver/core.go | 6 +- tests/mbt/driver/mbt_test.go | 16 ++-- testutil/integration/validators.go | 2 +- testutil/simibc/relay_util.go | 2 - x/ccv/consumer/keeper/soft_opt_out.go | 4 +- .../consumer/migrations/v2/migration_test.go | 1 + x/ccv/provider/client/cli/query.go | 1 - x/ccv/provider/keeper/grpc_query_test.go | 1 + x/ccv/provider/keeper/key_assignment_test.go | 8 +- x/ccv/provider/keeper/proposal.go | 12 --- x/ccv/provider/keeper/relay_test.go | 7 +- x/ccv/provider/keeper/validator_set_update.go | 14 +++- .../keeper/validator_set_update_test.go | 33 +++++--- .../provider/migrations/v3/migration_test.go | 32 +++---- x/ccv/provider/migrations/v3/migrations.go | 4 +- x/ccv/provider/migrations/v4/migrations.go | 2 +- x/ccv/provider/types/codec.go | 5 +- 29 files changed, 144 insertions(+), 241 deletions(-) diff --git a/Makefile b/Makefile index 1b3fa87e7f..26f2fe7f1d 100644 --- a/Makefile +++ b/Makefile @@ -148,17 +148,20 @@ verify-models: ############################################################################### ### Linting ### ############################################################################### - +golangci_lint_cmd=golangci-lint golangci_version=v1.54.1 lint: @echo "--> Running linter" @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) - golangci-lint run ./... --config .golangci.yml + @$(golangci_lint_cmd) run ./... --config .golangci.yml format: + @go install mvdan.cc/gofumpt@latest + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name "*.pb.go" -not -name "*.pb.gw.go" -not -name "*.pulsar.go" -not -path "./crypto/keys/secp256k1/*" | xargs gofumpt -w -l - golangci-lint run --fix --config .golangci.yml + $(golangci_lint_cmd) run --fix --config .golangci.yml + .PHONY: format mockgen_cmd=go run github.com/golang/mock/mockgen diff --git a/app/consumer/genesis.go b/app/consumer/genesis.go index bf7ba81c95..f6c8e47905 100644 --- a/app/consumer/genesis.go +++ b/app/consumer/genesis.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + consumerTypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types" "github.com/cosmos/interchain-security/v4/x/ccv/types" ) @@ -149,7 +150,6 @@ func transformToV33(jsonRaw []byte, ctx client.Context) ([]byte, error) { // to a format readable by consumer implementation of version v2.x // Use removePreHashKey to remove prehash_key_before_comparison from result. func transformToV2(jsonRaw []byte, ctx client.Context, removePreHashKey bool) (json.RawMessage, error) { - // populate deprecated fields of GenesisState used by version v2.x srcConGen := consumerTypes.GenesisState{} err := ctx.Codec.UnmarshalJSON(jsonRaw, &srcConGen) @@ -252,7 +252,7 @@ func transformToV2(jsonRaw []byte, ctx client.Context, removePreHashKey bool) (j // Returns the transformed data or an error in case the transformation failed or the format is not supported by current implementation func transformGenesis(ctx client.Context, targetVersion IcsVersion, jsonRaw []byte) (json.RawMessage, error) { var newConsumerGenesis json.RawMessage = nil - var err error = nil + var err error switch targetVersion { // v2.x, v3.0-v3.2 share same consumer genesis type @@ -284,7 +284,6 @@ func transformGenesis(ctx client.Context, targetVersion IcsVersion, jsonRaw []by // // Result will be written to defined output. func TransformConsumerGenesis(cmd *cobra.Command, args []string) error { - sourceFile := args[0] jsonRaw, err := os.ReadFile(filepath.Clean(sourceFile)) if err != nil { diff --git a/app/consumer/genesis_test.go b/app/consumer/genesis_test.go index f5aa3208b1..5827651959 100644 --- a/app/consumer/genesis_test.go +++ b/app/consumer/genesis_test.go @@ -21,6 +21,12 @@ import ( ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types" ) +const ( + V4x = "v4.x" + V33x = "v3.3.x" + V2x = "v2.x" +) + // Testdata mapping consumer genesis exports to a provider module version as // used by transformation function for consumer genesis content. var consumerGenesisStates map[string]string = map[string]string{ @@ -393,6 +399,7 @@ var consumerGenesisStates map[string]string = map[string]string{ // creates ccv consumer genesis data content for a given version // as it was exported from a provider func createConsumerDataGenesisFile(t *testing.T, version string) string { + t.Helper() filePath := filepath.Join(t.TempDir(), fmt.Sprintf("ConsumerGenesis_%s.json", version)) err := os.WriteFile( filePath, @@ -454,7 +461,7 @@ func transformConsumerGenesis(filePath string, version *string) ([]byte, error) // Check transformation of a version 2 ConsumerGenesis export to // consumer genesis json format used by current consumer implementation. func TestConsumerGenesisTransformationFromV2ToCurrent(t *testing.T) { - version := "v2.x" + version := V2x ctx := getClientCtx() srcGenesis := consumerTypes.GenesisState{} @@ -502,12 +509,11 @@ func TestConsumerGenesisTransformationFromV2ToCurrent(t *testing.T) { require.Equal(t, "", resultGenesis.ProviderChannelId) require.Equal(t, srcGenesis.InitialValSet, resultGenesis.Provider.InitialValSet) require.Empty(t, resultGenesis.InitialValSet) - } // Check transformation of provider v3.3.x implementation to consumer V2 func TestConsumerGenesisTransformationV330ToV2(t *testing.T) { - version := "v3.3.x" + version := V33x filePath := createConsumerDataGenesisFile(t, version) defer os.Remove(filePath) @@ -516,7 +522,7 @@ func TestConsumerGenesisTransformationV330ToV2(t *testing.T) { err := ctx.Codec.UnmarshalJSON([]byte(consumerGenesisStates[version]), &srcGenesis) require.NoError(t, err) - targetVersion := "v2.x" + targetVersion := V2x result, err := transformConsumerGenesis(filePath, &targetVersion) require.NoError(t, err) @@ -530,12 +536,11 @@ func TestConsumerGenesisTransformationV330ToV2(t *testing.T) { require.Equal(t, srcGenesis.NewChain, resultGenesis.NewChain) require.Equal(t, "", resultGenesis.ProviderClientId) require.Equal(t, "", resultGenesis.ProviderChannelId) - } // Check transformation of provider v3.3.x implementation to current consumer version func TestConsumerGenesisTransformationV330ToCurrent(t *testing.T) { - version := "v3.3.x" + version := V33x filePath := createConsumerDataGenesisFile(t, version) defer os.Remove(filePath) @@ -578,7 +583,7 @@ func TestConsumerGenesisTransformationV330ToCurrent(t *testing.T) { // Check transformation of provider v4.x implementation to consumer V2 func TestConsumerGenesisTransformationV4ToV2(t *testing.T) { - version := "v4.x" + version := V4x filePath := createConsumerDataGenesisFile(t, version) defer os.Remove(filePath) @@ -587,7 +592,7 @@ func TestConsumerGenesisTransformationV4ToV2(t *testing.T) { err := ctx.Codec.UnmarshalJSON([]byte(consumerGenesisStates[version]), &srcGenesis) require.NoError(t, err) - targetVersion := "v2.x" + targetVersion := V2x result, err := transformConsumerGenesis(filePath, &targetVersion) require.NoError(t, err) @@ -626,7 +631,7 @@ func TestConsumerGenesisTransformationV4ToV2(t *testing.T) { // Check transformation of provider v3.3.x implementation to consumer V2 func TestConsumerGenesisTransformationV4ToV33(t *testing.T) { - version := "v4.x" + version := V4x filePath := createConsumerDataGenesisFile(t, version) defer os.Remove(filePath) @@ -635,10 +640,10 @@ func TestConsumerGenesisTransformationV4ToV33(t *testing.T) { err := ctx.Codec.UnmarshalJSON([]byte(consumerGenesisStates[version]), &srcGenesis) require.NoError(t, err) - targetVersion := "v3.3.x" + targetVersion := V33x result, err := transformConsumerGenesis(filePath, &targetVersion) require.NoError(t, err) - resultGenesis := consumerTypes.GenesisState{} //Only difference to v33 is no RetryDelayPeriod + resultGenesis := consumerTypes.GenesisState{} // Only difference to v33 is no RetryDelayPeriod err = ctx.Codec.UnmarshalJSON(result, &resultGenesis) require.NoError(t, err) diff --git a/app/sovereign/app.go b/app/sovereign/app.go index 4017ca9d4f..3d1a981e83 100644 --- a/app/sovereign/app.go +++ b/app/sovereign/app.go @@ -79,7 +79,6 @@ import ( govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - // add mint mint "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" diff --git a/tests/e2e/actions.go b/tests/e2e/actions.go index 5ef7c58c6a..172ac70432 100644 --- a/tests/e2e/actions.go +++ b/tests/e2e/actions.go @@ -24,6 +24,15 @@ import ( ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types" ) +const ( + done = "done!!!!!!!!" + + VLatest = "latest" + V400 = "v4.0.0" + V330 = "v3.3.0" + V300 = "v3.0.0" +) + type SendTokensAction struct { Chain ChainID From ValidatorID @@ -31,8 +40,6 @@ type SendTokensAction struct { Amount uint } -const done = "done!!!!!!!!" - func (tr TestConfig) sendTokens( action SendTokensAction, target ExecutionTarget, @@ -294,7 +301,6 @@ func (tr TestConfig) submitConsumerAdditionProposal( bz, err = target.ExecCommand( "/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json"), ).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -311,7 +317,6 @@ func (tr TestConfig) submitConsumerAdditionProposal( `--keyring-backend`, `test`, `-y`, ).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -354,7 +359,6 @@ func (tr TestConfig) submitConsumerRemovalProposal( bz, err = target.ExecCommand( "/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json")).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -371,7 +375,6 @@ func (tr TestConfig) submitConsumerRemovalProposal( `--keyring-backend`, `test`, `-y`, ).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -430,7 +433,6 @@ func (tr TestConfig) submitParamChangeProposal( bz, err = target.ExecCommand( "/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/params-proposal.json"), ).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -559,7 +561,6 @@ func (tr *TestConfig) getConsumerGenesis(providerChain, consumerChain ChainID, t // needsGenesisTransform tries to identify if a genesis transformation should be performed func needsGenesisTransform(cfg TargetConfig) bool { - // no genesis transformation needed for same versions if cfg.consumerVersion == cfg.providerVersion { return false @@ -567,12 +568,12 @@ func needsGenesisTransform(cfg TargetConfig) bool { // use v4.0.0 (after genesis transform breakages) for the checks if 'latest' is used consumerVersion := cfg.consumerVersion - if cfg.consumerVersion == "latest" { - consumerVersion = "v4.0.0" + if cfg.consumerVersion == VLatest { + consumerVersion = V400 } providerVersion := cfg.providerVersion - if cfg.providerVersion == "latest" { - providerVersion = "v4.0.0" + if cfg.providerVersion == VLatest { + providerVersion = V400 } if !semver.IsValid(consumerVersion) || !semver.IsValid(providerVersion) { @@ -581,7 +582,7 @@ func needsGenesisTransform(cfg TargetConfig) bool { return false } - breakages := []string{"v3.0.0", "v3.3.0", "v4.0.0"} + breakages := []string{V300, V330, V400} for _, breakage := range breakages { if (semver.Compare(consumerVersion, breakage) < 0 && semver.Compare(providerVersion, breakage) >= 0) || (semver.Compare(providerVersion, breakage) < 0 && semver.Compare(consumerVersion, breakage) >= 0) { @@ -600,7 +601,7 @@ func getTransformParameter(consumerVersion string) (string, error) { case "": // For "" (default: local workspace) use HEAD as reference point consumerVersion = "HEAD" - case "latest": + case VLatest: // For 'latest' originated from latest-image use "origin/main" as ref point consumerVersion = "origin/main" } @@ -673,9 +674,9 @@ func (tr *TestConfig) transformConsumerGenesis(consumerChain ChainID, genesis [] panic(fmt.Sprintf("failed writing ccv consumer file : %v", err)) } defer file.Close() - err = os.WriteFile(file.Name(), genesis, 0600) + err = os.WriteFile(file.Name(), genesis, 0o600) if err != nil { - log.Fatalf("Failed writing consumer genesis to file: %v", err) + log.Panicf("Failed writing consumer genesis to file: %v", err) } containerInstance := tr.containerConfig.InstanceName @@ -686,7 +687,7 @@ func (tr *TestConfig) transformConsumerGenesis(consumerChain ChainID, genesis [] fmt.Sprintf("%s:%s", containerInstance, targetFile)) genesis, err = cmd.CombinedOutput() if err != nil { - log.Fatal(err, "\n", string(genesis)) + log.Panic(err, "\n", string(genesis)) } // check if genesis transform supports --to target @@ -697,7 +698,7 @@ func (tr *TestConfig) transformConsumerGenesis(consumerChain ChainID, genesis [] cfg := target.GetTargetConfig() targetVersion, err := getTransformParameter(cfg.consumerVersion) if err != nil { - log.Fatal("Failed getting genesis transformation parameter: ", err) + log.Panic("Failed getting genesis transformation parameter: ", err) } cmd = target.ExecCommand( "interchain-security-transformer", @@ -710,7 +711,7 @@ func (tr *TestConfig) transformConsumerGenesis(consumerChain ChainID, genesis [] result, err := cmd.CombinedOutput() if err != nil { - log.Fatal(err, "CCV consumer genesis transformation failed: %s", string(result)) + log.Panic(err, "CCV consumer genesis transformation failed: %s", string(result)) } return result } @@ -852,32 +853,6 @@ type AddChainToRelayerAction struct { IsConsumer bool } -const hermesChainConfigTemplate = ` - -[[chains]] -account_prefix = "%s" -clock_drift = "5s" -gas_multiplier = 1.1 -grpc_addr = "%s" -id = "%s" -key_name = "%s" -max_gas = 20000000 -rpc_addr = "%s" -rpc_timeout = "10s" -store_prefix = "ibc" -trusting_period = "14days" -event_source = { mode = "push", url = "%s", batch_delay = "50ms" } -ccv_consumer_chain = %v - -[chains.gas_price] - denom = "stake" - price = 0.000 - -[chains.trust_threshold] - denominator = "3" - numerator = "1" -` - // Set up the config for a new chain for gorelayer. // This config is added to the container as a file. // We then add the chain to the relayer, using this config as the chain config with `rly chains add --file` @@ -954,15 +929,11 @@ func (tr TestConfig) addChainToHermes( target ExecutionTarget, verbose bool, ) { - bz, err := target.ExecCommand("bash", "-c", "hermes", "version").CombinedOutput() if err != nil { log.Fatal(err, "\n error getting hermes version", string(bz)) } - re, err := regexp.Compile(`hermes\s+(\d+.\d+.\d+)`) - if err != nil { - log.Fatal(err, "error identifying hermes version") - } + re := regexp.MustCompile(`hermes\s+(\d+.\d+.\d+)`) match := re.FindStringSubmatch(string(bz)) if match == nil { log.Fatalln("error identifying hermes version from", string(bz)) @@ -999,7 +970,6 @@ func (tr TestConfig) addChainToHermes( "--chain", string(tr.chainConfigs[action.Chain].ChainId), "--mnemonic-file", "/root/.hermes/mnemonic.txt", ).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -1956,7 +1926,6 @@ func (tr TestConfig) submitChangeRewardDenomsProposal(action SubmitChangeRewardD bz, err = target.ExecCommand( "/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/change-reward-denoms-proposal.json")).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } @@ -1972,7 +1941,6 @@ func (tr TestConfig) submitChangeRewardDenomsProposal(action SubmitChangeRewardD `--keyring-backend`, `test`, `-y`, ).CombinedOutput() - if err != nil { log.Fatal(err, "\n", string(bz)) } diff --git a/tests/e2e/builder.go b/tests/e2e/builder.go index 79800d0c23..26eb5c34f6 100644 --- a/tests/e2e/builder.go +++ b/tests/e2e/builder.go @@ -82,7 +82,7 @@ func generateImageName(version string, cfg TargetConfig) (string, error) { tagName = "local" // this refers to build from local workspace } else { // use git hash of rev as docker image tag - //cmd := exec.Command("git", "rev-parse", "--verify", "--short", version) + // cmd := exec.Command("git", "rev-parse", "--verify", "--short", version) cmd := exec.Command("git", "log", "--pretty=format:%h", "-n", "1", version) out, err := cmd.CombinedOutput() if err != nil { @@ -179,7 +179,7 @@ func pullDockerImage(tag string, targetConfig TargetConfig) (string, error) { // bootstrapSDK in workspace to use custom SDK setup if required func bootstrapSDK(workSpace string, targetCfg TargetConfig) error { sdkPath := strings.Join([]string{workSpace, "cosmos-sdk"}, string(os.PathSeparator)) - err := os.RemoveAll(sdkPath) //delete old SDK directory + err := os.RemoveAll(sdkPath) // delete old SDK directory if err != nil { return fmt.Errorf("error deleting SDK directory from workspace: %v", err) } diff --git a/tests/e2e/config.go b/tests/e2e/config.go index 4ae8133568..a5b86e85f9 100644 --- a/tests/e2e/config.go +++ b/tests/e2e/config.go @@ -179,8 +179,6 @@ type TargetConfig struct { useGaia bool providerVersion string consumerVersion string - providerImage string - consumerImage string } type TestConfig struct { @@ -236,7 +234,7 @@ func getIcsVersion(reference string) string { log.Printf("error identifying config version to use '%v': %s", err, string(out)) return "" } - //reference is not part of this tag, try next one + // reference is not part of this tag, try next one } } return semver.Canonical(icsVersion) diff --git a/tests/e2e/main.go b/tests/e2e/main.go index 4a8e17be8b..83a41a0342 100644 --- a/tests/e2e/main.go +++ b/tests/e2e/main.go @@ -36,7 +36,7 @@ func (vs *VersionSet) Set(value string) error { func (vs *VersionSet) String() string { keys := []string{} - for k, _ := range *vs { + for k := range *vs { keys = append(keys, k) } return fmt.Sprint(keys) @@ -233,7 +233,8 @@ type testStepsWithConfig struct { } func getTestCases(selectedPredefinedTests, selectedTestFiles TestSet, providerVersions, - consumerVersions VersionSet) (tests []testStepsWithConfig) { + consumerVersions VersionSet, +) (tests []testStepsWithConfig) { // Run default tests if no test cases were selected if len(selectedPredefinedTests) == 0 && len(selectedTestFiles) == 0 { selectedPredefinedTests = TestSet{ @@ -251,7 +252,6 @@ func getTestCases(selectedPredefinedTests, selectedTestFiles TestSet, providerVe // Get predefined from selection for _, tc := range selectedPredefinedTests { testConfig := TestConfigType("") - testSteps := []Step{} // first part of tc is the steps, second part is the test config splitTcString := strings.Split(tc, "::") @@ -264,7 +264,7 @@ func getTestCases(selectedPredefinedTests, selectedTestFiles TestSet, providerVe log.Fatalf("Step choice '%s' not found.\nsee usage info:\n%s", tc, getTestCaseUsageString()) } - testSteps = stepChoices[tc].steps + testSteps := stepChoices[tc].steps if testConfig == "" { testConfig = stepChoices[tc].testConfig } @@ -326,8 +326,8 @@ func createTestConfigs(cfgType TestConfigType, providerVersions, consumerVersion } // Create test configs as a combination of "provider versions" with "consumer version" and "test case" - for provider, _ := range providerVersions { - for consumer, _ := range consumerVersions { + for provider := range providerVersions { + for consumer := range consumerVersions { // Skip target creation for same version of provider and consumer // if multiple versions need to be tested. // This is to reduce the tests to be run for compatibility testing. @@ -375,7 +375,7 @@ func executeTests(runners []TestRunner) error { var wg sync.WaitGroup var err error = nil - for idx, _ := range runners { + for idx := range runners { if parallel != nil && *parallel { wg.Add(1) go func(runner *TestRunner) { @@ -429,13 +429,13 @@ TEST RESULTS } } if len(passedTests) > 0 { - report += fmt.Sprintln("\n\nPASSED TESTS:\n") + report += fmt.Sprintln("\n\nPASSED TESTS:") for _, t := range passedTests { report += t.Report() } } if len(remainingTests) > 0 { - report += fmt.Sprintln("\n\nREMAINING TESTS:\n") + report += fmt.Sprintln("\n\nREMAINING TESTS:") for _, t := range remainingTests { report += t.Report() } @@ -474,7 +474,7 @@ func main() { start := time.Now() err := executeTests(testRunners) if err != nil { - log.Fatalf("Test execution failed '%s'", err) + log.Panicf("Test execution failed '%s'", err) } printReport(testRunners, time.Since(start)) diff --git a/tests/e2e/steps_compatibility.go b/tests/e2e/steps_compatibility.go index 1fc6ced315..89e80f3600 100644 --- a/tests/e2e/steps_compatibility.go +++ b/tests/e2e/steps_compatibility.go @@ -58,7 +58,7 @@ func compstepsStartConsumerChain(consumerName string, proposalIndex, chainIndex }, }, // not supported across major versions - //ProposedConsumerChains: &[]string{consumerName}, + // ProposedConsumerChains: &[]string{consumerName}, }, }, }, @@ -169,7 +169,7 @@ func compstepsStartConsumerChain(consumerName string, proposalIndex, chainIndex ValidatorID("carol"): 9500000000, }, // not supported - //ProposedConsumerChains: &[]string{}, + // ProposedConsumerChains: &[]string{}, }, ChainID(consumerName): ChainState{ ValBalances: &map[ValidatorID]uint{ @@ -231,82 +231,3 @@ func compstepsStartChains(consumerNames []string, setupTransferChans bool) []Ste return s } - -func compstepsAssignConsumerKeyOnStartedChain(consumerName, validator string) []Step { - return []Step{ - { - Action: AssignConsumerPubKeyAction{ - Chain: ChainID(consumerName), - Validator: ValidatorID("bob"), - // reconfigure the node -> validator was using provider key - // until this point -> key matches config.consumerValPubKey for "bob" - ConsumerPubkey: getDefaultValidators()[ValidatorID("bob")].ConsumerValPubKey, - ReconfigureNode: true, - }, - State: State{ - ChainID("provi"): ChainState{ - ValPowers: &map[ValidatorID]uint{ - // this happens after some delegations - // so that the chain does not halt if 1/3 of power is offline - ValidatorID("alice"): 511, - ValidatorID("bob"): 500, - ValidatorID("carol"): 500, - }, - }, - ChainID(consumerName): ChainState{ - ValPowers: &map[ValidatorID]uint{ - // this happens after some delegations - // so that the chain does not halt if 1/3 of power is offline - ValidatorID("alice"): 511, - ValidatorID("bob"): 500, - ValidatorID("carol"): 500, - }, - AssignedKeys: &map[ValidatorID]string{ - ValidatorID("bob"): getDefaultValidators()[ValidatorID("bob")].ConsumerValconsAddressOnProvider, - ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ConsumerValconsAddressOnProvider, - }, - ProviderKeys: &map[ValidatorID]string{ - ValidatorID("bob"): getDefaultValidators()[ValidatorID("bob")].ValconsAddress, - ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ValconsAddress, - }, - }, - }, - }, - { - Action: RelayPacketsAction{ - ChainA: ChainID("provi"), - ChainB: ChainID(consumerName), - Port: "provider", - Channel: 0, - }, - State: State{ - ChainID("provi"): ChainState{ - ValPowers: &map[ValidatorID]uint{ - // this happens after some delegations - // so that the chain does not halt if 1/3 of power is offline - ValidatorID("alice"): 511, - ValidatorID("bob"): 500, - ValidatorID("carol"): 500, - }, - }, - ChainID(consumerName): ChainState{ - ValPowers: &map[ValidatorID]uint{ - // this happens after some delegations - // so that the chain does not halt if 1/3 of power is offline - ValidatorID("alice"): 511, - ValidatorID("bob"): 500, - ValidatorID("carol"): 500, - }, - AssignedKeys: &map[ValidatorID]string{ - ValidatorID("bob"): getDefaultValidators()[ValidatorID("bob")].ConsumerValconsAddressOnProvider, - ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ConsumerValconsAddressOnProvider, - }, - ProviderKeys: &map[ValidatorID]string{ - ValidatorID("bob"): getDefaultValidators()[ValidatorID("bob")].ValconsAddress, - ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ValconsAddress, - }, - }, - }, - }, - } -} diff --git a/tests/e2e/test_runner.go b/tests/e2e/test_runner.go index 4fac32df11..7c02dd6d2d 100644 --- a/tests/e2e/test_runner.go +++ b/tests/e2e/test_runner.go @@ -103,6 +103,7 @@ func (tr *TestRunner) checkConfig() error { tr.config.validateStringLiterals() return nil } + func (tr *TestRunner) setupEnvironment(target ExecutionTarget) error { tr.target = target return target.Start() @@ -137,7 +138,6 @@ Target: %s tr.config.name, tr.target.Info(), ) - } func (tr *TestRunner) Report() string { diff --git a/tests/e2e/test_target.go b/tests/e2e/test_target.go index 6fcec7de1b..421be1d1fa 100644 --- a/tests/e2e/test_target.go +++ b/tests/e2e/test_target.go @@ -28,7 +28,7 @@ type ExecutionTarget interface { type DockerContainer struct { targetConfig TargetConfig containerCfg ContainerConfig - images []string //images needed to build the target container + images []string // images needed to build the target container ImageName string } diff --git a/tests/integration/soft_opt_out.go b/tests/integration/soft_opt_out.go index a9508118bd..bce2e1d77c 100644 --- a/tests/integration/soft_opt_out.go +++ b/tests/integration/soft_opt_out.go @@ -4,10 +4,12 @@ import ( "bytes" "sort" - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + abci "github.com/cometbft/cometbft/abci/types" + consumerKeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper" ccv "github.com/cosmos/interchain-security/v4/x/ccv/types" ) diff --git a/tests/mbt/driver/core.go b/tests/mbt/driver/core.go index 13716ad29c..3c985cb6fa 100644 --- a/tests/mbt/driver/core.go +++ b/tests/mbt/driver/core.go @@ -14,16 +14,16 @@ import ( "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - abcitypes "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/proto/tendermint/crypto" cmttypes "github.com/cometbft/cometbft/types" - "github.com/cometbft/cometbft/proto/tendermint/crypto" appConsumer "github.com/cosmos/interchain-security/v4/app/consumer" appProvider "github.com/cosmos/interchain-security/v4/app/provider" simibc "github.com/cosmos/interchain-security/v4/testutil/simibc" diff --git a/tests/mbt/driver/mbt_test.go b/tests/mbt/driver/mbt_test.go index 5dc26635bf..9a82bd7b9b 100644 --- a/tests/mbt/driver/mbt_test.go +++ b/tests/mbt/driver/mbt_test.go @@ -15,15 +15,13 @@ import ( "github.com/kylelemons/godebug/pretty" "github.com/stretchr/testify/require" - cmttypes "github.com/cometbft/cometbft/types" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" tmencoding "github.com/cometbft/cometbft/crypto/encoding" - "github.com/cosmos/interchain-security/v4/testutil/integration" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdktypes "github.com/cosmos/cosmos-sdk/types" + cmttypes "github.com/cometbft/cometbft/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/interchain-security/v4/testutil/integration" providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" "github.com/cosmos/interchain-security/v4/x/ccv/types" ) @@ -460,7 +458,7 @@ func RunItfTrace(t *testing.T, path string) { } val := addressMap[validatorName] - valConsAddr := sdktypes.ConsAddress(val.Address) + valConsAddr := sdk.ConsAddress(val.Address) slashFraction := doubleSignSlashPercentage if isDowntime { @@ -587,12 +585,14 @@ func RunItfTrace(t *testing.T, path string) { } func UpdateProviderClientOnConsumer(t *testing.T, driver *Driver, consumerChainId string) { + t.Helper() driver.path(ChainId(consumerChainId)).AddClientHeader(PROVIDER, driver.providerHeader()) err := driver.path(ChainId(consumerChainId)).UpdateClient(consumerChainId, false) require.True(t, err == nil, "Error updating client from %v on provider: %v", consumerChainId, err) } func UpdateConsumerClientOnProvider(t *testing.T, driver *Driver, consumerChain string) { + t.Helper() consumerHeader := driver.chain(ChainId(consumerChain)).LastHeader driver.path(ChainId(consumerChain)).AddClientHeader(consumerChain, consumerHeader) err := driver.path(ChainId(consumerChain)).UpdateClient(PROVIDER, false) @@ -634,7 +634,7 @@ func CompareValidatorSets( if ok { // the node has a key assigned, use the name of the consumer address in the model consumerCurValSet[consAddrModelName] = val.Power } else { // the node doesn't have a key assigned yet, get the validator moniker - consAddr := providertypes.NewConsumerConsAddress(sdktypes.ConsAddress(pubkey.Address().Bytes())) + consAddr := providertypes.NewConsumerConsAddress(sdk.ConsAddress(pubkey.Address().Bytes())) // the consumer vals right now are CrossChainValidators, for which we don't know their mnemonic // so we need to find the mnemonic of the consumer val now to enter it by name in the map diff --git a/testutil/integration/validators.go b/testutil/integration/validators.go index c6515b27e3..513c40021a 100644 --- a/testutil/integration/validators.go +++ b/testutil/integration/validators.go @@ -3,12 +3,12 @@ package integration import ( "fmt" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/testutil/mock" "github.com/cometbft/cometbft/abci/types" tmencoding "github.com/cometbft/cometbft/crypto/encoding" tmtypes "github.com/cometbft/cometbft/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" ) // CreateValidators creates a set of validators for testing purposes diff --git a/testutil/simibc/relay_util.go b/testutil/simibc/relay_util.go index e113c02fef..1082b2d864 100644 --- a/testutil/simibc/relay_util.go +++ b/testutil/simibc/relay_util.go @@ -24,7 +24,6 @@ import ( // NOTE: this function MAY be used independently of the rest of simibc. func UpdateReceiverClient(sender, receiver *ibctesting.Endpoint, header *ibctmtypes.Header, expectExpiration bool) (err error) { err = augmentHeader(sender.Chain, receiver.Chain, receiver.ClientID, header) - if err != nil { return err } @@ -95,7 +94,6 @@ func TryRecvPacket(sender, receiver *ibctesting.Endpoint, packet channeltypes.Pa } ack, err = ibctesting.ParseAckFromEvents(resWithAck.GetEvents()) - if err != nil { return nil, err } diff --git a/x/ccv/consumer/keeper/soft_opt_out.go b/x/ccv/consumer/keeper/soft_opt_out.go index 25747feb51..e5990ff65d 100644 --- a/x/ccv/consumer/keeper/soft_opt_out.go +++ b/x/ccv/consumer/keeper/soft_opt_out.go @@ -99,13 +99,13 @@ func (k Keeper) UpdateSlashingSigningInfo(ctx sdk.Context) { } if val.Power < smallestNonOptOutPower { // validator CAN opt-out from validating on consumer chains - if val.OptedOut == false { + if !val.OptedOut { // previously the validator couldn't opt-out val.OptedOut = true } } else { // validator CANNOT opt-out from validating on consumer chains - if val.OptedOut == true { + if val.OptedOut { // previously the validator could opt-out signingInfo.StartHeight = ctx.BlockHeight() val.OptedOut = false diff --git a/x/ccv/consumer/migrations/v2/migration_test.go b/x/ccv/consumer/migrations/v2/migration_test.go index 5df453d7cf..a99a2be0fb 100644 --- a/x/ccv/consumer/migrations/v2/migration_test.go +++ b/x/ccv/consumer/migrations/v2/migration_test.go @@ -8,6 +8,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + testutil "github.com/cosmos/interchain-security/v4/testutil/keeper" v2 "github.com/cosmos/interchain-security/v4/x/ccv/consumer/migrations/v2" consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types" diff --git a/x/ccv/provider/client/cli/query.go b/x/ccv/provider/client/cli/query.go index 7a75762546..90f7450355 100644 --- a/x/ccv/provider/client/cli/query.go +++ b/x/ccv/provider/client/cli/query.go @@ -409,7 +409,6 @@ $ %s query provider params flags.AddQueryFlagsToCmd(cmd) return cmd - } func CmdOldestUnconfirmedVsc() *cobra.Command { diff --git a/x/ccv/provider/keeper/grpc_query_test.go b/x/ccv/provider/keeper/grpc_query_test.go index 3d15eb997c..14e6e675e1 100644 --- a/x/ccv/provider/keeper/grpc_query_test.go +++ b/x/ccv/provider/keeper/grpc_query_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" sdktypes "github.com/cosmos/cosmos-sdk/types" + cryptotestutil "github.com/cosmos/interchain-security/v4/testutil/crypto" testkeeper "github.com/cosmos/interchain-security/v4/testutil/keeper" "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" diff --git a/x/ccv/provider/keeper/key_assignment_test.go b/x/ccv/provider/keeper/key_assignment_test.go index 7cb222a3be..46aefb1bbf 100644 --- a/x/ccv/provider/keeper/key_assignment_test.go +++ b/x/ccv/provider/keeper/key_assignment_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "bytes" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "math/rand" "sort" "testing" @@ -11,6 +10,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -24,6 +24,8 @@ import ( ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types" ) +const ChainID = "chainID" + func TestValidatorConsumerPubKeyCRUD(t *testing.T) { chainID := consumer providerAddr := types.NewProviderConsAddress([]byte("providerAddr")) @@ -312,7 +314,7 @@ func checkCorrectPruningProperty(ctx sdk.Context, k providerkeeper.Keeper, chain } func TestAssignConsensusKeyForConsumerChain(t *testing.T) { - chainID := "chainID" + chainID := ChainID providerIdentities := []*cryptotestutil.CryptoIdentity{ cryptotestutil.NewCryptoIdentityFromIntSeed(0), cryptotestutil.NewCryptoIdentityFromIntSeed(1), @@ -638,7 +640,7 @@ type Assignment struct { // of simulated scenarios where random key assignments and validator // set updates are generated. func TestSimulatedAssignmentsAndUpdateApplication(t *testing.T) { - CHAINID := "chainID" + CHAINID := ChainID // The number of full test executions to run NUM_EXECUTIONS := 100 // Each test execution mimics the adding of a consumer chain and the diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index b0e2845502..c7a122b497 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -16,7 +16,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - abci "github.com/cometbft/cometbft/abci/types" tmtypes "github.com/cometbft/cometbft/types" "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" @@ -255,7 +254,6 @@ func (k Keeper) MakeConsumerGenesis( var bondedValidators []stakingtypes.Validator - initialUpdates := []abci.ValidatorUpdate{} for _, p := range lastPowers { addr, err := sdk.ValAddressFromBech32(p.Address) if err != nil { @@ -267,16 +265,6 @@ func (k Keeper) MakeConsumerGenesis( return gen, nil, errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "error getting validator from LastValidatorPowers: %s", err) } - tmProtoPk, err := val.TmConsPublicKey() - if err != nil { - return gen, nil, err - } - - initialUpdates = append(initialUpdates, abci.ValidatorUpdate{ - PubKey: tmProtoPk, - Power: p.Power, - }) - // gather all the bonded validators in order to construct the consumer validator set for consumer chain `chainID` bondedValidators = append(bondedValidators, val) } diff --git a/x/ccv/provider/keeper/relay_test.go b/x/ccv/provider/keeper/relay_test.go index b7e89b3dc2..1e7347d3ce 100644 --- a/x/ccv/provider/keeper/relay_test.go +++ b/x/ccv/provider/keeper/relay_test.go @@ -1,24 +1,23 @@ package keeper_test import ( - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - ibctesting "github.com/cosmos/ibc-go/v7/testing" "strings" "testing" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "cosmossdk.io/math" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/cometbft/cometbft/abci/types" - "github.com/cosmos/interchain-security/v4/testutil/crypto" cryptotestutil "github.com/cosmos/interchain-security/v4/testutil/crypto" testkeeper "github.com/cosmos/interchain-security/v4/testutil/keeper" "github.com/cosmos/interchain-security/v4/x/ccv/provider/keeper" @@ -667,7 +666,7 @@ func TestEndBlockVSU(t *testing.T) { // create 4 sample lastValidators var lastValidators []stakingtypes.Validator for i := 0; i < 4; i++ { - lastValidators = append(lastValidators, crypto.NewCryptoIdentityFromIntSeed(i).SDKStakingValidator()) + lastValidators = append(lastValidators, cryptotestutil.NewCryptoIdentityFromIntSeed(i).SDKStakingValidator()) } mocks.MockStakingKeeper.EXPECT().GetLastValidators(gomock.Any()).Return(lastValidators).AnyTimes() mocks.MockStakingKeeper.EXPECT().GetLastValidatorPower(gomock.Any(), gomock.Any()).Return(int64(2)).AnyTimes() diff --git a/x/ccv/provider/keeper/validator_set_update.go b/x/ccv/provider/keeper/validator_set_update.go index 71238d210d..adaee853e8 100644 --- a/x/ccv/provider/keeper/validator_set_update.go +++ b/x/ccv/provider/keeper/validator_set_update.go @@ -2,9 +2,12 @@ package keeper import ( "fmt" - abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" ) @@ -36,7 +39,8 @@ func (k Keeper) DeleteConsumerValidator( // DeleteConsumerValSet deletes all the stored consumer validators for chain `chainID` func (k Keeper) DeleteConsumerValSet( ctx sdk.Context, - chainID string) { + chainID string, +) { store := ctx.KVStore(k.storeKey) key := types.ChainIdWithLenKey(types.ConsumerValidatorBytePrefix, chainID) iterator := sdk.KVStorePrefixIterator(store, key) @@ -65,7 +69,8 @@ func (k Keeper) IsConsumerValidator( // GetConsumerValSet returns all the consumer validators for chain `chainID` func (k Keeper) GetConsumerValSet( ctx sdk.Context, - chainID string) (validators []types.ConsumerValidator) { + chainID string, +) (validators []types.ConsumerValidator) { store := ctx.KVStore(k.storeKey) key := types.ChainIdWithLenKey(types.ConsumerValidatorBytePrefix, chainID) iterator := sdk.KVStorePrefixIterator(store, key) @@ -132,7 +137,8 @@ func (k Keeper) ComputeNextEpochConsumerValSet( // needed by CometBFT to update the validator set on a chain. func DiffValidators( currentValidators []types.ConsumerValidator, - nextValidators []types.ConsumerValidator) []abci.ValidatorUpdate { + nextValidators []types.ConsumerValidator, +) []abci.ValidatorUpdate { var updates []abci.ValidatorUpdate isCurrentValidator := make(map[string]types.ConsumerValidator) diff --git a/x/ccv/provider/keeper/validator_set_update_test.go b/x/ccv/provider/keeper/validator_set_update_test.go index 8505158816..3c6441bbc5 100644 --- a/x/ccv/provider/keeper/validator_set_update_test.go +++ b/x/ccv/provider/keeper/validator_set_update_test.go @@ -5,18 +5,21 @@ import ( "sort" "testing" - abci "github.com/cometbft/cometbft/abci/types" - "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cometbft/cometbft/proto/tendermint/crypto" + "github.com/stretchr/testify/require" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/cometbft/cometbft/proto/tendermint/crypto" + cryptotestutil "github.com/cosmos/interchain-security/v4/testutil/crypto" testkeeper "github.com/cosmos/interchain-security/v4/testutil/keeper" "github.com/cosmos/interchain-security/v4/x/ccv/provider/keeper" "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" - "github.com/stretchr/testify/require" ) // TestConsumerValidator tests the `SetConsumerValidator`, `IsConsumerValidator`, and `DeleteConsumerValidator` methods @@ -85,7 +88,7 @@ func TestGetConsumerValSet(t *testing.T) { // sort validators first to be able to compare sortValidators := func(validators []types.ConsumerValidator) { - sort.Slice(validators, func(i int, j int) bool { + sort.Slice(validators, func(i, j int) bool { return bytes.Compare(validators[i].ProviderConsAddr, validators[j].ProviderConsAddr) < 0 }) } @@ -121,8 +124,7 @@ func TestComputeNextEpochConsumerValSet(t *testing.T) { pk, _ := cryptocodec.FromTmPubKeyInterface(providerConsPubKey) pkAny, _ := codectypes.NewAnyWithValue(pk) - var providerValidatorAddr sdk.ValAddress - providerValidatorAddr = providerAddr.Address.Bytes() + var providerValidatorAddr sdk.ValAddress = providerAddr.Address.Bytes() mocks.MockStakingKeeper.EXPECT(). GetLastValidatorPower(ctx, providerValidatorAddr).Return(power).AnyTimes() @@ -243,7 +245,11 @@ func TestDiffEdgeCases(t *testing.T) { require.Empty(t, len(keeper.DiffValidators(validators, validators))) // only have `nextValidators` that would generate validator updates for the validators to be added - expectedUpdates := []abci.ValidatorUpdate{{publicKeyA, 1}, {publicKeyB, 2}, {publicKeyC, 3}} + expectedUpdates := []abci.ValidatorUpdate{ + {PubKey: publicKeyA, Power: 1}, + {PubKey: publicKeyB, Power: 2}, + {PubKey: publicKeyC, Power: 3}, + } actualUpdates := keeper.DiffValidators([]types.ConsumerValidator{}, validators) // sort validators first to be able to compare sortUpdates := func(updates []abci.ValidatorUpdate) { @@ -260,7 +266,11 @@ func TestDiffEdgeCases(t *testing.T) { require.Equal(t, expectedUpdates, actualUpdates) // only have `currentValidators` that would generate validator updates for the validators to be removed - expectedUpdates = []abci.ValidatorUpdate{{publicKeyA, 0}, {publicKeyB, 0}, {publicKeyC, 0}} + expectedUpdates = []abci.ValidatorUpdate{ + {PubKey: publicKeyA, Power: 0}, + {PubKey: publicKeyB, Power: 0}, + {PubKey: publicKeyC, Power: 0}, + } actualUpdates = keeper.DiffValidators(validators, []types.ConsumerValidator{}) sortUpdates(expectedUpdates) sortUpdates(actualUpdates) @@ -268,7 +278,10 @@ func TestDiffEdgeCases(t *testing.T) { // have nonempty `currentValidators` and `nextValidators`, but with empty intersection // all old validators should be removed, all new validators should be added - expectedUpdates = []abci.ValidatorUpdate{{publicKeyA, 0}, {publicKeyB, 2}} + expectedUpdates = []abci.ValidatorUpdate{ + {PubKey: publicKeyA, Power: 0}, + {PubKey: publicKeyB, Power: 2}, + } actualUpdates = keeper.DiffValidators(validators[0:1], validators[1:2]) sortUpdates(expectedUpdates) sortUpdates(actualUpdates) diff --git a/x/ccv/provider/migrations/v3/migration_test.go b/x/ccv/provider/migrations/v3/migration_test.go index 189c75e271..630b8fd7dd 100644 --- a/x/ccv/provider/migrations/v3/migration_test.go +++ b/x/ccv/provider/migrations/v3/migration_test.go @@ -19,41 +19,41 @@ func TestMigrate2To3(t *testing.T) { providerKeeper.SetConsumerClientId(ctx, "chain-3", "client-3") // Queue some data for chain-1 - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-1", 66, testutil.GetNewSlashPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-1", 67, testutil.GetNewVSCMaturedPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-1", 68, testutil.GetNewSlashPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-1", 69, testutil.GetNewVSCMaturedPacketData()) // Queue some data for chain-2 - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-2", 789, testutil.GetNewVSCMaturedPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-2", 790, testutil.GetNewSlashPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-2", 791, testutil.GetNewVSCMaturedPacketData()) // Queue some data for chain-3 - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-3", 123, testutil.GetNewSlashPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-3", 124, testutil.GetNewVSCMaturedPacketData()) - providerKeeper.LegacyQueueThrottledPacketData( //nolint:staticcheck // SA1019: used in migration tests + providerKeeper.LegacyQueueThrottledPacketData( ctx, "chain-3", 125, testutil.GetNewVSCMaturedPacketData()) // Confirm getter methods return expected values - slash1, vscm1 := providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-1") //nolint:staticcheck // SA1019: used in migration tests + slash1, vscm1 := providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-1") require.Len(t, slash1, 2) require.Len(t, vscm1, 2) - slash2, vscm2 := providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-2") //nolint:staticcheck // SA1019: used in migration tests + slash2, vscm2 := providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-2") require.Len(t, slash2, 1) require.Len(t, vscm2, 2) - slash3, vscm3 := providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-3") //nolint:staticcheck // SA1019: used in migration tests + slash3, vscm3 := providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-3") require.Len(t, slash3, 1) require.Len(t, vscm3, 2) @@ -91,13 +91,13 @@ func TestMigrate2To3(t *testing.T) { require.NoError(t, err) // Confirm throttled data is now deleted - slash1, vscm1 = providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-1") //nolint:staticcheck // SA1019: used in migration tests + slash1, vscm1 = providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-1") require.Empty(t, slash1) require.Empty(t, vscm1) - slash2, vscm2 = providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-2") //nolint:staticcheck // SA1019: used in migration tests + slash2, vscm2 = providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-2") require.Empty(t, slash2) require.Empty(t, vscm2) - slash3, vscm3 = providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-3") //nolint:staticcheck // SA1019: used in migration tests + slash3, vscm3 = providerKeeper.LegacyGetAllThrottledPacketData(ctx, "chain-3") require.Empty(t, slash3) require.Empty(t, vscm3) diff --git a/x/ccv/provider/migrations/v3/migrations.go b/x/ccv/provider/migrations/v3/migrations.go index c2cd9054ba..d308316761 100644 --- a/x/ccv/provider/migrations/v3/migrations.go +++ b/x/ccv/provider/migrations/v3/migrations.go @@ -12,14 +12,14 @@ import ( // on the provider in the v2 consensus version (jail throttling v1). func MigrateQueuedPackets(ctx sdk.Context, k providerkeeper.Keeper) error { for _, consumer := range k.GetAllConsumerChains(ctx) { - slashData, vscmData := k.LegacyGetAllThrottledPacketData(ctx, consumer.ChainId) //nolint:staticcheck // SA1019: function used for migration + slashData, vscmData := k.LegacyGetAllThrottledPacketData(ctx, consumer.ChainId) if len(slashData) > 0 { k.Logger(ctx).Error(fmt.Sprintf("slash data being dropped: %v", slashData)) } for _, data := range vscmData { k.HandleVSCMaturedPacket(ctx, consumer.ChainId, data) } - k.LegacyDeleteThrottledPacketDataForConsumer(ctx, consumer.ChainId) //nolint:staticcheck // SA1019: function used for migration + k.LegacyDeleteThrottledPacketDataForConsumer(ctx, consumer.ChainId) } return nil } diff --git a/x/ccv/provider/migrations/v4/migrations.go b/x/ccv/provider/migrations/v4/migrations.go index 06b89d7efb..825d01e25d 100644 --- a/x/ccv/provider/migrations/v4/migrations.go +++ b/x/ccv/provider/migrations/v4/migrations.go @@ -2,8 +2,8 @@ package v4 import ( sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types" ) diff --git a/x/ccv/provider/types/codec.go b/x/ccv/provider/types/codec.go index 6ab621f0e1..e5900bcf04 100644 --- a/x/ccv/provider/types/codec.go +++ b/x/ccv/provider/types/codec.go @@ -1,13 +1,14 @@ package types import ( + "github.com/cosmos/ibc-go/v7/modules/core/exported" + tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/cosmos/ibc-go/v7/modules/core/exported" - tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ) // RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types