Skip to content

Commit

Permalink
fix: check allowedList size in StakeAuthorization.Accept (#726)
Browse files Browse the repository at this point in the history
* fix: check allowedList size in StakeAuthorization.Accept

* docs: add changelog
  • Loading branch information
dudong2 authored Oct 18, 2022
1 parent ef55766 commit 502bfd7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (global) [\#694](https://github.com/line/lbm-sdk/pull/694) replace deprecated functions since go 1.16 or 1.17
* (x/bankplus) [\#705](https://github.com/line/lbm-sdk/pull/705) add missing blockedAddr checking in bankplus
* (x/foundation) [\#712](https://github.com/line/lbm-sdk/pull/712) fix x/foundation EndBlocker
* (x/staking) [\#726](https://github.com/line/lbm-sdk/pull/726) check allowedList size in StakeAuthorization.Accept()

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
2 changes: 1 addition & 1 deletion x/staking/types/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
}
}

if !isValidatorExists {
if len(allowedList) > 0 && !isValidatorExists {
return authz.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrapf("cannot delegate/undelegate to %s validator", validatorAddress)
}

Expand Down
15 changes: 14 additions & 1 deletion x/staking/types/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,20 @@ func TestAuthzAuthorizations(t *testing.T) {
false,
nil,
},

{
"delegate: testing with a validator out of denylist",
[]sdk.ValAddress{},
[]sdk.ValAddress{val1},
stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
nil,
stakingtypes.NewMsgDelegate(delAddr, val2, coin100),
false,
false,
&stakingtypes.StakeAuthorization{
Validators: &stakingtypes.StakeAuthorization_DenyList{
DenyList: &stakingtypes.StakeAuthorization_Validators{Address: []string{val1.String()}},
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE},
},
{
"undelegate: expect 0 remaining coins",
[]sdk.ValAddress{val1, val2},
Expand Down

0 comments on commit 502bfd7

Please sign in to comment.