From 9f6bb233e0d1e5ffe8d4009ea407dfc8d3a36f33 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 May 2024 13:10:38 +0200 Subject: [PATCH 01/10] check send enabled on coins --- x/bank/keeper/keeper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index c8f9e5ba7bca..a656b265aa21 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -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 + } + if k.BlockedAddr(recipientAddr) { return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", recipientAddr) } From 58cf10d959c53e30b425737854517bc9bdf95896 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 May 2024 14:51:56 +0200 Subject: [PATCH 02/10] add test case --- x/bank/keeper/keeper_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 315702dd857b..adfa7a5bb7c6 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -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() From 0da8332ae17f0f719de6444c8177b9da25338282 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 May 2024 17:34:20 +0200 Subject: [PATCH 03/10] changes to tests --- x/bank/keeper/keeper.go | 6 ++++-- x/bank/keeper/keeper_test.go | 26 +++++++++++--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index a656b265aa21..1982e884abb9 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -269,8 +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 + 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) { diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index adfa7a5bb7c6..4da9a063f342 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -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) { @@ -393,23 +393,15 @@ func (suite *KeeperTestSuite) TestSendCoinsFromModuleToAccount_CoinSendDisabled( suite.mockMintCoins(mintAcc) require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins)) - params := banktypes.Params{ - - SendEnabled: []*banktypes.SendEnabled{ - { - Denom: sdk.DefaultBondDenom, - Enabled: false, - }, - }, - } + keeper.SetSendEnabled(ctx, sdk.DefaultBondDenom, false) - require.NoError(keeper.SetParams(ctx, params)) - - suite.authKeeper.EXPECT().GetModuleAddress(mintAcc.Name).Return(mintAcc.GetAddress()) + suite.authKeeper.EXPECT().GetModuleAddress(mintAcc.Name).Return(mintAcc.GetAddress()).AnyTimes() err := keeper.SendCoinsFromModuleToAccount( - ctx, banktypes.MintModuleName, accAddrs[4], initCoins, + ctx, banktypes.MintModuleName, accAddrs[2], initCoins, ) - require.Contains(err.Error(), "stake transfers are currently disabled") + require.Contains(err.Error(), "stake, is prohibited from being sent at this time") + keeper.SetSendEnabled(ctx, sdk.DefaultBondDenom, true) + } func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() { @@ -417,6 +409,10 @@ func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() { require := suite.Require() authKeeper, keeper := suite.authKeeper, suite.bankKeeper + res, err1 := keeper.SendEnabled(ctx, &banktypes.QuerySendEnabledRequest{}) + require.NoError(err1) + fmt.Println(res) + // set initial balances suite.mockMintCoins(mintAcc) require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins)) From 4539db5af5a97484888af98b81919055d03268af Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 May 2024 21:21:46 +0200 Subject: [PATCH 04/10] some changes and linting --- baseapp/baseapp.go | 2 +- x/bank/keeper/keeper_test.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) 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/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 4da9a063f342..3def2b33ba6a 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -395,13 +395,12 @@ func (suite *KeeperTestSuite) TestSendCoinsFromModuleToAccount_CoinSendDisabled( keeper.SetSendEnabled(ctx, sdk.DefaultBondDenom, false) - suite.authKeeper.EXPECT().GetModuleAddress(mintAcc.Name).Return(mintAcc.GetAddress()).AnyTimes() + 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() { @@ -409,9 +408,9 @@ func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() { require := suite.Require() authKeeper, keeper := suite.authKeeper, suite.bankKeeper - res, err1 := keeper.SendEnabled(ctx, &banktypes.QuerySendEnabledRequest{}) - require.NoError(err1) - fmt.Println(res) + require.NoError(keeper.SetParams(ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) // set initial balances suite.mockMintCoins(mintAcc) From 55fcb7b471640cbd418c0a4af0c90a2019034a81 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 13 May 2024 12:09:24 +0200 Subject: [PATCH 05/10] set value to true --- x/bank/keeper/genesis_test.go | 5 +++++ x/bank/keeper/grpc_query_test.go | 9 +++++++++ x/bank/keeper/keeper_test.go | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index 0432d1b0fd94..d22c1a018ce1 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -3,6 +3,7 @@ package keeper_test import ( sdkmath "cosmossdk.io/math" "cosmossdk.io/x/bank/types" + banktypes "cosmossdk.io/x/bank/types" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,6 +21,10 @@ func (suite *KeeperTestSuite) TestExportGenesis() { suite.Require().NoError(err) expTotalSupply = expTotalSupply.Add(genesisSupply...) + suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) + for i := range []int{1, 2} { suite.bankKeeper.SetDenomMetaData(ctx, expectedMetadata[i]) accAddr, err1 := suite.authKeeper.AddressCodec().StringToBytes(expectedBalances[i].Address) diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index a5b4e352c88c..c2bc94f1efe1 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -10,6 +10,7 @@ import ( vestingtypes "cosmossdk.io/x/auth/vesting/types" "cosmossdk.io/x/bank/testutil" "cosmossdk.io/x/bank/types" + banktypes "cosmossdk.io/x/bank/types" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -606,6 +607,10 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { suite.mockMintCoins(mintAcc) suite.Require().NoError(keeper.MintCoins(ctx, types.MintModuleName, initCoins)) + suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) + for i := 0; i < 10; i++ { addr := sdk.AccAddress(fmt.Sprintf("account-%d", i)) @@ -831,6 +836,10 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwnersByQuery() { suite.mockMintCoins(mintAcc) suite.Require().NoError(keeper.MintCoins(ctx, types.MintModuleName, newCoins)) + suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) + for i := 0; i < 10; i++ { addr := sdk.AccAddress(fmt.Sprintf("account-%d", i)) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 3def2b33ba6a..c9d07ccd431e 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -175,7 +175,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).AnyTimes() } @@ -195,7 +195,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 +204,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) } @@ -412,6 +412,9 @@ func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() { DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, })) + res := keeper.GetParams(ctx) + fmt.Println(res) + // set initial balances suite.mockMintCoins(mintAcc) require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins)) @@ -1699,6 +1702,10 @@ func (suite *KeeperTestSuite) TestDelegateCoins() { vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.HeaderInfo().Time.Unix(), endTime.Unix()) suite.Require().NoError(err) + suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) + suite.mockFundAccount(accAddrs[0]) require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins)) @@ -1877,6 +1884,10 @@ func (suite *KeeperTestSuite) TestIterateAllDenomMetaData() { func (suite *KeeperTestSuite) TestBalanceTrackingEvents() { require := suite.Require() + require.NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ + DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, + })) + // mint coins suite.mockMintCoins(multiPermAcc) require.NoError( @@ -1885,6 +1896,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( From e673249b5b778681fbffad5e64c1e01577573fb1 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 13 May 2024 12:16:04 +0200 Subject: [PATCH 06/10] fix tests --- x/bank/keeper/grpc_query_test.go | 9 --------- x/bank/keeper/keeper_test.go | 21 +++++---------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index c2bc94f1efe1..a5b4e352c88c 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -10,7 +10,6 @@ import ( vestingtypes "cosmossdk.io/x/auth/vesting/types" "cosmossdk.io/x/bank/testutil" "cosmossdk.io/x/bank/types" - banktypes "cosmossdk.io/x/bank/types" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -607,10 +606,6 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { suite.mockMintCoins(mintAcc) suite.Require().NoError(keeper.MintCoins(ctx, types.MintModuleName, initCoins)) - suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ - DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, - })) - for i := 0; i < 10; i++ { addr := sdk.AccAddress(fmt.Sprintf("account-%d", i)) @@ -836,10 +831,6 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwnersByQuery() { suite.mockMintCoins(mintAcc) suite.Require().NoError(keeper.MintCoins(ctx, types.MintModuleName, newCoins)) - suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ - DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, - })) - for i := 0; i < 10; i++ { addr := sdk.AccAddress(fmt.Sprintf("account-%d", i)) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index c9d07ccd431e..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) @@ -177,7 +181,7 @@ func (suite *KeeperTestSuite) mockMintCoins(moduleAcc *authtypes.ModuleAccount) 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).AnyTimes() + suite.authKeeper.EXPECT().GetAccount(suite.ctx, moduleAcc.GetAddress()).Return(moduleAcc) } func (suite *KeeperTestSuite) mockBurnCoins(moduleAcc *authtypes.ModuleAccount) { @@ -408,13 +412,6 @@ func (suite *KeeperTestSuite) TestSupply_DelegateUndelegateCoins() { require := suite.Require() authKeeper, keeper := suite.authKeeper, suite.bankKeeper - require.NoError(keeper.SetParams(ctx, banktypes.Params{ - DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, - })) - - res := keeper.GetParams(ctx) - fmt.Println(res) - // set initial balances suite.mockMintCoins(mintAcc) require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins)) @@ -1702,10 +1699,6 @@ func (suite *KeeperTestSuite) TestDelegateCoins() { vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.HeaderInfo().Time.Unix(), endTime.Unix()) suite.Require().NoError(err) - suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ - DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, - })) - suite.mockFundAccount(accAddrs[0]) require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins)) @@ -1884,10 +1877,6 @@ func (suite *KeeperTestSuite) TestIterateAllDenomMetaData() { func (suite *KeeperTestSuite) TestBalanceTrackingEvents() { require := suite.Require() - require.NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ - DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, - })) - // mint coins suite.mockMintCoins(multiPermAcc) require.NoError( From 219ab569b60b64894c0e34fb57756ff7b3d93798 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 13 May 2024 12:16:40 +0200 Subject: [PATCH 07/10] revert change --- x/bank/keeper/genesis_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index d22c1a018ce1..0432d1b0fd94 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -3,7 +3,6 @@ package keeper_test import ( sdkmath "cosmossdk.io/math" "cosmossdk.io/x/bank/types" - banktypes "cosmossdk.io/x/bank/types" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -21,10 +20,6 @@ func (suite *KeeperTestSuite) TestExportGenesis() { suite.Require().NoError(err) expTotalSupply = expTotalSupply.Add(genesisSupply...) - suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, banktypes.Params{ - DefaultSendEnabled: banktypes.DefaultDefaultSendEnabled, - })) - for i := range []int{1, 2} { suite.bankKeeper.SetDenomMetaData(ctx, expectedMetadata[i]) accAddr, err1 := suite.authKeeper.AddressCodec().StringToBytes(expectedBalances[i].Address) From df01254a7116d70611082018f155f31ce82a2465 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 13 May 2024 12:18:17 +0200 Subject: [PATCH 08/10] add changelog entry --- x/bank/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 10c1b38ff64f5c28935f0aef5bde7c3d585e4abc Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 13 May 2024 12:59:40 +0200 Subject: [PATCH 09/10] fix integration tests --- tests/integration/bank/keeper/deterministic_test.go | 2 ++ tests/integration/distribution/keeper/msg_server_test.go | 2 ++ tests/integration/evidence/keeper/infraction_test.go | 2 ++ tests/integration/gov/keeper/keeper_test.go | 2 ++ tests/integration/slashing/keeper/keeper_test.go | 2 ++ tests/integration/staking/keeper/common_test.go | 2 ++ tests/integration/staking/keeper/deterministic_test.go | 2 ++ tests/integration/types/pagination_test.go | 2 ++ 8 files changed, 16 insertions(+) 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..054446330b60 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) 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() { From f01a23a8fb5ffeb6ff72b0152ff3a711717d57e0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 13 May 2024 14:04:56 +0200 Subject: [PATCH 10/10] linting --- tests/integration/staking/keeper/deterministic_test.go | 2 +- tests/integration/types/filtered_pagination_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index 054446330b60..4da0b8f8c2b2 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -201,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))