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

fix: use module permission from app_config in app.go #12997

Merged
merged 12 commits into from
Aug 23, 2022
20 changes: 5 additions & 15 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ var (
vesting.AppModuleBasic{},
nftmodule.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
nft.ModuleName: nil,
}
)

var (
Expand Down Expand Up @@ -387,9 +376,10 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
dup := make(map[string][]string)
for _, perms := range moduleAccPerms {
dup[perms.Account] = perms.Permissions
}
return dupMaccPerms

return dup
}
24 changes: 13 additions & 11 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,8 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
{
Name: authtypes.ModuleName,
Config: appconfig.WrapAny(&authmodulev1.Module{
Bech32Prefix: "cosmos",
ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{
{Account: authtypes.FeeCollectorName},
{Account: distrtypes.ModuleName},
{Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}},
{Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}},
{Account: nft.ModuleName},
},
Bech32Prefix: "cosmos",
ModuleAccountPermissions: moduleAccPerms,
}),
},
{
Expand All @@ -137,7 +129,6 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
minttypes.ModuleName,
stakingtypes.BondedPoolName,
stakingtypes.NotBondedPoolName,
govtypes.ModuleName,
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
nft.ModuleName,
// We allow the following module accounts to receive funds:
// govtypes.ModuleName
Expand Down Expand Up @@ -215,3 +206,14 @@ var AppConfig = appconfig.Compose(&appv1alpha1.Config{
},
},
})

// module account permissions
var moduleAccPerms = []*authmodulev1.ModuleAccountPermission{
{Account: authtypes.FeeCollectorName},
{Account: distrtypes.ModuleName},
{Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}},
{Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}},
{Account: nft.ModuleName},
}
7 changes: 1 addition & 6 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
AppOpts: simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
})

for acc := range maccPerms {
for acc := range GetMaccPerms() {
require.True(
t,
app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)),
Expand All @@ -63,11 +63,6 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

func TestGetMaccPerms(t *testing.T) {
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
}

func TestRunMigrations(t *testing.T) {
db := dbm.NewMemDB()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
Expand Down