Skip to content

Commit

Permalink
feat(x/auth): app wiring setup (cosmos#12019)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc authored May 27, 2022
1 parent 9de9d7b commit 2f09905
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
16 changes: 5 additions & 11 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ type SimApp struct {

// simulation manager
sm *module.SimulationManager

// module configurator
configurator module.Configurator
}

func init() {
Expand All @@ -213,6 +210,7 @@ func NewSimApp(
) *SimApp {
var appBuilder *runtime.AppBuilder
var paramsKeeper paramskeeper.Keeper
var accountKeeper authkeeper.AccountKeeper
var appCodec codec.Codec
var legacyAmino *codec.LegacyAmino
var interfaceRegistry codectypes.InterfaceRegistry
Expand All @@ -222,6 +220,7 @@ func NewSimApp(
&appCodec,
&legacyAmino,
&interfaceRegistry,
&accountKeeper,
)
if err != nil {
panic(err)
Expand All @@ -230,7 +229,7 @@ func NewSimApp(
runtimeApp := appBuilder.Build(logger, db, traceStore, baseAppOptions...)

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
Expand Down Expand Up @@ -259,15 +258,14 @@ func NewSimApp(
app.ParamsKeeper = paramsKeeper
initParamsKeeper(paramsKeeper)

app.AccountKeeper = accountKeeper

app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
)
Expand Down Expand Up @@ -355,7 +353,6 @@ func NewSimApp(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
Expand Down Expand Up @@ -395,8 +392,6 @@ func NewSimApp(

app.ModuleManager.RegisterInvariants(&app.CrisisKeeper)
app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.ModuleManager.RegisterServices(app.configurator)

// add test gRPC service for testing gRPC queries in isolation
testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{})
Expand Down Expand Up @@ -617,7 +612,6 @@ func GetMaccPerms() map[string][]string {

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(paramsKeeper paramskeeper.Keeper) {
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
Expand Down
21 changes: 21 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ modules:
feegrant, nft, group,
params, upgrade, vesting ]

override_store_keys:
- module_name: auth
kv_store_key: acc

- name: auth
config:
"@type": cosmos.auth.module.v1.Module
bech32_prefix: cosmos
module_account_permissions:
- account: fee_collector
- account: distribution
- account: mint
permissions: [ minter ]
- account: bonded_tokens_pool
permissions: [ burner, staking ]
- account: not_bonded_tokens_pool
permissions: [ burner, staking ]
- account: gov
permissions: [ burner ]
- account: nft

- name: params
config:
"@type": cosmos.params.module.v1.Module
10 changes: 5 additions & 5 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestRunMigrations(t *testing.T) {
bApp.SetCommitMultiStoreTracer(nil)
bApp.SetInterfaceRegistry(encCfg.InterfaceRegistry)
app.BaseApp = bApp
app.configurator = module.NewConfigurator(app.appCodec, bApp.MsgServiceRouter(), app.GRPCQueryRouter())
configurator := module.NewConfigurator(app.appCodec, bApp.MsgServiceRouter(), app.GRPCQueryRouter())

// We register all modules on the Configurator, except x/bank. x/bank will
// serve as the test subject on which we run the migration tests.
Expand All @@ -94,7 +94,7 @@ func TestRunMigrations(t *testing.T) {
continue
}

module.RegisterServices(app.configurator)
module.RegisterServices(configurator)
}

// Initialize the chain
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestRunMigrations(t *testing.T) {

if tc.moduleName != "" {
// Register migration for module from version `fromVersion` to `fromVersion+1`.
err = app.configurator.RegisterMigration(tc.moduleName, tc.fromVersion, func(sdk.Context) error {
err = configurator.RegisterMigration(tc.moduleName, tc.fromVersion, func(sdk.Context) error {
called++

return nil
Expand All @@ -168,7 +168,7 @@ func TestRunMigrations(t *testing.T) {
// version for bank as 1, and for all other modules, we put as
// their latest ConsensusVersion.
_, err = app.ModuleManager.RunMigrations(
app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}), app.configurator,
app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}), configurator,
module.VersionMap{
"bank": 1,
"auth": auth.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestInitGenesisOnMigration(t *testing.T) {

// Run migrations only for "mock" module. We exclude it from
// the VersionMap to simulate upgrading with a new module.
_, err := app.ModuleManager.RunMigrations(ctx, app.configurator,
_, err := app.ModuleManager.RunMigrations(ctx, app.Configurator(),
module.VersionMap{
"bank": bank.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
Expand Down
2 changes: 1 addition & 1 deletion upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (app SimApp) RegisterUpgradeHandlers() {
"genutil": 1,
}

return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
Expand Down

0 comments on commit 2f09905

Please sign in to comment.