From fc4adde65257a6feecf183ef3df1f752e13b7b96 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 18 Sep 2023 11:00:20 +0200 Subject: [PATCH] chore: fix slices.Contains api usage, and remove unused imports --- .../apps/27-interchain-accounts/host/client/cli/tx.go | 4 ++-- modules/apps/27-interchain-accounts/types/metadata.go | 7 ++++--- modules/core/02-client/types/params.go | 4 ++-- modules/core/03-connection/types/version.go | 9 ++++----- testing/events.go | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/client/cli/tx.go b/modules/apps/27-interchain-accounts/host/client/cli/tx.go index b846d01d612..78f204eb63b 100644 --- a/modules/apps/27-interchain-accounts/host/client/cli/tx.go +++ b/modules/apps/27-interchain-accounts/host/client/cli/tx.go @@ -3,6 +3,7 @@ package cli import ( "encoding/json" "fmt" + "slices" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" @@ -12,7 +13,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/ibc-go/v8/internal/collections" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" ) @@ -82,7 +82,7 @@ otherwise the encoding flag can be used in combination with either "proto3" or " return err } - if !slices.Contains(encoding, []string{icatypes.EncodingProtobuf, icatypes.EncodingProto3JSON}) { + if !slices.Contains([]string{icatypes.EncodingProtobuf, icatypes.EncodingProto3JSON}, encoding) { return fmt.Errorf("unsupported encoding type: %s", encoding) } diff --git a/modules/apps/27-interchain-accounts/types/metadata.go b/modules/apps/27-interchain-accounts/types/metadata.go index 2f72d22c99e..29d1da45d42 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.go +++ b/modules/apps/27-interchain-accounts/types/metadata.go @@ -1,11 +1,12 @@ package types import ( + "slices" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v8/internal/collections" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" ) @@ -134,7 +135,7 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti // isSupportedEncoding returns true if the provided encoding is supported, otherwise false func isSupportedEncoding(encoding string) bool { - return slices.Contains(encoding, getSupportedEncoding()) + return slices.Contains(getSupportedEncoding(), encoding) } // getSupportedEncoding returns a string slice of supported encoding formats @@ -144,7 +145,7 @@ func getSupportedEncoding() []string { // isSupportedTxType returns true if the provided transaction type is supported, otherwise false func isSupportedTxType(txType string) bool { - return slices.Contains(txType, getSupportedTxTypes()) + return slices.Contains(getSupportedTxTypes(), txType) } // getSupportedTxTypes returns a string slice of supported transaction types diff --git a/modules/core/02-client/types/params.go b/modules/core/02-client/types/params.go index 54c923ee5f1..2234f049e66 100644 --- a/modules/core/02-client/types/params.go +++ b/modules/core/02-client/types/params.go @@ -2,9 +2,9 @@ package types import ( "fmt" + "slices" "strings" - "github.com/cosmos/ibc-go/v8/internal/collections" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -30,7 +30,7 @@ func (p Params) Validate() error { // IsAllowedClient checks if the given client type is registered on the allowlist. func (p Params) IsAllowedClient(clientType string) bool { - return slices.Contains(clientType, p.AllowedClients) + return slices.Contains(p.AllowedClients, clientType) } // validateClients checks that the given clients are not blank. diff --git a/modules/core/03-connection/types/version.go b/modules/core/03-connection/types/version.go index 8dab5d9a154..00aadcb8682 100644 --- a/modules/core/03-connection/types/version.go +++ b/modules/core/03-connection/types/version.go @@ -1,11 +1,10 @@ package types import ( + "slices" "strings" errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/ibc-go/v8/internal/collections" ) var ( @@ -86,7 +85,7 @@ func (version Version) VerifyProposedVersion(proposedVersion *Version) error { } for _, proposedFeature := range proposedVersion.GetFeatures() { - if !slices.Contains(proposedFeature, version.GetFeatures()) { + if !slices.Contains(version.GetFeatures(), proposedFeature) { return errorsmod.Wrapf( ErrVersionNegotiationFailed, "proposed feature (%s) is not a supported feature set (%s)", proposedFeature, version.GetFeatures(), @@ -100,7 +99,7 @@ func (version Version) VerifyProposedVersion(proposedVersion *Version) error { // VerifySupportedFeature takes in a version and feature string and returns // true if the feature is supported by the version and false otherwise. func VerifySupportedFeature(version *Version, feature string) bool { - return slices.Contains(feature, version.GetFeatures()) + return slices.Contains(version.GetFeatures(), feature) } // GetCompatibleVersions returns a descending ordered set of compatible IBC @@ -176,7 +175,7 @@ func PickVersion(supportedVersions, counterpartyVersions []*Version) (*Version, // set for the counterparty version. func GetFeatureSetIntersection(sourceFeatureSet, counterpartyFeatureSet []string) (featureSet []string) { for _, feature := range sourceFeatureSet { - if slices.Contains(feature, counterpartyFeatureSet) { + if slices.Contains(counterpartyFeatureSet, feature) { featureSet = append(featureSet, feature) } } diff --git a/testing/events.go b/testing/events.go index 5e87ae30f2e..9ccfaea96fa 100644 --- a/testing/events.go +++ b/testing/events.go @@ -2,13 +2,13 @@ package ibctesting import ( "fmt" + "slices" "strconv" testifysuite "github.com/stretchr/testify/suite" abci "github.com/cometbft/cometbft/abci/types" - "github.com/cosmos/ibc-go/v8/internal/collections" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" @@ -185,7 +185,7 @@ func AssertEvents( for _, expectedAttr := range expectedEvent.Attributes { // any expected attributes that are not contained in the actual events will cause this event // not to match - attributeMatch = attributeMatch && slices.Contains(expectedAttr, actualEvent.Attributes) + attributeMatch = attributeMatch && slices.Contains(actualEvent.Attributes, expectedAttr) } if attributeMatch {