From 62ba589f2440cbb3bd50cf24e8f3b0844fb84c4a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 5 Nov 2022 13:11:34 +0100 Subject: [PATCH] add check send enabled (backport #2679) (#2689) * add check send enabled (#2679) * add check send enabled * changelog (cherry picked from commit b1f494c643280c73f3696461abbb11a39303b190) * fix conflicts * fix return value * fix build Co-authored-by: Carlos Rodriguez Co-authored-by: Carlos Rodriguez --- CHANGELOG.md | 2 ++ .../apps/transfer/keeper/msg_server_test.go | 23 +++++++++++++++++++ modules/apps/transfer/keeper/relay.go | 4 ++++ .../apps/transfer/types/expected_keepers.go | 1 + 4 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 781daefc12d..b57ab17cbf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (apps/transfer) [\#2672](https://github.com/cosmos/ibc-go/pull/2672) Check `x/bank` send enabled. + ## [v4.1.0](https://github.com/cosmos/ibc-go/releases/tag/v4.1.0) - 2022-09-20 ### Dependencies diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index be11ae1a01e..261a98ecf66 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -2,6 +2,7 @@ package keeper_test import ( sdk "github.com/Finschia/finschia-sdk/types" + banktypes "github.com/Finschia/finschia-sdk/x/bank/types" "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" ) @@ -19,6 +20,17 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { func() {}, true, }, + { + "bank send enabled for denom", + func() { + suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(), + banktypes.Params{ + SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: true}}, + }, + ) + }, + true, + }, { "invalid sender", func() { @@ -33,6 +45,17 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { }, false, }, + { + "bank send disabled for denom", + func() { + suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(), + banktypes.Params{ + SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: false}}, + }, + ) + }, + false, + }, { "channel does not exist", func() { diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index dcd57f84d80..e63e899ab29 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -90,6 +90,10 @@ func (k Keeper) sendTransfer( return 0, types.ErrSendDisabled } + if !k.bankKeeper.IsSendEnabledCoin(ctx, token) { + return 0, sdkerrors.Wrapf(types.ErrSendDisabled, "%s transfers are currently disabled", token.Denom) + } + if k.bankKeeper.BlockedAddr(sender) { return 0, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index b235df5eb59..62001b6de07 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -24,6 +24,7 @@ type BankKeeper interface { SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error BlockedAddr(addr sdk.AccAddress) bool + IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool } // ICS4Wrapper defines the expected ICS4Wrapper for middleware