Add crisis module and invariants for auction module
This commit is contained in:
parent
d346b95234
commit
d5be22ae65
@ -29,6 +29,7 @@ import (
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
|
||||
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
|
||||
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
@ -42,6 +43,7 @@ import (
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
|
||||
@ -73,6 +75,7 @@ type LaconicApp struct {
|
||||
BankKeeper bankkeeper.Keeper
|
||||
StakingKeeper *stakingkeeper.Keeper
|
||||
DistrKeeper distrkeeper.Keeper
|
||||
CrisisKeeper *crisiskeeper.Keeper
|
||||
ConsensusParamsKeeper consensuskeeper.Keeper
|
||||
|
||||
// laconic keepers
|
||||
@ -137,6 +140,7 @@ func NewLaconicApp(
|
||||
&app.BankKeeper,
|
||||
&app.StakingKeeper,
|
||||
&app.DistrKeeper,
|
||||
&app.CrisisKeeper,
|
||||
&app.ConsensusParamsKeeper,
|
||||
&app.AuctionKeeper,
|
||||
&app.BondKeeper,
|
||||
@ -154,7 +158,8 @@ func NewLaconicApp(
|
||||
|
||||
/**** Module Options ****/
|
||||
|
||||
// TOOD: Required?
|
||||
app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
|
||||
|
||||
// create the simulation manager and define the order of the modules for deterministic simulations
|
||||
// NOTE: this is not required apps that don't use the simulator for fuzz testing transactions
|
||||
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, make(map[string]module.AppModuleSimulation, 0))
|
||||
|
@ -7,10 +7,10 @@ modules:
|
||||
# there is nothing left over in the validator fee pool, so as to keep the CanWithdrawInvariant invariant.
|
||||
# NOTE: staking module is required if HistoricalEntries param > 0
|
||||
begin_blockers: [distribution, staking]
|
||||
end_blockers: [staking, auction, registry]
|
||||
end_blockers: [crisis, staking, auction, registry]
|
||||
# NOTE: The genutils module must occur after staking so that pools are properly initialized with tokens from genesis accounts.
|
||||
# NOTE: The genutils module must also occur after auth so that it can access the params from auth.
|
||||
init_genesis: [auth, bank, distribution, staking, genutil, auction, bond, registry]
|
||||
init_genesis: [auth, bank, distribution, staking, crisis, genutil, auction, bond, registry]
|
||||
override_store_keys:
|
||||
- module_name: auth
|
||||
kv_store_key: acc
|
||||
@ -51,6 +51,9 @@ modules:
|
||||
- name: tx
|
||||
config:
|
||||
"@type": cosmos.tx.config.v1.Config
|
||||
- name: crisis
|
||||
config:
|
||||
"@type": cosmos.crisis.module.v1.Module
|
||||
- name: bond
|
||||
config:
|
||||
"@type": cerc.bond.module.v1.Module
|
||||
|
38
x/auction/keeper/invariants.go
Normal file
38
x/auction/keeper/invariants.go
Normal file
@ -0,0 +1,38 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
)
|
||||
|
||||
// RegisterInvariants registers all auction invariants
|
||||
func RegisterInvariants(ir sdk.InvariantRegistry, k *Keeper) {
|
||||
ir.RegisterRoute(types.ModuleName, "module-accounts", ModuleAccountInvariant(k))
|
||||
}
|
||||
|
||||
// AllInvariants runs all invariants of the auctions module.
|
||||
func AllInvariants(k *Keeper) sdk.Invariant {
|
||||
return func(ctx sdk.Context) (string, bool) {
|
||||
return ModuleAccountInvariant(k)(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// ModuleAccountInvariant checks that the 'auction' module account balance is non-negative.
|
||||
func ModuleAccountInvariant(k *Keeper) sdk.Invariant {
|
||||
return func(ctx sdk.Context) (string, bool) {
|
||||
fmt.Println("running auction module invariant")
|
||||
moduleAddress := k.accountKeeper.GetModuleAddress(types.ModuleName)
|
||||
if k.bankKeeper.GetAllBalances(ctx, moduleAddress).IsAnyNegative() {
|
||||
return sdk.FormatInvariant(
|
||||
types.ModuleName,
|
||||
"module-account",
|
||||
fmt.Sprintf("Module account '%s' has negative balance.", types.ModuleName)),
|
||||
true
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ var (
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasConsensusVersion = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
)
|
||||
|
||||
// ConsensusVersion defines the current module consensus version
|
||||
@ -126,6 +127,12 @@ func (am AppModule) EndBlock(ctx context.Context) error {
|
||||
return EndBlocker(ctx, am.keeper)
|
||||
}
|
||||
|
||||
// module.HasInvariants
|
||||
|
||||
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||
keeper.RegisterInvariants(ir, am.keeper)
|
||||
}
|
||||
|
||||
// Get the root tx command of this module
|
||||
func (AppModule) GetTxCmd() *cobra.Command {
|
||||
return cli.GetTxCmd()
|
||||
|
Loading…
Reference in New Issue
Block a user