Skip to content

Commit

Permalink
feat: check StakeAuthorization params
Browse files Browse the repository at this point in the history
  • Loading branch information
lukema95 committed Dec 7, 2023
1 parent 14bb52a commit 9cd02a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions x/staking/types/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,24 @@ func validateAllowAndDenyValidators(allowed, denied []sdk.ValAddress) ([]string,

allowedValidators := make([]string, len(allowed))
if len(allowed) > 0 {
foundAllowedValidators := make(map[string]bool, len(allowed))
for i, validator := range allowed {
if foundAllowedValidators[validator.String()] {
return nil, nil, sdkerrors.ErrInvalidRequest.Wrapf("duplicate allowed validator address: %s", validator.String())
}
foundAllowedValidators[validator.String()] = true
allowedValidators[i] = validator.String()
}
return allowedValidators, nil, nil
}

deniedValidators := make([]string, len(denied))
foundDeniedValidators := make(map[string]bool, len(denied))
for i, validator := range denied {
if foundDeniedValidators[validator.String()] {
return nil, nil, sdkerrors.ErrInvalidRequest.Wrapf("duplicate denied validator address: %s", validator.String())
}
foundDeniedValidators[validator.String()] = true
deniedValidators[i] = validator.String()
}

Expand Down
8 changes: 8 additions & 0 deletions x/staking/types/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func TestAuthzAuthorizations(t *testing.T) {
_, err = stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{val1}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100)
require.Error(t, err)

// error duplicate allow list
_, err = stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val1}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100)
require.ErrorContains(t, err, "duplicate allowed validator address")

// error duplicate denied list
_, err = stakingtypes.NewStakeAuthorization([]sdk.ValAddress{}, []sdk.ValAddress{val1, val1}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, &coin100)
require.ErrorContains(t, err, "duplicate denied validator address")

// verify MethodName
undelAuth, _ := stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE, &coin100)
require.Equal(t, undelAuth.MsgTypeURL(), sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}))
Expand Down

0 comments on commit 9cd02a3

Please sign in to comment.