diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 698ed874617f..ba0c43cfd1f3 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -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 diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 027cab51e096..bcc02b3a9abb 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -107,6 +107,8 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authority.String(), ) + assert.NilError(t, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 2ca4814fd136..d8565c1e5e4a 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -118,6 +118,8 @@ func initFixture(t *testing.T) *fixture { authority.String(), ) + assert.NilError(t, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + msgRouter := baseapp.NewMsgServiceRouter() grpcRouter := baseapp.NewGRPCQueryRouter() cometService := runtime.NewContextAwareCometInfoService() diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 5eb9268ccfc1..3578b47484f8 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -137,6 +137,8 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) + assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger()), cdc, codec.NewLegacyAmino(), stakingKeeper, authority.String()) diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 911bcc763219..b2d3ef7a5d25 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -100,6 +100,8 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) + assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 4444aacd420b..cd396d626457 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -106,6 +106,8 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) + assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + cometInfoService := runtime.NewContextAwareCometInfoService() stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometInfoService) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index d273e2c6ca9a..1c6e0cd126a1 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -159,6 +159,8 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) + assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index 6cb8bd374bd1..4da0b8f8c2b2 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -115,6 +115,8 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authority.String(), ) + assert.NilError(t, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) @@ -199,7 +201,7 @@ func bondTypeGenerator() *rapid.Generator[stakingtypes.BondStatus] { } // createValidator creates a validator with random values. -func createValidator(t *testing.T, rt *rapid.T, f *deterministicFixture) stakingtypes.Validator { +func createValidator(t *testing.T, rt *rapid.T, _ *deterministicFixture) stakingtypes.Validator { t.Helper() pubkey := pubKeyGenerator().Draw(rt, "pubkey") pubkeyAny, err := codectypes.NewAnyWithValue(&pubkey) diff --git a/tests/integration/types/filtered_pagination_test.go b/tests/integration/types/filtered_pagination_test.go index 139869e18305..042aa224495c 100644 --- a/tests/integration/types/filtered_pagination_test.go +++ b/tests/integration/types/filtered_pagination_test.go @@ -221,7 +221,7 @@ func (s *paginationTestSuite) TestFilteredPaginate() { // balances: pagination: } -func execFilterPaginate(store storetypes.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { +func execFilterPaginate(store storetypes.KVStore, pageReq *query.PageRequest, _ codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1)) @@ -263,7 +263,7 @@ func (s *paginationTestSuite) TestFilteredPaginationsNextKey() { s.Require().NoError(testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances)) store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey)) - execFilterPaginate := func(store storetypes.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { + execFilterPaginate := func(store storetypes.KVStore, pageReq *query.PageRequest, _ codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) { balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1)) diff --git a/tests/integration/types/pagination_test.go b/tests/integration/types/pagination_test.go index 3e1c44fe30db..7e7c53b3dfa1 100644 --- a/tests/integration/types/pagination_test.go +++ b/tests/integration/types/pagination_test.go @@ -84,6 +84,8 @@ func (s *paginationTestSuite) SetupTest() { ctx := app.BaseApp.NewContextLegacy(false, cmtproto.Header{Height: 1}) s.ctx, s.bankKeeper, s.accountKeeper, s.cdc, s.app, s.interfaceReg = ctx, bankKeeper, accountKeeper, cdc, app, reg + + s.Require().NoError(s.bankKeeper.SetParams(s.ctx, types.DefaultParams())) } func (s *paginationTestSuite) TestParsePagination() { diff --git a/x/bank/CHANGELOG.md b/x/bank/CHANGELOG.md index 9d5a91718557..6f298085ee62 100644 --- a/x/bank/CHANGELOG.md +++ b/x/bank/CHANGELOG.md @@ -49,3 +49,4 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Consensus Breaking Changes * [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist +* [#20343](https://github.com/cosmos/cosmos-sdk/pull/20343) Add a check in send moduleaccount to account to prevent module accounts from sending disabled tokens to accounts diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index c8f9e5ba7bca..1982e884abb9 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -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) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 315702dd857b..45fdb7031dc8 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -154,6 +154,10 @@ func (suite *KeeperTestSuite) SetupTest() { authority, ) + suite.Require().NoError(suite.bankKeeper.SetParams(ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) + banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) @@ -175,7 +179,7 @@ func (suite *KeeperTestSuite) mockMintCoins(moduleAcc *authtypes.ModuleAccount) suite.authKeeper.EXPECT().GetModuleAccount(suite.ctx, moduleAcc.Name).Return(moduleAcc) } -func (suite *KeeperTestSuite) mockSendCoinsFromModuleToAccount(moduleAcc *authtypes.ModuleAccount, accAddr sdk.AccAddress) { +func (suite *KeeperTestSuite) mockSendCoinsFromModuleToAccount(moduleAcc *authtypes.ModuleAccount, _ sdk.AccAddress) { suite.authKeeper.EXPECT().GetModuleAddress(moduleAcc.Name).Return(moduleAcc.GetAddress()) suite.authKeeper.EXPECT().GetAccount(suite.ctx, moduleAcc.GetAddress()).Return(moduleAcc) } @@ -195,7 +199,7 @@ func (suite *KeeperTestSuite) mockSendCoinsFromAccountToModule(acc *authtypes.Ba suite.authKeeper.EXPECT().GetAccount(suite.ctx, acc.GetAddress()).Return(acc) } -func (suite *KeeperTestSuite) mockSendCoins(ctx context.Context, sender sdk.AccountI, receiver sdk.AccAddress) { +func (suite *KeeperTestSuite) mockSendCoins(ctx context.Context, sender sdk.AccountI, _ sdk.AccAddress) { suite.authKeeper.EXPECT().GetAccount(ctx, sender.GetAddress()).Return(sender) } @@ -204,7 +208,7 @@ func (suite *KeeperTestSuite) mockFundAccount(receiver sdk.AccAddress) { suite.mockSendCoinsFromModuleToAccount(mintAcc, receiver) } -func (suite *KeeperTestSuite) mockInputOutputCoins(inputs []sdk.AccountI, outputs []sdk.AccAddress) { +func (suite *KeeperTestSuite) mockInputOutputCoins(inputs []sdk.AccountI, _ []sdk.AccAddress) { for _, input := range inputs { suite.authKeeper.EXPECT().GetAccount(suite.ctx, input.GetAddress()).Return(input) } @@ -385,6 +389,24 @@ 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() @@ -1863,6 +1885,7 @@ func (suite *KeeperTestSuite) TestBalanceTrackingEvents() { multiPermAcc.Name, sdk.NewCoins(sdk.NewCoin("utxo", math.NewInt(100000)))), ) + // send coins to address suite.mockSendCoinsFromModuleToAccount(multiPermAcc, accAddrs[0]) require.NoError(