Skip to content

Commit

Permalink
replace all instances of collections.Contains with slices.Contains ac…
Browse files Browse the repository at this point in the history
…ross the entire codebase (cosmos#4685)

* replace collections.Contains with slices.Contains

* chore: remove internal/collections pkg

* chore: fix slices.Contains api usage, and remove unused imports

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Co-authored-by: Jim Fasarakis-Hilliard <d.f.hilliard@gmail.com>
  • Loading branch information
3 people committed Sep 18, 2023
1 parent 4fcb399 commit 234ff4e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 69 deletions.
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

0 comments on commit 234ff4e

Please sign in to comment.