diff --git a/x/bank/app_test.go b/tests/integration/bank/app_test.go similarity index 99% rename from x/bank/app_test.go rename to tests/integration/bank/app_test.go index 016a743420..ec74b9aa99 100644 --- a/x/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -399,7 +399,7 @@ func TestMsgSetSendEnabled(t *testing.T) { "invalid authority", "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", addr1Str, - "expected gov account as only signer for proposal message", + "invalid signer", }, }, { diff --git a/x/bank/bench_test.go b/tests/integration/bank/bench_test.go similarity index 99% rename from x/bank/bench_test.go rename to tests/integration/bank/bench_test.go index 1e3121d633..4f91eb3734 100644 --- a/x/bank/bench_test.go +++ b/tests/integration/bank/bench_test.go @@ -15,6 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + _ "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/bank/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index 251f0180ba..a1058e6963 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/bank/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) func (suite *KeeperTestSuite) TestExportGenesis() { @@ -30,11 +29,11 @@ func (suite *KeeperTestSuite) TestExportGenesis() { suite.mockMintCoins(mintAcc) suite. Require(). - NoError(suite.bankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedBalances[i].Coins)) + NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, expectedBalances[i].Coins)) suite.mockSendCoinsFromModuleToAccount(mintAcc, accAddr) suite. Require(). - NoError(suite.bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, accAddr, expectedBalances[i].Coins)) + NoError(suite.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.MintModuleName, accAddr, expectedBalances[i].Coins)) } suite.Require().NoError(suite.bankKeeper.SetParams(ctx, types.DefaultParams())) diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 1190ab522d..42eaaae718 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -12,7 +12,6 @@ import ( vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" "github.com/cosmos/cosmos-sdk/x/bank/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) func (suite *KeeperTestSuite) TestQueryBalance() { @@ -235,7 +234,7 @@ func (suite *KeeperTestSuite) TestQueryTotalSupply() { suite.mockMintCoins(mintAcc) suite. Require(). - NoError(suite.bankKeeper.MintCoins(ctx, minttypes.ModuleName, testCoins)) + NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, testCoins)) res, err = queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) suite.Require().NoError(err) @@ -256,7 +255,7 @@ func (suite *KeeperTestSuite) TestQueryTotalSupplyOf() { suite.mockMintCoins(mintAcc) suite. Require(). - NoError(suite.bankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedTotalSupply)) + NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, expectedTotalSupply)) _, err := queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{}) suite.Require().Error(err) @@ -460,7 +459,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { keeper := suite.bankKeeper suite.mockMintCoins(mintAcc) - suite.Require().NoError(keeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) + suite.Require().NoError(keeper.MintCoins(ctx, types.MintModuleName, initCoins)) for i := 0; i < 10; i++ { addr := sdk.AccAddress(fmt.Sprintf("account-%d", i)) @@ -470,7 +469,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { sdk.TokensFromConsensusPower(initialPower/10, sdk.DefaultPowerReduction), )) suite.mockSendCoinsFromModuleToAccount(mintAcc, addr) - suite.Require().NoError(keeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, bal)) + suite.Require().NoError(keeper.SendCoinsFromModuleToAccount(ctx, types.MintModuleName, addr, bal)) } testCases := map[string]struct { diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index f28346ea29..2ba847b2af 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -32,8 +32,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) const ( @@ -52,7 +50,7 @@ var ( holderAcc = authtypes.NewEmptyModuleAccount(holder) burnerAcc = authtypes.NewEmptyModuleAccount(authtypes.Burner, authtypes.Burner) minterAcc = authtypes.NewEmptyModuleAccount(authtypes.Minter, authtypes.Minter) - mintAcc = authtypes.NewEmptyModuleAccount(minttypes.ModuleName, authtypes.Minter) + mintAcc = authtypes.NewEmptyModuleAccount(banktypes.MintModuleName, authtypes.Minter) multiPermAcc = authtypes.NewEmptyModuleAccount(multiPerm, authtypes.Burner, authtypes.Minter, authtypes.Staking) baseAcc = authtypes.NewBaseAccountWithAddress(sdk.AccAddress([]byte("baseAcc"))) @@ -144,7 +142,7 @@ func (suite *KeeperTestSuite) SetupTest() { storeService, suite.authKeeper, map[string]bool{accAddrs[4].String(): true}, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authtypes.NewModuleAddress(banktypes.GovModuleName).String(), log.NewNopLogger(), ) @@ -254,8 +252,8 @@ func (suite *KeeperTestSuite) TestGetAuthority() { tests := map[string]string{ "some random account": "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5", - "gov module account": authtypes.NewModuleAddress(govtypes.ModuleName).String(), - "another module account": authtypes.NewModuleAddress(minttypes.ModuleName).String(), + "gov module account": authtypes.NewModuleAddress(banktypes.GovModuleName).String(), + "another module account": authtypes.NewModuleAddress(banktypes.MintModuleName).String(), } for name, expected := range tests { @@ -308,11 +306,11 @@ func (suite *KeeperTestSuite) TestSendCoinsFromModuleToAccount_Blocklist() { keeper := suite.bankKeeper suite.mockMintCoins(mintAcc) - require.NoError(keeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) + require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins)) suite.authKeeper.EXPECT().GetModuleAddress(mintAcc.Name).Return(mintAcc.GetAddress()) require.Error(keeper.SendCoinsFromModuleToAccount( - ctx, minttypes.ModuleName, accAddrs[4], initCoins, + ctx, banktypes.MintModuleName, accAddrs[4], initCoins, )) } @@ -323,10 +321,10 @@ func (suite *KeeperTestSuite) TestSupply_SendCoins() { // set initial balances suite.mockMintCoins(mintAcc) - require.NoError(keeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) + require.NoError(keeper.MintCoins(ctx, banktypes.MintModuleName, initCoins)) suite.mockSendCoinsFromModuleToAccount(mintAcc, holderAcc.GetAddress()) - require.NoError(keeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, holderAcc.GetAddress(), initCoins)) + require.NoError(keeper.SendCoinsFromModuleToAccount(ctx, banktypes.MintModuleName, holderAcc.GetAddress(), initCoins)) authKeeper.EXPECT().GetModuleAddress("").Return(nil) require.Panics(func() { diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index c6fbedf836..1b8f3246d7 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -11,7 +11,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) type msgServer struct { @@ -133,7 +132,7 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if k.GetAuthority() != req.Authority { - return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) } if err := req.Params.Validate(); err != nil { @@ -150,7 +149,7 @@ func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam func (k msgServer) SetSendEnabled(goCtx context.Context, msg *types.MsgSetSendEnabled) (*types.MsgSetSendEnabledResponse, error) { if k.GetAuthority() != msg.Authority { - return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority) + return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority) } seen := map[string]bool{} diff --git a/x/bank/keeper/msg_server_test.go b/x/bank/keeper/msg_server_test.go index 0a4902688a..c7d5dde17f 100644 --- a/x/bank/keeper/msg_server_test.go +++ b/x/bank/keeper/msg_server_test.go @@ -4,10 +4,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -var govAcc = authtypes.NewEmptyModuleAccount(govtypes.ModuleName, authtypes.Minter) +var govAcc = authtypes.NewEmptyModuleAccount(banktypes.GovModuleName, authtypes.Minter) func (suite *KeeperTestSuite) TestMsgUpdateParams() { // default params diff --git a/x/bank/module.go b/x/bank/module.go index ca201365d0..e63a1eb257 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -31,7 +31,6 @@ import ( v1bank "github.com/cosmos/cosmos-sdk/x/bank/migrations/v1" "github.com/cosmos/cosmos-sdk/x/bank/simulation" "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) // ConsensusVersion defines the current x/bank module consensus version. @@ -249,7 +248,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { } // default to governance authority if not provided - authority := authtypes.NewModuleAddress(govtypes.ModuleName) + authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 33faddd5e8..02c0e759ca 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -12,7 +12,6 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/types" - disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/simulation" ) @@ -22,6 +21,8 @@ const ( OpWeightMsgMultiSend = "op_weight_msg_multisend" DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend + + distributionModuleName = "distribution" ) // WeightedOperations returns all the operations from the module with their respective weights @@ -420,7 +421,7 @@ func getModuleAccounts(ak types.AccountKeeper, ctx sdk.Context, moduleAccCount i moduleAccounts := make([]simtypes.Account, moduleAccCount) for i := 0; i < moduleAccCount; i++ { - acc := ak.GetModuleAccount(ctx, disttypes.ModuleName) + acc := ak.GetModuleAccount(ctx, distributionModuleName) mAcc := simtypes.Account{ Address: acc.GetAddress(), PrivKey: nil, diff --git a/x/bank/testutil/helpers.go b/x/bank/testutil/helpers.go index 430fe578d0..694dcf5a06 100644 --- a/x/bank/testutil/helpers.go +++ b/x/bank/testutil/helpers.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // FundAccount is a utility function that funds an account by minting and @@ -15,11 +15,11 @@ import ( // TODO: Instead of using the mint module account, which has the // permission of minting, create a "faucet" account. (@fdymylja) func FundAccount(ctx context.Context, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, amounts sdk.Coins) error { - if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil { + if err := bankKeeper.MintCoins(ctx, types.MintModuleName, amounts); err != nil { return err } - return bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts) + return bankKeeper.SendCoinsFromModuleToAccount(ctx, types.MintModuleName, addr, amounts) } // FundModuleAccount is a utility function that funds a module account by @@ -29,9 +29,9 @@ func FundAccount(ctx context.Context, bankKeeper bankkeeper.Keeper, addr sdk.Acc // TODO: Instead of using the mint module account, which has the // permission of minting, create a "faucet" account. (@fdymylja) func FundModuleAccount(ctx context.Context, bankKeeper bankkeeper.Keeper, recipientMod string, amounts sdk.Coins) error { - if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil { + if err := bankKeeper.MintCoins(ctx, types.MintModuleName, amounts); err != nil { return err } - return bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts) + return bankKeeper.SendCoinsFromModuleToModule(ctx, types.MintModuleName, recipientMod, amounts) } diff --git a/x/bank/types/errors.go b/x/bank/types/errors.go index 6988af108d..bec021a99f 100644 --- a/x/bank/types/errors.go +++ b/x/bank/types/errors.go @@ -12,4 +12,5 @@ var ( ErrInvalidKey = errors.Register(ModuleName, 7, "invalid key") ErrDuplicateEntry = errors.Register(ModuleName, 8, "duplicate entry") ErrMultipleSenders = errors.Register(ModuleName, 9, "multiple senders not allowed") + ErrInvalidSigner = errors.Register(ModuleName, 10, "invalid signer") ) diff --git a/x/bank/types/keys.go b/x/bank/types/keys.go index 33c14f5c38..0611d77a1f 100644 --- a/x/bank/types/keys.go +++ b/x/bank/types/keys.go @@ -4,6 +4,7 @@ import ( "cosmossdk.io/collections" collcodec "cosmossdk.io/collections/codec" "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -16,6 +17,16 @@ const ( // RouterKey defines the module's message routing key RouterKey = ModuleName + + // GovModuleName duplicates the gov module's name to avoid a cyclic dependency with x/gov. + // It should be synced with the gov module's name if it is ever changed. + // See: https://github.com/cosmos/cosmos-sdk/blob/b62a28aac041829da5ded4aeacfcd7a42873d1c8/x/gov/types/keys.go#L9 + GovModuleName = "gov" + + // MintModuleName duplicates the mint module's name to avoid a cyclic dependency with x/mint. + // It should be synced with the mint module's name if it is ever changed. + // See: https://github.com/cosmos/cosmos-sdk/blob/0e34478eb7420b69869ed50f129fc274a97a9b06/x/mint/types/keys.go#L13 + MintModuleName = "mint" ) // KVStore keys diff --git a/x/bank/types/msgs_test.go b/x/bank/types/msgs_test.go index 50c7a7f7ae..b7f98f08b5 100644 --- a/x/bank/types/msgs_test.go +++ b/x/bank/types/msgs_test.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) func TestMsgSendGetSignBytes(t *testing.T) { @@ -163,7 +162,7 @@ func TestMsgSetSendEnabledGetSignBytes(t *testing.T) { } func TestMsgSetSendEnabledGetSigners(t *testing.T) { - govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName) + govModuleAddr := authtypes.NewModuleAddress(GovModuleName) msg := NewMsgSetSendEnabled(govModuleAddr.String(), nil, nil) expected := []sdk.AccAddress{govModuleAddr} actual := msg.GetSigners()