From c05850241e2d615721e3492d15fee4e1deec082b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 19 Feb 2024 22:31:10 +0100 Subject: [PATCH] fix(x/auth/vesting): Add BlockedAddr check in `CreatePeriodicVestingAccount` (#19480) --- x/auth/vesting/msg_server.go | 4 +++ x/auth/vesting/msg_server_test.go | 56 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index e65cde63cea4..22588fad5979 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -193,6 +193,10 @@ func (s msgServer) CreatePeriodicVestingAccount(ctx context.Context, msg *types. totalCoins = totalCoins.Add(period.Amount...) } + if s.BankKeeper.BlockedAddr(to) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", msg.ToAddress) + } + if acc := s.AccountKeeper.GetAccount(ctx, to); acc != nil { return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress) } diff --git a/x/auth/vesting/msg_server_test.go b/x/auth/vesting/msg_server_test.go index df72946dae2f..8ad3c9776af6 100644 --- a/x/auth/vesting/msg_server_test.go +++ b/x/auth/vesting/msg_server_test.go @@ -138,6 +138,21 @@ func (s *VestingTestSuite) TestCreateVestingAccount() { expErr: true, expErrMsg: "already exists", }, + "create for blocked account": { + preRun: func() { + s.bankKeeper.EXPECT().IsSendEnabledCoins(gomock.Any(), fooCoin).Return(nil) + s.bankKeeper.EXPECT().BlockedAddr(to1Addr).Return(true) + }, + input: vestingtypes.NewMsgCreateVestingAccount( + fromAddr, + to1Addr, + sdk.Coins{fooCoin}, + time.Now().Unix(), + true, + ), + expErr: true, + expErrMsg: "not allowed to receive funds", + }, "create a valid delayed vesting account": { preRun: func() { s.bankKeeper.EXPECT().IsSendEnabledCoins(gomock.Any(), fooCoin).Return(nil) @@ -237,6 +252,22 @@ func (s *VestingTestSuite) TestCreatePermanentLockedAccount() { expErr: true, expErrMsg: "already exists", }, + "create for blocked account": { + preRun: func() { + toAcc := s.accountKeeper.NewAccountWithAddress(s.ctx, to1Addr) + s.bankKeeper.EXPECT().IsSendEnabledCoins(gomock.Any(), fooCoin).Return(nil) + s.bankKeeper.EXPECT().BlockedAddr(to1Addr).Return(true) + s.accountKeeper.SetAccount(s.ctx, toAcc) + }, + input: vestingtypes.NewMsgCreatePermanentLockedAccount( + fromAddr, + to1Addr, + sdk.Coins{fooCoin}, + ), + expErr: true, + expErrMsg: "not allowed to receive funds", + }, + "create a valid permanent locked account": { preRun: func() { s.bankKeeper.EXPECT().IsSendEnabledCoins(gomock.Any(), fooCoin).Return(nil) @@ -361,6 +392,7 @@ func (s *VestingTestSuite) TestCreatePeriodicVestingAccount() { { name: "create for existing account", preRun: func() { + s.bankKeeper.EXPECT().BlockedAddr(to1Addr).Return(false) toAcc := s.accountKeeper.NewAccountWithAddress(s.ctx, to1Addr) s.accountKeeper.SetAccount(s.ctx, toAcc) }, @@ -378,10 +410,34 @@ func (s *VestingTestSuite) TestCreatePeriodicVestingAccount() { expErr: true, expErrMsg: "already exists", }, + { + name: "create for blocked address", + preRun: func() { + s.bankKeeper.EXPECT().BlockedAddr(to2Addr).Return(true) + }, + input: vestingtypes.NewMsgCreatePeriodicVestingAccount( + fromAddr, + to2Addr, + time.Now().Unix(), + []vestingtypes.Period{ + { + Length: 10, + Amount: sdk.NewCoins(periodCoin), + }, + { + Length: 20, + Amount: sdk.NewCoins(fooCoin), + }, + }, + ), + expErr: true, + expErrMsg: "not allowed to receive funds", + }, { name: "create a valid periodic vesting account", preRun: func() { s.bankKeeper.EXPECT().IsSendEnabledCoins(gomock.Any(), periodCoin.Add(fooCoin)).Return(nil) + s.bankKeeper.EXPECT().BlockedAddr(to2Addr).Return(false) s.bankKeeper.EXPECT().SendCoins(gomock.Any(), fromAddr, to2Addr, gomock.Any()).Return(nil) }, input: vestingtypes.NewMsgCreatePeriodicVestingAccount(