hook into app to get integration tests running

This commit is contained in:
rhuairahrighairigh 2020-03-10 22:29:16 +00:00
parent cae6cb196c
commit f2e4956d88
8 changed files with 319 additions and 25 deletions

View File

@ -30,10 +30,9 @@ import (
"github.com/kava-labs/kava/x/auction"
"github.com/kava-labs/kava/x/cdp"
"github.com/kava-labs/kava/x/committee"
"github.com/kava-labs/kava/x/pricefeed"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
shutdownAnte "github.com/kava-labs/kava/x/shutdown/ante"
"github.com/kava-labs/kava/x/shutdown"
)
const (
@ -64,6 +63,7 @@ var (
auction.AppModuleBasic{},
cdp.AppModuleBasic{},
pricefeed.AppModuleBasic{},
committee.AppModuleBasic{},
)
// module account permissions
@ -107,6 +107,7 @@ type App struct {
auctionKeeper auction.Keeper
cdpKeeper cdp.Keeper
pricefeedKeeper pricefeed.Keeper
committeeKeeper committee.Keeper
// the module manager
mm *module.Manager
@ -130,7 +131,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, validatorvesting.StoreKey,
auction.StoreKey, cdp.StoreKey, pricefeed.StoreKey,
auction.StoreKey, cdp.StoreKey, pricefeed.StoreKey, committee.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)
@ -245,6 +246,11 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
app.auctionKeeper,
app.supplyKeeper,
cdp.DefaultCodespace)
app.committeeKeeper = committee.NewKeeper(
app.cdc,
keys[committee.StoreKey],
// TODO blacklist module addresses?
)
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
@ -268,6 +274,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
auction.NewAppModule(app.auctionKeeper, app.supplyKeeper),
cdp.NewAppModule(app.cdpKeeper, app.pricefeedKeeper),
pricefeed.NewAppModule(app.pricefeedKeeper),
committee.NewAppModule(app.committeeKeeper),
)
// During begin block slashing happens after distr.BeginBlocker so that
@ -287,7 +294,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
auth.ModuleName, validatorvesting.ModuleName, distr.ModuleName,
staking.ModuleName, bank.ModuleName, slashing.ModuleName,
gov.ModuleName, mint.ModuleName, supply.ModuleName, crisis.ModuleName, genutil.ModuleName,
pricefeed.ModuleName, cdp.ModuleName, auction.ModuleName, // TODO is this order ok?
pricefeed.ModuleName, cdp.ModuleName, auction.ModuleName, committee.ModuleName, // TODO is this order ok?
)
app.mm.RegisterInvariants(&app.crisisKeeper)
@ -310,6 +317,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
cdp.NewAppModule(app.cdpKeeper, app.pricefeedKeeper), // TODO how is the order be decided here? Is this order correct?
pricefeed.NewAppModule(app.pricefeedKeeper),
auction.NewAppModule(app.auctionKeeper, app.supplyKeeper),
// TODO committee
)
app.sm.RegisterStoreDecoders()
@ -321,7 +329,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
// initialize the app
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(NewAnteHandler(app.accountKeeper, app.supplyKeeper, app.shutdownKeeper, auth.DefaultSigVerificationGasConsumer))
// app.SetAnteHandler(NewAnteHandler(app.accountKeeper, app.supplyKeeper, app.shutdownKeeper, auth.DefaultSigVerificationGasConsumer))
app.SetEndBlocker(app.EndBlocker)
// load store
@ -335,22 +343,22 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
return app
}
func NewAnteHandler(ak auth.AccountKeeper, supplyKeeper supply.SupplyKeeper, shutdownKeeper shutdown.Keeper, sigGasConsumer SignatureVerificationGasConsumer) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
auth.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
shutdownAnte.NewDisableMsgDecorator(shutdownKeeper)
auth.NewMempoolFeeDecorator(),
auth.NewValidateBasicDecorator(),
auth.NewValidateMemoDecorator(ak),
auth.NewConsumeGasForTxSizeDecorator(ak),
auth.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
auth.NewValidateSigCountDecorator(ak),
auth.NewDeductFeeDecorator(ak, supplyKeeper),
auth.NewSigGasConsumeDecorator(ak, sigGasConsumer),
auth.NewSigVerificationDecorator(ak),
auth.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator
)
}
// func NewAnteHandler(ak auth.AccountKeeper, supplyKeeper supply.Keeper, shutdownKeeper shutdown.Keeper, sigGasConsumer SignatureVerificationGasConsumer) sdk.AnteHandler {
// return sdk.ChainAnteDecorators(
// auth.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
// shutdownAnte.NewDisableMsgDecorator(shutdownKeeper),
// auth.NewMempoolFeeDecorator(),
// auth.NewValidateBasicDecorator(),
// auth.NewValidateMemoDecorator(ak),
// auth.NewConsumeGasForTxSizeDecorator(ak),
// auth.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
// auth.NewValidateSigCountDecorator(ak),
// auth.NewDeductFeeDecorator(ak, supplyKeeper),
// auth.NewSigGasConsumeDecorator(ak, sigGasConsumer),
// auth.NewSigVerificationDecorator(ak),
// auth.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator
// )
// }
// custom tx codec
func MakeCodec() *codec.Codec {

View File

@ -29,6 +29,7 @@ import (
"github.com/kava-labs/kava/x/auction"
"github.com/kava-labs/kava/x/cdp"
"github.com/kava-labs/kava/x/committee"
"github.com/kava-labs/kava/x/pricefeed"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
)
@ -67,6 +68,7 @@ func (tApp TestApp) GetVVKeeper() validatorvesting.Keeper { return tApp.vvKeeper
func (tApp TestApp) GetAuctionKeeper() auction.Keeper { return tApp.auctionKeeper }
func (tApp TestApp) GetCDPKeeper() cdp.Keeper { return tApp.cdpKeeper }
func (tApp TestApp) GetPriceFeedKeeper() pricefeed.Keeper { return tApp.pricefeedKeeper }
func (tApp TestApp) GetCommitteeKeeper() committee.Keeper { return tApp.committeeKeeper }
// This calls InitChain on the app using the default genesis state, overwitten with any passed in genesis states
func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp {

36
x/committee/alias.go Normal file
View File

@ -0,0 +1,36 @@
// nolint
// DO NOT EDIT - generated by aliasgen tool (github.com/rhuairahrighairidh/aliasgen)
package committee
import (
"github.com/kava-labs/kava/x/committee/keeper"
"github.com/kava-labs/kava/x/committee/types"
)
const (
ModuleName = types.ModuleName
StoreKey = types.StoreKey
)
var (
// function aliases
NewKeeper = keeper.NewKeeper
RegisterCodec = types.RegisterCodec
// variable aliases
ModuleCdc = types.ModuleCdc
)
type (
Keeper = keeper.Keeper
Committee = types.Committee
GeneralShutdownPermission = types.GeneralShutdownPermission
GroupChangeProposal = types.GroupChangeProposal
InflationRateChangePermission = types.InflationRateChangePermission
MsgSubmitProposal = types.MsgSubmitProposal
MsgVote = types.MsgVote
Permission = types.Permission
Proposal = types.Proposal
ShutdownCDPDepsitPermission = types.ShutdownCDPDepsitPermission
Vote = types.Vote
)

View File

@ -1,17 +1,27 @@
package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
//govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/kava-labs/kava/x/committee/types"
)
type Keeper struct {
// TODO other stuff as needed
cdc *codec.Codec
storeKey sdk.StoreKey
// Proposal router
router govtypes.Router
// TODO Proposal router
//router govtypes.Router
}
func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey) Keeper {
return Keeper{
cdc: cdc,
storeKey: storeKey,
}
}
/* TODO keeper methods - very similar to gov

View File

@ -0,0 +1,35 @@
package keeper_test
import (
"testing"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/committee/keeper"
)
type KeeperTestSuite struct {
suite.Suite
keeper keeper.Keeper
app app.TestApp
ctx sdk.Context
}
func (suite *KeeperTestSuite) SetupTest() {
suite.app = app.NewTestApp()
suite.keeper = suite.app.GetCommitteeKeeper()
suite.ctx = suite.app.NewContext(true, abci.Header{})
}
func (suite *KeeperTestSuite) TestGetSetCommittee() {
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

162
x/committee/module.go Normal file
View File

@ -0,0 +1,162 @@
package committee
import (
"encoding/json"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
// TODO_ module.AppModuleSimulation = AppModuleSimulation{}
)
// AppModuleBasic app module basics object
type AppModuleBasic struct{}
// Name get module name
func (AppModuleBasic) Name() string {
return ModuleName
}
// RegisterCodec register module codec
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
}
// DefaultGenesis default genesis state
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
//return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
return nil
}
// ValidateGenesis module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
// var gs GenesisState
// err := ModuleCdc.UnmarshalJSON(bz, &gs)
// if err != nil {
// return err
// }
// return gs.Validate()
return nil
}
// RegisterRESTRoutes registers the REST routes for the module.
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
//rest.RegisterRoutes(ctx, rtr)
}
// GetTxCmd returns the root tx command for the module.
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
//return cli.GetTxCmd(cdc)
return nil
}
// GetQueryCmd returns the root query command for the auction module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
//return cli.GetQueryCmd(StoreKey, cdc)
return nil
}
//____________________________________________________________________________
// TODO
// // AppModuleSimulation defines the module simulation functions used by the module.
// type AppModuleSimulation struct{}
// // RegisterStoreDecoder registers a decoder for the module's types
// func (AppModuleSimulation) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
// sdr[StoreKey] = simulation.DecodeStore
// }
// // GenerateGenesisState creates a randomized GenState of the module
// func (AppModuleSimulation) GenerateGenesisState(simState *module.SimulationState) {
// simulation.RandomizedGenState(simState)
// }
// // RandomizedParams creates randomized param changes for the simulator.
// func (AppModuleSimulation) RandomizedParams(r *rand.Rand) []sim.ParamChange {
// return simulation.ParamChanges(r)
// }
//____________________________________________________________________________
// AppModule app module type
type AppModule struct {
AppModuleBasic
// TODO AppModuleSimulation
keeper Keeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
}
}
// Name module name
func (AppModule) Name() string {
return ModuleName
}
// RegisterInvariants register module invariants
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
// Route module message route name
func (AppModule) Route() string {
return ModuleName
}
// NewHandler module handler
func (am AppModule) NewHandler() sdk.Handler {
//return NewHandler(am.keeper)
return nil
}
// QuerierRoute module querier route name
func (AppModule) QuerierRoute() string {
return ModuleName
}
// NewQuerierHandler module querier
func (am AppModule) NewQuerierHandler() sdk.Querier {
// return NewQuerier(am.keeper)
return nil
}
// InitGenesis module init-genesis
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
// var genesisState GenesisState
// ModuleCdc.MustUnmarshalJSON(data, &genesisState)
// InitGenesis(ctx, am.keeper, am.pricefeedKeeper, genesisState)
return []abci.ValidatorUpdate{}
}
// ExportGenesis module export genesis
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
// gs := ExportGenesis(ctx, am.keeper)
// return ModuleCdc.MustMarshalJSON(gs)
return nil
}
// BeginBlock module begin-block
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
// TODO BeginBlocker(ctx, req, am.keeper)
}
// EndBlock module end-block
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}

View File

@ -0,0 +1,22 @@
package types
import "github.com/cosmos/cosmos-sdk/codec"
// ModuleCdc generic sealed codec to be used throughout module
var ModuleCdc *codec.Codec
func init() {
cdc := codec.New()
RegisterCodec(cdc)
ModuleCdc = cdc.Seal()
}
// RegisterCodec registers the necessary types for the module
func RegisterCodec(cdc *codec.Codec) {
// TODO
// cdc.RegisterConcrete(MsgCreateCDP{}, "cdp/MsgCreateCDP", nil)
// cdc.RegisterConcrete(MsgDeposit{}, "cdp/MsgDeposit", nil)
// cdc.RegisterConcrete(MsgWithdraw{}, "cdp/MsgWithdraw", nil)
// cdc.RegisterConcrete(MsgDrawDebt{}, "cdp/MsgDrawDebt", nil)
// cdc.RegisterConcrete(MsgRepayDebt{}, "cdp/MsgRepayDebt", nil)
}

19
x/committee/types/keys.go Normal file
View File

@ -0,0 +1,19 @@
package types
const (
// ModuleName The name that will be used throughout the module
ModuleName = "committee"
// StoreKey Top level store key where all module items will be stored
StoreKey = ModuleName
/*
// RouterKey Top level router key
RouterKey = ModuleName
// QuerierRoute Top level query string
QuerierRoute = ModuleName
// DefaultParamspace default name for parameter store
DefaultParamspace = ModuleName
*/
)