Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace all instances of collections.Contains with slices.Contains across the entire codebase #4685

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions internal/collections/collections.go

This file was deleted.

44 changes: 0 additions & 44 deletions internal/collections/collections_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"encoding/json"
"fmt"
"slices"

"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cobra"
Expand All @@ -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"
)

Expand Down Expand Up @@ -82,7 +82,7 @@ otherwise the encoding flag can be used in combination with either "proto3" or "
return err
}

if !collections.Contains(encoding, []string{icatypes.EncodingProtobuf, icatypes.EncodingProto3JSON}) {
if !slices.Contains([]string{icatypes.EncodingProtobuf, icatypes.EncodingProto3JSON}, encoding) {
return fmt.Errorf("unsupported encoding type: %s", encoding)
}

Expand Down
7 changes: 4 additions & 3 deletions modules/apps/27-interchain-accounts/types/metadata.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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 collections.Contains(encoding, getSupportedEncoding())
return slices.Contains(getSupportedEncoding(), encoding)
}

// getSupportedEncoding returns a string slice of supported encoding formats
Expand All @@ -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 collections.Contains(txType, getSupportedTxTypes())
return slices.Contains(getSupportedTxTypes(), txType)
}

// getSupportedTxTypes returns a string slice of supported transaction types
Expand Down
4 changes: 2 additions & 2 deletions modules/core/02-client/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 collections.Contains(clientType, p.AllowedClients)
return slices.Contains(p.AllowedClients, clientType)
}

// validateClients checks that the given clients are not blank.
Expand Down
9 changes: 4 additions & 5 deletions modules/core/03-connection/types/version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package types

import (
"slices"
"strings"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/ibc-go/v8/internal/collections"
)

var (
Expand Down Expand Up @@ -86,7 +85,7 @@ func (version Version) VerifyProposedVersion(proposedVersion *Version) error {
}

for _, proposedFeature := range proposedVersion.GetFeatures() {
if !collections.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(),
Expand All @@ -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 collections.Contains(feature, version.GetFeatures())
return slices.Contains(version.GetFeatures(), feature)
}

// GetCompatibleVersions returns a descending ordered set of compatible IBC
Expand Down Expand Up @@ -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 collections.Contains(feature, counterpartyFeatureSet) {
if slices.Contains(counterpartyFeatureSet, feature) {
featureSet = append(featureSet, feature)
}
}
Expand Down
4 changes: 2 additions & 2 deletions testing/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 && collections.Contains(expectedAttr, actualEvent.Attributes)
attributeMatch = attributeMatch && slices.Contains(actualEvent.Attributes, expectedAttr)
}

if attributeMatch {
Expand Down
Loading