From f65746b31773e2b81b44d6dc31203a085f946825 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 17 Mar 2022 17:33:12 +0530 Subject: [PATCH 1/2] fix: authz with denylist --- x/staking/types/authz.go | 2 +- x/staking/types/authz_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index f1c2a717069a..45ce23089a3e 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -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) } diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index d1d740e171f8..1ffa3f1b62e9 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -120,6 +120,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", From 06d2a8180860bca4f25d77b5d5270cbe543fd26f Mon Sep 17 00:00:00 2001 From: atheeshp <59333759+atheeshp@users.noreply.github.com> Date: Thu, 17 Mar 2022 18:34:05 +0530 Subject: [PATCH 2/2] Update x/staking/types/authz_test.go --- x/staking/types/authz_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index 1ffa3f1b62e9..fd7f17d63e65 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -134,7 +134,6 @@ func TestAuthzAuthorizations(t *testing.T) { 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},