Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/bank): check send enabled on coins #20343

Merged
merged 12 commits into from
May 13, 2024
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) error {
return nil
}

func (app *BaseApp) beginBlock(req *abci.FinalizeBlockRequest) (sdk.BeginBlock, error) {
func (app *BaseApp) beginBlock(_ *abci.FinalizeBlockRequest) (sdk.BeginBlock, error) {
var (
resp sdk.BeginBlock
err error
Expand Down
6 changes: 6 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ func (k BaseKeeper) SendCoinsFromModuleToAccount(
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule)
}

for _, coin := range amt {
if ok := k.IsSendEnabledDenom(ctx, coin.Denom); !ok {
return fmt.Errorf("denom: %s, is prohibited from being sent at this time", coin.Denom)
}
}

if k.BlockedAddr(recipientAddr) {
return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", recipientAddr)
}
Expand Down
24 changes: 23 additions & 1 deletion x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (suite *KeeperTestSuite) mockMintCoins(moduleAcc *authtypes.ModuleAccount)

func (suite *KeeperTestSuite) mockSendCoinsFromModuleToAccount(moduleAcc *authtypes.ModuleAccount, accAddr sdk.AccAddress) {
suite.authKeeper.EXPECT().GetModuleAddress(moduleAcc.Name).Return(moduleAcc.GetAddress())
suite.authKeeper.EXPECT().GetAccount(suite.ctx, moduleAcc.GetAddress()).Return(moduleAcc)
suite.authKeeper.EXPECT().GetAccount(suite.ctx, moduleAcc.GetAddress()).Return(moduleAcc).AnyTimes()
}

func (suite *KeeperTestSuite) mockBurnCoins(moduleAcc *authtypes.ModuleAccount) {
Expand Down Expand Up @@ -385,11 +385,33 @@ func (suite *KeeperTestSuite) TestSendCoinsFromModuleToAccount_Blocklist() {
))
}

func (suite *KeeperTestSuite) TestSendCoinsFromModuleToAccount_CoinSendDisabled() {
ctx := suite.ctx
require := suite.Require()
keeper := suite.bankKeeper

suite.mockMintCoins(mintAcc)
require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins))

keeper.SetSendEnabled(ctx, sdk.DefaultBondDenom, false)

suite.authKeeper.EXPECT().GetModuleAddress(mintAcc.Name).Return(mintAcc.GetAddress())
err := keeper.SendCoinsFromModuleToAccount(
ctx, banktypes.MintModuleName, accAddrs[2], initCoins,
)
require.Contains(err.Error(), "stake, is prohibited from being sent at this time")
keeper.SetSendEnabled(ctx, sdk.DefaultBondDenom, true)
}

func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() {
ctx := suite.ctx
require := suite.Require()
authKeeper, keeper := suite.authKeeper, suite.bankKeeper

require.NoError(keeper.SetParams(ctx, banktypes.Params{
DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled,
}))

// set initial balances
suite.mockMintCoins(mintAcc)
require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins))
Expand Down
Loading