From 9ef65572677c18582937ebc165d11c1da7bcaf30 Mon Sep 17 00:00:00 2001 From: zemyblue Date: Wed, 12 Oct 2022 10:48:04 +0900 Subject: [PATCH] chore: add missing blockedAddr checking in bankplus (#705) * chore: add missing blockedAddr checking in bankplus Signed-off-by: zemyblue * fix: unittest error about blockedAddr Signed-off-by: zemyblue * chore: update changelog Signed-off-by: zemyblue * chore: add unittest of `bankplus` blockedAddr Signed-off-by: zemyblue Signed-off-by: zemyblue --- CHANGELOG.md | 1 + x/bank/keeper/genesis_test.go | 2 +- x/bankplus/keeper/keeper.go | 4 +++ x/bankplus/keeper/keeper_test.go | 27 +++++++++++++++++++ .../transfer/keeper/relay_test.go | 4 +-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd1388862..8d5576f5fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (simapp) [\#679](https://github.com/line/lbm-sdk/pull/679) fix the bug not setting `iavl-cache-size` value of `app.toml` * (x/foundation) [\#687](https://github.com/line/lbm-sdk/pull/687) fix bugs on aborting x/foundation proposals * (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 ### Breaking Changes * (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index 798a7e3a93..9d35e6cb5d 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -39,7 +39,7 @@ func (suite *IntegrationTestSuite) TestExportGenesis() { func (suite *IntegrationTestSuite) getTestBalancesAndSupply() ([]types.Balance, sdk.Coins) { addr2, _ := sdk.AccAddressFromBech32("link1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0p662v8") - addr1, _ := sdk.AccAddressFromBech32("link1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3q4fdzl") + addr1, _ := sdk.AccAddressFromBech32("link1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8j3y7jh") // distribution module address addr1Balance := sdk.Coins{sdk.NewInt64Coin("testcoin3", 10)} addr2Balance := sdk.Coins{sdk.NewInt64Coin("testcoin1", 32), sdk.NewInt64Coin("testcoin2", 34)} diff --git a/x/bankplus/keeper/keeper.go b/x/bankplus/keeper/keeper.go index 5a2f84d179..2261c319e4 100644 --- a/x/bankplus/keeper/keeper.go +++ b/x/bankplus/keeper/keeper.go @@ -57,6 +57,10 @@ func (keeper BaseKeeper) SendCoinsFromModuleToAccount( panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule)) } + if keeper.BlockedAddr(recipientAddr) { + return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", recipientAddr) + } + return keeper.SendCoins(ctx, senderAddr, recipientAddr, amt) } diff --git a/x/bankplus/keeper/keeper_test.go b/x/bankplus/keeper/keeper_test.go index aa4bc2a59d..0fbb290567 100644 --- a/x/bankplus/keeper/keeper_test.go +++ b/x/bankplus/keeper/keeper_test.go @@ -204,6 +204,33 @@ func (suite *IntegrationTestSuite) TestInitializeBankPlus() { } } +func (suite *IntegrationTestSuite) TestSendCoinsFromModuleToAccount_Blacklist() { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, ocproto.Header{Height: 1}) + appCodec := app.AppCodec() + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[authtypes.Burner] = []string{authtypes.Burner} + maccPerms[authtypes.Minter] = []string{authtypes.Minter} + + addr1 := sdk.AccAddress([]byte("addr1_______________")) + + authKeeper := authkeeper.NewAccountKeeper( + appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), + authtypes.ProtoBaseAccount, maccPerms, + ) + keeper := bankpluskeeper.NewBaseKeeper( + appCodec, app.GetKey(types.StoreKey), authKeeper, + app.GetSubspace(types.ModuleName), map[string]bool{addr1.String(): true}) + + suite.Require().NoError(keeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) + suite.Require().Error(keeper.SendCoinsFromModuleToAccount( + ctx, minttypes.ModuleName, addr1, initCoins, + )) +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } diff --git a/x/ibc/applications/transfer/keeper/relay_test.go b/x/ibc/applications/transfer/keeper/relay_test.go index 8109a609f2..adf511a72c 100644 --- a/x/ibc/applications/transfer/keeper/relay_test.go +++ b/x/ibc/applications/transfer/keeper/relay_test.go @@ -169,11 +169,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { }, true, false}, // - coin being sent to module address on chainA - // Change the original test (https://github.com/cosmos/ibc-go/blob/v3.0.0/modules/apps/transfer/keeper/relay_test.go#L171-L174) - // because the bankplus module SendCoinsFromModuleToAccount function does not have a blacklist check {"failure: receive on module account", func() { receiver = suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(types.ModuleName).String() - }, false, true}, + }, false, false}, // - coin being sent back to original chain (chainB) to module address {"failure: receive on module account on source chain", func() {