refactor: remove simapp from client/server tests (#12676)
This commit is contained in:
@@ -5,32 +5,91 @@ import (
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
|
||||
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
|
||||
distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
|
||||
feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1"
|
||||
genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1"
|
||||
govmodulev1 "cosmossdk.io/api/cosmos/gov/module/v1"
|
||||
paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1"
|
||||
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
|
||||
txmodulev1 "cosmossdk.io/api/cosmos/tx/module/v1"
|
||||
vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1"
|
||||
"cosmossdk.io/core/appconfig"
|
||||
"cosmossdk.io/depinject"
|
||||
)
|
||||
|
||||
var beginBlockOrder = []string{
|
||||
"upgrade",
|
||||
"capability",
|
||||
"mint",
|
||||
"distribution",
|
||||
"slashing",
|
||||
"evidence",
|
||||
"staking",
|
||||
"auth",
|
||||
"bank",
|
||||
"gov",
|
||||
"crisis",
|
||||
"genutil",
|
||||
"authz",
|
||||
"feegrant",
|
||||
"nft",
|
||||
"group",
|
||||
"params",
|
||||
"vesting",
|
||||
}
|
||||
|
||||
var endBlockersOrder = []string{
|
||||
"crisis",
|
||||
"gov",
|
||||
"staking",
|
||||
"capability",
|
||||
"auth",
|
||||
"bank",
|
||||
"distribution",
|
||||
"slashing",
|
||||
"mint",
|
||||
"genutil",
|
||||
"evidence",
|
||||
"authz",
|
||||
"feegrant",
|
||||
"nft",
|
||||
"group",
|
||||
"params",
|
||||
"upgrade",
|
||||
"vesting",
|
||||
}
|
||||
|
||||
type ModuleOption func(options map[string]*appv1alpha1.ModuleConfig)
|
||||
var initGenesisOrder = []string{
|
||||
"capability",
|
||||
"auth",
|
||||
"bank",
|
||||
"distribution",
|
||||
"staking",
|
||||
"slashing",
|
||||
"gov",
|
||||
"mint",
|
||||
"crisis",
|
||||
"genutil",
|
||||
"evidence",
|
||||
"authz",
|
||||
"feegrant",
|
||||
"nft",
|
||||
"group",
|
||||
"params",
|
||||
"upgrade",
|
||||
"vesting",
|
||||
}
|
||||
|
||||
type appConfig struct {
|
||||
moduleConfigs map[string]*appv1alpha1.ModuleConfig
|
||||
setInitGenesis bool
|
||||
}
|
||||
|
||||
type ModuleOption func(config *appConfig)
|
||||
|
||||
func BankModule() ModuleOption {
|
||||
return func(options map[string]*appv1alpha1.ModuleConfig) {
|
||||
options["bank"] = &appv1alpha1.ModuleConfig{
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["bank"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "bank",
|
||||
Config: appconfig.WrapAny(&bankmodulev1.Module{}),
|
||||
}
|
||||
@@ -38,16 +97,18 @@ func BankModule() ModuleOption {
|
||||
}
|
||||
|
||||
func AuthModule() ModuleOption {
|
||||
return func(options map[string]*appv1alpha1.ModuleConfig) {
|
||||
options["auth"] = &appv1alpha1.ModuleConfig{
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["auth"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "auth",
|
||||
Config: appconfig.WrapAny(&authmodulev1.Module{
|
||||
Bech32Prefix: "cosmos",
|
||||
ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{
|
||||
{Account: "fee_collector"},
|
||||
{Account: "distribution"},
|
||||
{Account: "mint", Permissions: []string{"minter"}},
|
||||
{Account: "bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
|
||||
{Account: "not_bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
|
||||
{Account: "gov", Permissions: []string{"burner"}},
|
||||
},
|
||||
}),
|
||||
}
|
||||
@@ -55,53 +116,135 @@ func AuthModule() ModuleOption {
|
||||
}
|
||||
|
||||
func ParamsModule() ModuleOption {
|
||||
return func(options map[string]*appv1alpha1.ModuleConfig) {
|
||||
options["params"] = &appv1alpha1.ModuleConfig{
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["params"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "params",
|
||||
Config: appconfig.WrapAny(¶msmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TxModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["tx"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "tx",
|
||||
Config: appconfig.WrapAny(&txmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StakingModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["staking"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "staking",
|
||||
Config: appconfig.WrapAny(&stakingmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GenutilModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["genutil"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "genutil",
|
||||
Config: appconfig.WrapAny(&genutilmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DistributionModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["distribution"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "distribution",
|
||||
Config: appconfig.WrapAny(&distrmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FeegrantModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["feegrant"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "feegrant",
|
||||
Config: appconfig.WrapAny(&feegrantmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func VestingModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["vesting"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "vesting",
|
||||
Config: appconfig.WrapAny(&vestingmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GovModule() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.moduleConfigs["gov"] = &appv1alpha1.ModuleConfig{
|
||||
Name: "gov",
|
||||
Config: appconfig.WrapAny(&govmodulev1.Module{}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func OmitInitGenesis() ModuleOption {
|
||||
return func(config *appConfig) {
|
||||
config.setInitGenesis = false
|
||||
}
|
||||
}
|
||||
|
||||
func NewAppConfig(opts ...ModuleOption) depinject.Config {
|
||||
options := make(map[string]*appv1alpha1.ModuleConfig)
|
||||
cfg := &appConfig{
|
||||
moduleConfigs: make(map[string]*appv1alpha1.ModuleConfig),
|
||||
setInitGenesis: true,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
opt(cfg)
|
||||
}
|
||||
|
||||
beginBlockers := make([]string, 0)
|
||||
endBlockers := make([]string, 0)
|
||||
initGenesis := make([]string, 0)
|
||||
overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0)
|
||||
|
||||
for _, s := range beginBlockOrder {
|
||||
if _, ok := options[s]; ok {
|
||||
if _, ok := cfg.moduleConfigs[s]; ok {
|
||||
beginBlockers = append(beginBlockers, s)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range endBlockersOrder {
|
||||
if _, ok := options[s]; ok {
|
||||
if _, ok := cfg.moduleConfigs[s]; ok {
|
||||
endBlockers = append(endBlockers, s)
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := options["auth"]; ok {
|
||||
for _, s := range initGenesisOrder {
|
||||
if _, ok := cfg.moduleConfigs[s]; ok {
|
||||
initGenesis = append(initGenesis, s)
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := cfg.moduleConfigs["auth"]; ok {
|
||||
overrides = append(overrides, &runtimev1alpha1.StoreKeyConfig{ModuleName: "auth", KvStoreKey: "acc"})
|
||||
}
|
||||
|
||||
modules := []*appv1alpha1.ModuleConfig{
|
||||
{
|
||||
Name: "runtime",
|
||||
Config: appconfig.WrapAny(&runtimev1alpha1.Module{
|
||||
AppName: "TestApp",
|
||||
BeginBlockers: beginBlockers,
|
||||
EndBlockers: endBlockers,
|
||||
OverrideStoreKeys: overrides,
|
||||
}),
|
||||
},
|
||||
runtimeConfig := &runtimev1alpha1.Module{
|
||||
AppName: "TestApp",
|
||||
BeginBlockers: beginBlockers,
|
||||
EndBlockers: endBlockers,
|
||||
OverrideStoreKeys: overrides,
|
||||
}
|
||||
if cfg.setInitGenesis {
|
||||
runtimeConfig.InitGenesis = initGenesis
|
||||
}
|
||||
|
||||
for _, m := range options {
|
||||
modules := []*appv1alpha1.ModuleConfig{{
|
||||
Name: "runtime",
|
||||
Config: appconfig.WrapAny(runtimeConfig),
|
||||
}}
|
||||
|
||||
for _, m := range cfg.moduleConfigs {
|
||||
modules = append(modules, m)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
@@ -44,9 +46,14 @@ import (
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/bank"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/params"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
@@ -124,6 +131,17 @@ func DefaultConfig(factory TestFixtureFactory) Config {
|
||||
}
|
||||
}
|
||||
|
||||
// MinimumAppConfig defines the minimum of modules required for a call to New to succeed
|
||||
func MinimumAppConfig() depinject.Config {
|
||||
return configurator.NewAppConfig(
|
||||
configurator.AuthModule(),
|
||||
configurator.ParamsModule(),
|
||||
configurator.BankModule(),
|
||||
configurator.GenutilModule(),
|
||||
configurator.StakingModule(),
|
||||
configurator.TxModule())
|
||||
}
|
||||
|
||||
func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
|
||||
var (
|
||||
appBuilder *runtime.AppBuilder
|
||||
@@ -165,6 +183,8 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
|
||||
baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
|
||||
)
|
||||
|
||||
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})
|
||||
|
||||
if err := app.Load(true); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{
|
||||
},
|
||||
}
|
||||
|
||||
// createDefaultRandomValidatorSet creates a validator set with one random validator
|
||||
func createDefaultRandomValidatorSet() (*tmtypes.ValidatorSet, error) {
|
||||
// CreateRandomValidatorSet creates a validator set with one random validator
|
||||
func CreateRandomValidatorSet() (*tmtypes.ValidatorSet, error) {
|
||||
privVal := mock.NewPV()
|
||||
pubKey, err := privVal.GetPubKey(context.TODO())
|
||||
if err != nil {
|
||||
@@ -70,19 +70,19 @@ func createDefaultRandomValidatorSet() (*tmtypes.ValidatorSet, error) {
|
||||
// Setup initializes a new runtime.App and can inject values into extraOutputs.
|
||||
// It uses SetupWithConfiguration under the hood.
|
||||
func Setup(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error) {
|
||||
return SetupWithConfiguration(appConfig, createDefaultRandomValidatorSet, nil, false, extraOutputs...)
|
||||
return SetupWithConfiguration(appConfig, CreateRandomValidatorSet, nil, false, extraOutputs...)
|
||||
}
|
||||
|
||||
// SetupAtGenesis initializes a new runtime.App at genesis and can inject values into extraOutputs.
|
||||
// It uses SetupWithConfiguration under the hood.
|
||||
func SetupAtGenesis(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error) {
|
||||
return SetupWithConfiguration(appConfig, createDefaultRandomValidatorSet, nil, true, extraOutputs...)
|
||||
return SetupWithConfiguration(appConfig, CreateRandomValidatorSet, nil, true, extraOutputs...)
|
||||
}
|
||||
|
||||
// SetupWithBaseAppOption initializes a new runtime.App and can inject values into extraOutputs.
|
||||
// With specific baseApp options. It uses SetupWithConfiguration under the hood.
|
||||
func SetupWithBaseAppOption(appConfig depinject.Config, baseAppOption runtime.BaseAppOption, extraOutputs ...interface{}) (*runtime.App, error) {
|
||||
return SetupWithConfiguration(appConfig, createDefaultRandomValidatorSet, baseAppOption, false, extraOutputs...)
|
||||
return SetupWithConfiguration(appConfig, CreateRandomValidatorSet, baseAppOption, false, extraOutputs...)
|
||||
}
|
||||
|
||||
// SetupWithConfiguration initializes a new runtime.App. A Nop logger is set in runtime.App.
|
||||
|
||||
Reference in New Issue
Block a user