Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configurator config options (backport #16672) #16703

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 92 additions & 72 deletions testutil/configurator/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,79 +25,102 @@ import (
"cosmossdk.io/depinject"
)

var beginBlockOrder = []string{
"upgrade",
"mint",
"distribution",
"slashing",
"evidence",
"staking",
"auth",
"bank",
"gov",
"crisis",
"genutil",
"authz",
"feegrant",
"nft",
"group",
"params",
"consensus",
"vesting",
"circuit",
// Config should never need to be instantiated manually and is solely used for ModuleOption.
type Config struct {
ModuleConfigs map[string]*appv1alpha1.ModuleConfig
BeginBlockersOrder []string
EndBlockersOrder []string
InitGenesisOrder []string
setInitGenesis bool
}

var endBlockersOrder = []string{
"crisis",
"gov",
"staking",
"auth",
"bank",
"distribution",
"slashing",
"mint",
"genutil",
"evidence",
"authz",
"feegrant",
"nft",
"group",
"params",
"consensus",
"upgrade",
"vesting",
"circuit",
var defaultConfig = &Config{
ModuleConfigs: make(map[string]*appv1alpha1.ModuleConfig),
BeginBlockersOrder: []string{
"upgrade",
"mint",
"distribution",
"slashing",
"evidence",
"staking",
"auth",
"bank",
"gov",
"crisis",
"genutil",
"authz",
"feegrant",
"nft",
"group",
"params",
"consensus",
"vesting",
"circuit",
},
EndBlockersOrder: []string{
"crisis",
"gov",
"staking",
"auth",
"bank",
"distribution",
"slashing",
"mint",
"genutil",
"evidence",
"authz",
"feegrant",
"nft",
"group",
"params",
"consensus",
"upgrade",
"vesting",
"circuit",
},
InitGenesisOrder: []string{
"auth",
"bank",
"distribution",
"staking",
"slashing",
"gov",
"mint",
"crisis",
"genutil",
"evidence",
"authz",
"feegrant",
"nft",
"group",
"params",
"consensus",
"upgrade",
"vesting",
"circuit",
},
setInitGenesis: true,
}

var initGenesisOrder = []string{
"auth",
"bank",
"distribution",
"staking",
"slashing",
"gov",
"mint",
"crisis",
"genutil",
"evidence",
"authz",
"feegrant",
"nft",
"group",
"params",
"consensus",
"upgrade",
"vesting",
"circuit",
type ModuleOption func(config *Config)

func WithCustomBeginBlockersOrder(beginBlockOrder ...string) ModuleOption {
return func(config *Config) {
config.BeginBlockersOrder = beginBlockOrder
}
}

// Config should never need to be instantiated manually and is solely used for ModuleOption.
type Config struct {
ModuleConfigs map[string]*appv1alpha1.ModuleConfig
setInitGenesis bool
func WithCustomEndBlockersOrder(endBlockersOrder ...string) ModuleOption {
return func(config *Config) {
config.EndBlockersOrder = endBlockersOrder
}
}

type ModuleOption func(config *Config)
func WithCustomInitGenesisOrder(initGenesisOrder ...string) ModuleOption {
return func(config *Config) {
config.InitGenesisOrder = initGenesisOrder
}
}

func BankModule() ModuleOption {
return func(config *Config) {
Expand Down Expand Up @@ -285,10 +308,7 @@ func OmitInitGenesis() ModuleOption {
}

func NewAppConfig(opts ...ModuleOption) depinject.Config {
cfg := &Config{
ModuleConfigs: make(map[string]*appv1alpha1.ModuleConfig),
setInitGenesis: true,
}
cfg := defaultConfig
for _, opt := range opts {
opt(cfg)
}
Expand All @@ -298,19 +318,19 @@ func NewAppConfig(opts ...ModuleOption) depinject.Config {
initGenesis := make([]string, 0)
overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0)

for _, s := range beginBlockOrder {
for _, s := range cfg.BeginBlockersOrder {
if _, ok := cfg.ModuleConfigs[s]; ok {
beginBlockers = append(beginBlockers, s)
}
}

for _, s := range endBlockersOrder {
for _, s := range cfg.EndBlockersOrder {
if _, ok := cfg.ModuleConfigs[s]; ok {
endBlockers = append(endBlockers, s)
}
}

for _, s := range initGenesisOrder {
for _, s := range cfg.InitGenesisOrder {
if _, ok := cfg.ModuleConfigs[s]; ok {
initGenesis = append(initGenesis, s)
}
Expand Down