refactor: remove invariants (#22994)
Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
type AppModuleWithAllExtensions interface {
|
||||
module.AppModule
|
||||
module.HasServices
|
||||
module.HasInvariants
|
||||
appmodulev2.HasConsensusVersion
|
||||
appmodulev2.HasGenesis
|
||||
module.HasABCIEndBlock
|
||||
@@ -25,7 +24,6 @@ type AppModuleWithAllExtensionsABCI interface {
|
||||
module.AppModule
|
||||
module.HasServices
|
||||
appmodulev2.HasABCIGenesis
|
||||
module.HasInvariants
|
||||
appmodulev2.HasConsensusVersion
|
||||
module.HasABCIEndBlock
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user