Skip to content

Commit dcc5afe

Browse files
authored
feat: add configurator config options (#16672)
1 parent 417f455 commit dcc5afe

File tree

1 file changed

+92
-72
lines changed

1 file changed

+92
-72
lines changed

testutil/configurator/configurator.go

+92-72
Original file line numberDiff line numberDiff line change
@@ -25,79 +25,102 @@ import (
2525
"cosmossdk.io/depinject"
2626
)
2727

28-
var beginBlockOrder = []string{
29-
"upgrade",
30-
"mint",
31-
"distribution",
32-
"slashing",
33-
"evidence",
34-
"staking",
35-
"auth",
36-
"bank",
37-
"gov",
38-
"crisis",
39-
"genutil",
40-
"authz",
41-
"feegrant",
42-
"nft",
43-
"group",
44-
"params",
45-
"consensus",
46-
"vesting",
47-
"circuit",
28+
// Config should never need to be instantiated manually and is solely used for ModuleOption.
29+
type Config struct {
30+
ModuleConfigs map[string]*appv1alpha1.ModuleConfig
31+
BeginBlockersOrder []string
32+
EndBlockersOrder []string
33+
InitGenesisOrder []string
34+
setInitGenesis bool
4835
}
4936

50-
var endBlockersOrder = []string{
51-
"crisis",
52-
"gov",
53-
"staking",
54-
"auth",
55-
"bank",
56-
"distribution",
57-
"slashing",
58-
"mint",
59-
"genutil",
60-
"evidence",
61-
"authz",
62-
"feegrant",
63-
"nft",
64-
"group",
65-
"params",
66-
"consensus",
67-
"upgrade",
68-
"vesting",
69-
"circuit",
37+
var defaultConfig = &Config{
38+
ModuleConfigs: make(map[string]*appv1alpha1.ModuleConfig),
39+
BeginBlockersOrder: []string{
40+
"upgrade",
41+
"mint",
42+
"distribution",
43+
"slashing",
44+
"evidence",
45+
"staking",
46+
"auth",
47+
"bank",
48+
"gov",
49+
"crisis",
50+
"genutil",
51+
"authz",
52+
"feegrant",
53+
"nft",
54+
"group",
55+
"params",
56+
"consensus",
57+
"vesting",
58+
"circuit",
59+
},
60+
EndBlockersOrder: []string{
61+
"crisis",
62+
"gov",
63+
"staking",
64+
"auth",
65+
"bank",
66+
"distribution",
67+
"slashing",
68+
"mint",
69+
"genutil",
70+
"evidence",
71+
"authz",
72+
"feegrant",
73+
"nft",
74+
"group",
75+
"params",
76+
"consensus",
77+
"upgrade",
78+
"vesting",
79+
"circuit",
80+
},
81+
InitGenesisOrder: []string{
82+
"auth",
83+
"bank",
84+
"distribution",
85+
"staking",
86+
"slashing",
87+
"gov",
88+
"mint",
89+
"crisis",
90+
"genutil",
91+
"evidence",
92+
"authz",
93+
"feegrant",
94+
"nft",
95+
"group",
96+
"params",
97+
"consensus",
98+
"upgrade",
99+
"vesting",
100+
"circuit",
101+
},
102+
setInitGenesis: true,
70103
}
71104

72-
var initGenesisOrder = []string{
73-
"auth",
74-
"bank",
75-
"distribution",
76-
"staking",
77-
"slashing",
78-
"gov",
79-
"mint",
80-
"crisis",
81-
"genutil",
82-
"evidence",
83-
"authz",
84-
"feegrant",
85-
"nft",
86-
"group",
87-
"params",
88-
"consensus",
89-
"upgrade",
90-
"vesting",
91-
"circuit",
105+
type ModuleOption func(config *Config)
106+
107+
func WithCustomBeginBlockersOrder(beginBlockOrder ...string) ModuleOption {
108+
return func(config *Config) {
109+
config.BeginBlockersOrder = beginBlockOrder
110+
}
92111
}
93112

94-
// Config should never need to be instantiated manually and is solely used for ModuleOption.
95-
type Config struct {
96-
ModuleConfigs map[string]*appv1alpha1.ModuleConfig
97-
setInitGenesis bool
113+
func WithCustomEndBlockersOrder(endBlockersOrder ...string) ModuleOption {
114+
return func(config *Config) {
115+
config.EndBlockersOrder = endBlockersOrder
116+
}
98117
}
99118

100-
type ModuleOption func(config *Config)
119+
func WithCustomInitGenesisOrder(initGenesisOrder ...string) ModuleOption {
120+
return func(config *Config) {
121+
config.InitGenesisOrder = initGenesisOrder
122+
}
123+
}
101124

102125
func BankModule() ModuleOption {
103126
return func(config *Config) {
@@ -285,10 +308,7 @@ func OmitInitGenesis() ModuleOption {
285308
}
286309

287310
func NewAppConfig(opts ...ModuleOption) depinject.Config {
288-
cfg := &Config{
289-
ModuleConfigs: make(map[string]*appv1alpha1.ModuleConfig),
290-
setInitGenesis: true,
291-
}
311+
cfg := defaultConfig
292312
for _, opt := range opts {
293313
opt(cfg)
294314
}
@@ -298,19 +318,19 @@ func NewAppConfig(opts ...ModuleOption) depinject.Config {
298318
initGenesis := make([]string, 0)
299319
overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0)
300320

301-
for _, s := range beginBlockOrder {
321+
for _, s := range cfg.BeginBlockersOrder {
302322
if _, ok := cfg.ModuleConfigs[s]; ok {
303323
beginBlockers = append(beginBlockers, s)
304324
}
305325
}
306326

307-
for _, s := range endBlockersOrder {
327+
for _, s := range cfg.EndBlockersOrder {
308328
if _, ok := cfg.ModuleConfigs[s]; ok {
309329
endBlockers = append(endBlockers, s)
310330
}
311331
}
312332

313-
for _, s := range initGenesisOrder {
333+
for _, s := range cfg.InitGenesisOrder {
314334
if _, ok := cfg.ModuleConfigs[s]; ok {
315335
initGenesis = append(initGenesis, s)
316336
}

0 commit comments

Comments
 (0)