Skip to content

Commit 234ff4e

Browse files
CyberGAdamiannolanDimitrisJim
authoredSep 18, 2023
replace all instances of collections.Contains with slices.Contains across 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 <[email protected]> Co-authored-by: Jim Fasarakis-Hilliard <[email protected]>

File tree

7 files changed

+14
-69
lines changed

7 files changed

+14
-69
lines changed
 

‎internal/collections/collections.go

-11
This file was deleted.

‎internal/collections/collections_test.go

-44
This file was deleted.

‎modules/apps/27-interchain-accounts/host/client/cli/tx.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"encoding/json"
55
"fmt"
6+
"slices"
67

78
"github.com/cosmos/gogoproto/proto"
89
"github.com/spf13/cobra"
@@ -12,7 +13,6 @@ import (
1213
sdk "github.com/cosmos/cosmos-sdk/types"
1314
"github.com/cosmos/cosmos-sdk/version"
1415

15-
"github.com/cosmos/ibc-go/v8/internal/collections"
1616
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
1717
)
1818

@@ -82,7 +82,7 @@ otherwise the encoding flag can be used in combination with either "proto3" or "
8282
return err
8383
}
8484

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

‎modules/apps/27-interchain-accounts/types/metadata.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package types
22

33
import (
4+
"slices"
5+
46
errorsmod "cosmossdk.io/errors"
57

68
sdk "github.com/cosmos/cosmos-sdk/types"
79

8-
"github.com/cosmos/ibc-go/v8/internal/collections"
910
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
1011
)
1112

@@ -134,7 +135,7 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti
134135

135136
// isSupportedEncoding returns true if the provided encoding is supported, otherwise false
136137
func isSupportedEncoding(encoding string) bool {
137-
return collections.Contains(encoding, getSupportedEncoding())
138+
return slices.Contains(getSupportedEncoding(), encoding)
138139
}
139140

140141
// getSupportedEncoding returns a string slice of supported encoding formats
@@ -144,7 +145,7 @@ func getSupportedEncoding() []string {
144145

145146
// isSupportedTxType returns true if the provided transaction type is supported, otherwise false
146147
func isSupportedTxType(txType string) bool {
147-
return collections.Contains(txType, getSupportedTxTypes())
148+
return slices.Contains(getSupportedTxTypes(), txType)
148149
}
149150

150151
// getSupportedTxTypes returns a string slice of supported transaction types

‎modules/core/02-client/types/params.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package types
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67

7-
"github.com/cosmos/ibc-go/v8/internal/collections"
88
"github.com/cosmos/ibc-go/v8/modules/core/exported"
99
)
1010

@@ -30,7 +30,7 @@ func (p Params) Validate() error {
3030

3131
// IsAllowedClient checks if the given client type is registered on the allowlist.
3232
func (p Params) IsAllowedClient(clientType string) bool {
33-
return collections.Contains(clientType, p.AllowedClients)
33+
return slices.Contains(p.AllowedClients, clientType)
3434
}
3535

3636
// validateClients checks that the given clients are not blank.

‎modules/core/03-connection/types/version.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package types
22

33
import (
4+
"slices"
45
"strings"
56

67
errorsmod "cosmossdk.io/errors"
7-
8-
"github.com/cosmos/ibc-go/v8/internal/collections"
98
)
109

1110
var (
@@ -86,7 +85,7 @@ func (version Version) VerifyProposedVersion(proposedVersion *Version) error {
8685
}
8786

8887
for _, proposedFeature := range proposedVersion.GetFeatures() {
89-
if !collections.Contains(proposedFeature, version.GetFeatures()) {
88+
if !slices.Contains(version.GetFeatures(), proposedFeature) {
9089
return errorsmod.Wrapf(
9190
ErrVersionNegotiationFailed,
9291
"proposed feature (%s) is not a supported feature set (%s)", proposedFeature, version.GetFeatures(),
@@ -100,7 +99,7 @@ func (version Version) VerifyProposedVersion(proposedVersion *Version) error {
10099
// VerifySupportedFeature takes in a version and feature string and returns
101100
// true if the feature is supported by the version and false otherwise.
102101
func VerifySupportedFeature(version *Version, feature string) bool {
103-
return collections.Contains(feature, version.GetFeatures())
102+
return slices.Contains(version.GetFeatures(), feature)
104103
}
105104

106105
// GetCompatibleVersions returns a descending ordered set of compatible IBC
@@ -176,7 +175,7 @@ func PickVersion(supportedVersions, counterpartyVersions []*Version) (*Version,
176175
// set for the counterparty version.
177176
func GetFeatureSetIntersection(sourceFeatureSet, counterpartyFeatureSet []string) (featureSet []string) {
178177
for _, feature := range sourceFeatureSet {
179-
if collections.Contains(feature, counterpartyFeatureSet) {
178+
if slices.Contains(counterpartyFeatureSet, feature) {
180179
featureSet = append(featureSet, feature)
181180
}
182181
}

‎testing/events.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package ibctesting
22

33
import (
44
"fmt"
5+
"slices"
56
"strconv"
67

78
testifysuite "github.com/stretchr/testify/suite"
89

910
abci "github.com/cometbft/cometbft/abci/types"
1011

11-
"github.com/cosmos/ibc-go/v8/internal/collections"
1212
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
1313
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
1414
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
@@ -185,7 +185,7 @@ func AssertEvents(
185185
for _, expectedAttr := range expectedEvent.Attributes {
186186
// any expected attributes that are not contained in the actual events will cause this event
187187
// not to match
188-
attributeMatch = attributeMatch && collections.Contains(expectedAttr, actualEvent.Attributes)
188+
attributeMatch = attributeMatch && slices.Contains(actualEvent.Attributes, expectedAttr)
189189
}
190190

191191
if attributeMatch {

0 commit comments

Comments
 (0)
Please sign in to comment.