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
4 changes: 4 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func (k BaseKeeper) SendCoinsFromModuleToAccount(
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule)
}

if err := k.IsSendEnabledCoins(ctx, amt...); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining the purpose of the IsSendEnabledCoins check.

+  // Check if sending coins is enabled for the specified amounts

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := k.IsSendEnabledCoins(ctx, amt...); err != nil {
return err
}
if err := k.IsSendEnabledCoins(ctx, amt...); err != nil {
// Check if sending coins is enabled for the specified amounts
return err
}


if k.BlockedAddr(recipientAddr) {
return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", recipientAddr)
}
Expand Down
27 changes: 27 additions & 0 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +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))

params := banktypes.Params{

SendEnabled: []*banktypes.SendEnabled{
{
Denom: sdk.DefaultBondDenom,
Enabled: false,
},
},
}

require.NoError(keeper.SetParams(ctx, params))

suite.authKeeper.EXPECT().GetModuleAddress(mintAcc.Name).Return(mintAcc.GetAddress())
err := keeper.SendCoinsFromModuleToAccount(
ctx, banktypes.MintModuleName, accAddrs[4], initCoins,
)
require.Contains(err.Error(), "stake transfers are currently disabled")
}

func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() {
ctx := suite.ctx
require := suite.Require()
Expand Down
Loading