Skip to content

Commit

Permalink
Merge branch 'main' into chore/remove-xparams
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 authored Dec 20, 2024
2 parents eb0b966 + 71ddfbd commit 1b1e8d4
Show file tree
Hide file tree
Showing 19 changed files with 10 additions and 924 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### Deprecated

* (modules) [#22994](https://github.com/cosmos/cosmos-sdk/pull/22994) Deprecate `Invariants` and associated methods.

## [v0.52.0-rc.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.52.0-rc.1) - 2024-12-18

Every module contains its own CHANGELOG.md. Please refer to the module you are interested in.
Expand Down
1 change: 0 additions & 1 deletion docs/build/building-modules/11-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ x/{module_name}
│   ├── genesis.go
│   ├── grpc_query.go
│   ├── hooks.go
│   ├── invariants.go
│   ├── keeper.go
│   ├── keys.go
│   ├── msg_server.go
Expand Down
25 changes: 0 additions & 25 deletions testutil/mock/types_mock_appmodule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions types/invariant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import "fmt"
// The invariant returns a descriptive message about what happened
// and a boolean indicating whether the invariant has been broken.
// The simulator will then halt and print the logs.
// Deprecated: to be removed in > 0.52.
type Invariant func(ctx Context) (string, bool)

// Invariants defines a group of invariants
// Deprecated: to be removed in the next SDK version.
type Invariants []Invariant

// expected interface for registering invariants
// Deprecated: to be removed in the next SDK version.
type InvariantRegistry interface {
RegisterRoute(moduleName, route string, invar Invariant)
}

// FormatInvariant returns a standardized invariant message.
// Deprecated: to be removed in the next SDK version.
func FormatInvariant(module, name, msg string) string {
return fmt.Sprintf("%s: %s invariant\n%s\n", module, name, msg)
}
4 changes: 1 addition & 3 deletions types/module/mock_appmodule_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// module_test inconsistenctly import appmodulev2 & appmodulev1 due to limitation in mockgen
// module_test inconsistently imports appmodulev2 & appmodulev1 due to limitation in mockgen
// eventually, when we change mocking library, we should be consistent in our appmodule imports
package module_test

Expand All @@ -14,7 +14,6 @@ import (
type AppModuleWithAllExtensions interface {
module.AppModule
module.HasServices
module.HasInvariants
appmodulev2.HasConsensusVersion
appmodulev2.HasGenesis
module.HasABCIEndBlock
Expand All @@ -25,7 +24,6 @@ type AppModuleWithAllExtensionsABCI interface {
module.AppModule
module.HasServices
appmodulev2.HasABCIGenesis
module.HasInvariants
appmodulev2.HasConsensusVersion
module.HasABCIEndBlock
}
Expand Down
2 changes: 2 additions & 0 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type HasGenesis = appmodulev2.HasGenesis
type HasABCIGenesis = appmodulev2.HasABCIGenesis

// HasInvariants is the interface for registering invariants.
// Deprecated: invariants are no longer used from modules.
type HasInvariants interface {
// RegisterInvariants registers module invariants.
RegisterInvariants(sdk.InvariantRegistry)
Expand Down Expand Up @@ -389,6 +390,7 @@ func (m *Manager) AddQueryCommands(rootQueryCmd *cobra.Command) {
}

// RegisterInvariants registers all module invariants
// Deprecated: this function is no longer to be used as invariants are deprecated.
func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) {
for _, module := range m.Modules {
if module, ok := module.(HasInvariants); ok {
Expand Down
21 changes: 0 additions & 21 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,6 @@ func TestManagerOrderSetters(t *testing.T) {
require.Equal(t, []string{"module3", "module2", "module1"}, mm.OrderPrecommiters)
}

func TestManager_RegisterInvariants(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

mockAppModule1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockAppModule2 := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl)
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
// TODO: This is not working for Core API modules yet
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockAppModule3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))

// test RegisterInvariants
mockInvariantRegistry := mock.NewMockInvariantRegistry(mockCtrl)
mockAppModule1.EXPECT().RegisterInvariants(gomock.Eq(mockInvariantRegistry)).Times(1)
mockAppModule2.EXPECT().RegisterInvariants(gomock.Eq(mockInvariantRegistry)).Times(1)
mm.RegisterInvariants(mockInvariantRegistry)
}

func TestManager_RegisterQueryServices(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
Expand Down
78 changes: 0 additions & 78 deletions x/bank/keeper/invariants.go

This file was deleted.

7 changes: 0 additions & 7 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simsx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
Expand All @@ -33,7 +32,6 @@ var (
_ module.HasAminoCodec = AppModule{}
_ module.HasGRPCGateway = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.HasInvariants = AppModule{}

_ appmodule.AppModule = AppModule{}
_ appmodule.HasMigrations = AppModule{}
Expand Down Expand Up @@ -114,11 +112,6 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
return nil
}

// RegisterInvariants registers the bank module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper)
}

// DefaultGenesis returns default genesis state as raw bytes for the bank module.
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(types.DefaultGenesisState())
Expand Down
Loading

0 comments on commit 1b1e8d4

Please sign in to comment.