Skip to content

Commit

Permalink
imp(statemachine)!: check if there are duplicate client types in allo…
Browse files Browse the repository at this point in the history
…wed clients param

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
lukema95 and crodriguezvega authored Dec 11, 2023
1 parent 65d6437 commit e7f0966
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/core/02-client/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ func (p Params) IsAllowedClient(clientType string) bool {
return slices.Contains(p.AllowedClients, clientType)
}

// validateClients checks that the given clients are not blank.
// validateClients checks that the given clients are not blank and there are no duplicates.
func validateClients(clients []string) error {
foundClients := make(map[string]bool, len(clients))
for i, clientType := range clients {
if strings.TrimSpace(clientType) == "" {
return fmt.Errorf("client type %d cannot be blank", i)
}
if foundClients[clientType] {
return fmt.Errorf("duplicate client type: %s", clientType)
}
foundClients[clientType] = true
}

return nil
Expand Down
1 change: 1 addition & 0 deletions modules/core/02-client/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestValidateParams(t *testing.T) {
{"default params", DefaultParams(), true},
{"custom params", NewParams(exported.Tendermint), true},
{"blank client", NewParams(" "), false},
{"duplicate clients", NewParams(exported.Tendermint, exported.Tendermint), false},
}

for _, tc := range testCases {
Expand Down

0 comments on commit e7f0966

Please sign in to comment.