refactor: x/gov and x/mint no longer depend on each other (#16580)
This commit is contained in:
parent
277d5fd371
commit
dc6985e29c
@ -28,7 +28,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -38,6 +37,11 @@ var (
|
||||
TestProposal = getTestProposal()
|
||||
)
|
||||
|
||||
// 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
|
||||
const mintModuleName = "mint"
|
||||
|
||||
// getTestProposal creates and returns a test proposal message.
|
||||
func getTestProposal() []sdk.Msg {
|
||||
legacyProposalMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), authtypes.NewModuleAddress(types.ModuleName).String())
|
||||
@ -122,9 +126,9 @@ func trackMockBalances(bankKeeper *govtestutil.MockBankKeeper, distributionKeepe
|
||||
balances[distAcct.String()] = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(0)))
|
||||
|
||||
// We don't track module account balances.
|
||||
bankKeeper.EXPECT().MintCoins(gomock.Any(), minttypes.ModuleName, gomock.Any()).AnyTimes()
|
||||
bankKeeper.EXPECT().MintCoins(gomock.Any(), mintModuleName, gomock.Any()).AnyTimes()
|
||||
bankKeeper.EXPECT().BurnCoins(gomock.Any(), types.ModuleName, gomock.Any()).AnyTimes()
|
||||
bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), minttypes.ModuleName, types.ModuleName, gomock.Any()).AnyTimes()
|
||||
bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), mintModuleName, types.ModuleName, gomock.Any()).AnyTimes()
|
||||
|
||||
// But we do track normal account balances.
|
||||
bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), types.ModuleName, gomock.Any()).DoAndReturn(func(_ sdk.Context, sender sdk.AccAddress, _ string, coins sdk.Coins) error {
|
||||
|
||||
@ -19,7 +19,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
)
|
||||
|
||||
var address1 = "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"
|
||||
@ -51,9 +50,9 @@ func (suite *KeeperTestSuite) reset() {
|
||||
// Populate the gov account with some coins, as the TestProposal we have
|
||||
// is a MsgSend from the gov account.
|
||||
coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100000)))
|
||||
err := bankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, coins)
|
||||
err := bankKeeper.MintCoins(suite.ctx, mintModuleName, coins)
|
||||
suite.NoError(err)
|
||||
err = bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.ModuleName, coins)
|
||||
err = bankKeeper.SendCoinsFromModuleToModule(ctx, mintModuleName, types.ModuleName, coins)
|
||||
suite.NoError(err)
|
||||
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry)
|
||||
|
||||
@ -15,7 +15,6 @@ 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"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
|
||||
minttestutil "github.com/cosmos/cosmos-sdk/x/mint/testutil"
|
||||
@ -52,7 +51,7 @@ func (suite *MintTestSuite) SetupTest() {
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
authtypes.FeeCollectorName,
|
||||
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
||||
authtypes.NewModuleAddress(types.GovModuleName).String(),
|
||||
)
|
||||
|
||||
err := suite.mintKeeper.Params.Set(suite.ctx, types.DefaultParams())
|
||||
|
||||
@ -14,7 +14,6 @@ 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"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
|
||||
minttestutil "github.com/cosmos/cosmos-sdk/x/mint/testutil"
|
||||
@ -57,7 +56,7 @@ func (s *IntegrationTestSuite) SetupTest() {
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
authtypes.FeeCollectorName,
|
||||
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
||||
authtypes.NewModuleAddress(types.GovModuleName).String(),
|
||||
)
|
||||
s.stakingKeeper = stakingKeeper
|
||||
s.bankKeeper = bankKeeper
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"cosmossdk.io/errors"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
)
|
||||
|
||||
@ -27,7 +26,7 @@ func NewMsgServerImpl(k Keeper) types.MsgServer {
|
||||
// UpdateParams updates the params.
|
||||
func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
|
||||
if ms.authority != msg.Authority {
|
||||
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, msg.Authority)
|
||||
return nil, errors.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, msg.Authority)
|
||||
}
|
||||
|
||||
if err := msg.Params.Validate(); err != nil {
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
|
||||
@ -246,7 +245,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)
|
||||
}
|
||||
|
||||
5
x/mint/types/errors.go
Normal file
5
x/mint/types/errors.go
Normal file
@ -0,0 +1,5 @@
|
||||
package types
|
||||
|
||||
import "cosmossdk.io/errors"
|
||||
|
||||
var ErrInvalidSigner = errors.Register(ModuleName, 1, "invalid signer")
|
||||
@ -14,4 +14,9 @@ const (
|
||||
|
||||
// StoreKey is the default store key for mint
|
||||
StoreKey = 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"
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user