diff --git a/app/app.go b/app/app.go index c1f7ecb2ce..4b0643feae 100644 --- a/app/app.go +++ b/app/app.go @@ -634,7 +634,7 @@ func (app *App) LoadHeight(height int64) error { return app.LoadVersion(height) } -// ModuleAccountAddrs returns all the app's module account addresses. +// ModuleAccountAddrs returns a map of the app's module account addresses. func (app *App) ModuleAccountAddrs() map[string]bool { modAccAddrs := make(map[string]bool) for acc := range maccPerms { @@ -644,11 +644,11 @@ func (app *App) ModuleAccountAddrs() map[string]bool { return modAccAddrs } -// BlockedAddresses returns all the app's blocked account addresses. +// BlockedAddresses returns a map of the app's blocked account addresses. func (app *App) BlockedAddresses() map[string]bool { modAccAddrs := make(map[string]bool) - for acc := range app.ModuleAccountAddrs() { - modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + for address := range app.ModuleAccountAddrs() { + modAccAddrs[address] = true } // allow the following addresses to receive funds diff --git a/app/app_test.go b/app/app_test.go index db7fb59805..a261b26501 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -15,6 +15,8 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmdb "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -100,6 +102,57 @@ func TestInitChain(t *testing.T) { } } +func TestModuleAccountAddrs(t *testing.T) { + testApp := getTestApp() + got := testApp.ModuleAccountAddrs() + + moduleNames := []string{ + "fee_collector", + "distribution", + "gov", + "mint", + "bonded_tokens_pool", + "not_bonded_tokens_pool", + "transfer", + "interchainaccounts", + "hyperlane", + "warp", + } + for _, moduleName := range moduleNames { + address := authtypes.NewModuleAddress(moduleName).String() + assert.Contains(t, got, address) + } + assert.Equal(t, len(moduleNames), len(got)) +} + +func TestBlockedAddresses(t *testing.T) { + testApp := getTestApp() + got := testApp.BlockedAddresses() + + t.Run("blocked addresses should not contain the gov module address", func(t *testing.T) { + govAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String() + assert.NotContains(t, got, govAddress) + }) + t.Run("blocked addresses should contain all the other module addresses", func(t *testing.T) { + moduleNames := []string{ + "fee_collector", + "distribution", + "mint", + "bonded_tokens_pool", + "not_bonded_tokens_pool", + "transfer", + "interchainaccounts", + "hyperlane", + "warp", + } + for _, moduleName := range moduleNames { + address := authtypes.NewModuleAddress(moduleName).String() + assert.Contains(t, got, address) + } + assert.Equal(t, len(moduleNames), len(got)) + }) +} + func TestNodeHome(t *testing.T) { // Test that NodeHome is accessible and non-empty assert.NotEmpty(t, app.NodeHome, "NodeHome should be set and non-empty") @@ -121,3 +174,12 @@ type NoopAppOptions struct{} func (nao NoopAppOptions) Get(string) any { return nil } + +func getTestApp() *app.App { + logger := log.NewNopLogger() + db := tmdb.NewMemDB() + traceStore := &NoopWriter{} + timeoutCommit := time.Second + appOptions := NoopAppOptions{} + return app.New(logger, db, traceStore, timeoutCommit, appOptions) +}