refactor(types): remove dependency on simapp in integration test (#12587)

## Description

Closes: #12584

- refactored tests to use a test suite initialized by `depinject`
- dependency on `simapp` replaced by 3 dependencies on modules used in the integration test: bank, auth, and params.
- introduces a prototype composable AppConfig configurator which I plan to reuse and refine in the future test refactors 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Matt Kocubinski
2022-07-15 13:19:51 +00:00
committed by GitHub
parent 9bc59e6af8
commit 9c90f980d2
3 changed files with 195 additions and 75 deletions
+109
View File
@@ -0,0 +1,109 @@
package configurator
import (
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1"
"cosmossdk.io/core/appconfig"
"cosmossdk.io/depinject"
)
var beginBlockOrder = []string{
"mint",
"staking",
"auth",
"bank",
"params",
}
var endBlockersOrder = []string{
"staking",
"auth",
"bank",
"mint",
"params",
}
type ModuleOption func(options map[string]*appv1alpha1.ModuleConfig)
func BankModule() ModuleOption {
return func(options map[string]*appv1alpha1.ModuleConfig) {
options["bank"] = &appv1alpha1.ModuleConfig{
Name: "bank",
Config: appconfig.WrapAny(&bankmodulev1.Module{}),
}
}
}
func AuthModule() ModuleOption {
return func(options map[string]*appv1alpha1.ModuleConfig) {
options["auth"] = &appv1alpha1.ModuleConfig{
Name: "auth",
Config: appconfig.WrapAny(&authmodulev1.Module{
Bech32Prefix: "cosmos",
ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{
{Account: "fee_collector"},
{Account: "mint", Permissions: []string{"minter"}},
{Account: "bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
{Account: "not_bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
},
}),
}
}
}
func ParamsModule() ModuleOption {
return func(options map[string]*appv1alpha1.ModuleConfig) {
options["params"] = &appv1alpha1.ModuleConfig{
Name: "params",
Config: appconfig.WrapAny(&paramsmodulev1.Module{}),
}
}
}
func NewAppConfig(opts ...ModuleOption) depinject.Config {
options := make(map[string]*appv1alpha1.ModuleConfig)
for _, opt := range opts {
opt(options)
}
beginBlockers := make([]string, 0)
endBlockers := make([]string, 0)
overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0)
for _, s := range beginBlockOrder {
if _, ok := options[s]; ok {
beginBlockers = append(beginBlockers, s)
}
}
for _, s := range endBlockersOrder {
if _, ok := options[s]; ok {
endBlockers = append(endBlockers, s)
}
}
if _, ok := options["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,
}),
},
}
for _, m := range options {
modules = append(modules, m)
}
return appconfig.Compose(&appv1alpha1.Config{Modules: modules})
}